Skip to content

Commit

Permalink
freeze flaky unit test
Browse files Browse the repository at this point in the history
(cherry picked from commit ce41b44)
  • Loading branch information
mistercrunch committed Nov 2, 2020
1 parent 7124146 commit 8a9f282
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions tests/queries/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import random
import string

from freezegun import freeze_time
import pytest
import prison
from sqlalchemy.sql import func
Expand Down Expand Up @@ -326,19 +327,20 @@ def test_get_list_query_filter_changed_on(self):
Query API: Test get list query filter changed_on
"""
self.login(username="admin")
now_time = datetime.now()
yesterday_time = now_time - timedelta(days=1)
arguments = {
"filters": [
{"col": "changed_on", "opr": "lt", "value": str(now_time)},
{"col": "changed_on", "opr": "gt", "value": str(yesterday_time)},
]
}
uri = f"api/v1/query/?q={prison.dumps(arguments)}"
rv = self.client.get(uri)
assert rv.status_code == 200
data = json.loads(rv.data.decode("utf-8"))
assert data["count"] == QUERIES_FIXTURE_COUNT
with freeze_time("2020-01-01T00:00:00Z"):
now_time = datetime.now()
yesterday_time = now_time - timedelta(days=1)
arguments = {
"filters": [
{"col": "changed_on", "opr": "lt", "value": str(now_time)},
{"col": "changed_on", "opr": "gt", "value": str(yesterday_time)},
]
}
uri = f"api/v1/query/?q={prison.dumps(arguments)}"
rv = self.client.get(uri)
assert rv.status_code == 200
data = json.loads(rv.data.decode("utf-8"))
assert data["count"] == QUERIES_FIXTURE_COUNT

@pytest.mark.usefixtures("create_queries")
def test_get_list_query_order(self):
Expand Down

0 comments on commit 8a9f282

Please sign in to comment.