Skip to content

Commit

Permalink
Merge pull request #464 from MongoEngine/tests-fstrings
Browse files Browse the repository at this point in the history
Replace strings interpolation with f-strings in project tests
  • Loading branch information
insspb committed Jul 1, 2022
2 parents 7c39717 + 932acda commit 3492665
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions tests/test_basic_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def show(id):
def test_with_id(app, todo):
Todo = todo
client = app.test_client()
response = client.get("/show/%s/" % ObjectId())
response = client.get(f"/show/{ObjectId()}/")
assert response.status_code == 404

client.post("/add", data={"title": "First Item", "text": "The text"})

response = client.get("/show/%s/" % Todo.objects.first_or_404().id)
response = client.get(f"/show/{Todo.objects.first_or_404().id}/")
assert response.status_code == 200
assert response.data.decode("utf-8") == "First Item\nThe text"

Expand Down
8 changes: 3 additions & 5 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,19 @@ class Email(db.Document):

EmailForm = model_form(Email)
form = EmailForm(instance=Email())
assert "None" not in "%s" % form.email
assert "None" not in f"{form.email}"
assert form.validate()

form = EmailForm(MultiDict({"email": ""}))
assert "None" not in "%s" % form.email
assert "None" not in f"{form.email}"
assert form.validate()

# Ensure required works

class Email(db.Document):
email = db.EmailField(required=True)

EmailForm = model_form(Email)
form = EmailForm(MultiDict({"email": ""}))
assert "None" not in "%s" % form.email
assert "None" not in f"{form.email}"
assert not form.validate()


Expand Down
4 changes: 2 additions & 2 deletions tests/test_json_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def show(id):
def test_with_id(app, todo):
Todo = todo
client = app.test_client()
response = client.get("/show/%s/" % ObjectId())
response = client.get(f"/show/{ObjectId()}/")
assert response.status_code == 404

response = client.post("/add", data={"title": "First Item", "text": "The text"})
assert response.status_code == 200

response = client.get("/show/%s/" % Todo.objects.first().id)
response = client.get(f"/show/{Todo.objects.first().id}/")
assert response.status_code == 200

result = flask.json.loads(response.data).get("result")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def test_queryset_paginator(app, todo):
Todo = todo
for i in range(42):
Todo(title="post: %s" % i).save()
Todo(title=f"post: {i}").save()

with pytest.raises(NotFound):
Pagination(iterable=Todo.objects, page=0, per_page=10)
Expand All @@ -33,7 +33,7 @@ def test_paginate_plain_list():
def test_list_field_pagination(app, todo):
Todo = todo

comments = ["comment: %s" % i for i in range(42)]
comments = [f"comment: {i}" for i in range(42)]
todo = Todo(
title="todo has comments",
comments=comments,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def index():

@app.route("/check-session")
def check_session():
return "session: %s" % session["a"]
return f'session: {session["a"]}'


@pytest.fixture
Expand Down

0 comments on commit 3492665

Please sign in to comment.