Skip to content

Commit

Permalink
Use UTC for test_query_with_creation_date comparisons
Browse files Browse the repository at this point in the history
The creation time of the record inserted by upsert_sample() will
be reported in UTC, so we need to compare against today in UTC.
Otherwise tests fail when run locally before lunchtimeish as it
is still "yesterday" in UTC, so lt=today unexpectedly returns
the just-created record.
  • Loading branch information
jmarshall committed Apr 22, 2024
1 parent 3c2af5f commit 86e9237
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions test/test_sequencing_groups.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date
from datetime import datetime
from test.testbase import DbIsolatedTest, run_as_sync

from db.python.layers import AnalysisLayer, SampleLayer, SequencingGroupLayer
Expand Down Expand Up @@ -202,31 +202,34 @@ async def test_query_with_creation_date(self):
sample_to_insert = get_sample_model()
await self.slayer.upsert_sample(sample_to_insert)

# There's a race condition here -- don't run this near UTC midnight!
today = datetime.utcnow().date()

# Query for sequencing group with creation date before today
sgs = await self.sglayer.query(
SequencingGroupFilter(created_on=GenericFilter(lt=date.today()))
SequencingGroupFilter(created_on=GenericFilter(lt=today))
)
self.assertEqual(len(sgs), 0)

# Query for sequencing group with creation date today
sgs = await self.sglayer.query(
SequencingGroupFilter(created_on=GenericFilter(eq=date.today()))
SequencingGroupFilter(created_on=GenericFilter(eq=today))
)
self.assertEqual(len(sgs), 1)

sgs = await self.sglayer.query(
SequencingGroupFilter(created_on=GenericFilter(lte=date.today()))
SequencingGroupFilter(created_on=GenericFilter(lte=today))
)
self.assertEqual(len(sgs), 1)

sgs = await self.sglayer.query(
SequencingGroupFilter(created_on=GenericFilter(gte=date.today()))
SequencingGroupFilter(created_on=GenericFilter(gte=today))
)
self.assertEqual(len(sgs), 1)

# Query for sequencing group with creation date today
sgs = await self.sglayer.query(
SequencingGroupFilter(created_on=GenericFilter(gt=date.today()))
SequencingGroupFilter(created_on=GenericFilter(gt=today))
)
self.assertEqual(len(sgs), 0)

Expand Down

0 comments on commit 86e9237

Please sign in to comment.