Skip to content

Commit

Permalink
Refactor and fix flaky tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrf345 committed Sep 6, 2020
1 parent 355e140 commit b41c2b5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 5 additions & 1 deletion app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
class Mixin:
@classmethod
def get(cls, id=False, **kwargs):
if id is False and not kwargs:
if id is None:
# NOTE: leaving it to avoid awakinging dragons!
return None

if id is False or id and not kwargs:
return cls.query.first()

if id:
Expand Down
8 changes: 2 additions & 6 deletions tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,8 @@ def test_pull_tickets_from_all(_, c):
assert response.status == '200 OK'
assert ticket_to_be_pulled is not None
assert ticket_to_be_pulled.p is False
assert Serial.query.filter_by(number=ticket_to_be_pulled.number,
office_id=ticket_to_be_pulled.office_id,
task_id=ticket_to_be_pulled.task_id,
p=True)\
.order_by(Serial.number)\
.first() is not None
assert Serial.get(ticket_to_be_pulled.id).number == ticket_to_be_pulled.number
assert Serial.get(ticket_to_be_pulled.id).p is True


@pytest.mark.parametrize('_', range(TEST_REPEATS))
Expand Down
5 changes: 3 additions & 2 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ def test_single_row_pulling(_, c):
100)

response = c.get(f'/pull', follow_redirects=True)
pulled_ticket = Office.get(0).tickets.order_by(Serial.timestamp.desc()).first()

assert response.status == '200 OK'
assert Office.get(0).tickets.count() - 1 == tickets_length
assert Office.get(0).tickets.first().number - 1 == last_number
assert Office.get(0).tickets.first().p is True
assert pulled_ticket.number - 1 == last_number
assert pulled_ticket.p is True


@pytest.mark.usefixtures('c')
Expand Down

0 comments on commit b41c2b5

Please sign in to comment.