Coverage for databases/sync_tests/arrays/push/test_datetime.py: 100%
19 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
1from typing import List
2from datetime import datetime, timezone, timedelta
4from prisma import Prisma
7def _utcnow() -> datetime:
8 # workaround for https://github.com/RobertCraigie/prisma-client-py/issues/129
9 now = datetime.now(timezone.utc)
10 return now.replace(microsecond=int(now.microsecond / 1000) * 1000)
13def _assert_datelist_equal(actual: List[datetime], expected: List[datetime]) -> None:
14 actual = [dt.replace(tzinfo=None) for dt in actual]
15 expected = [dt.replace(tzinfo=None) for dt in expected]
16 assert actual == expected
19def test_pushing_datetime(client: Prisma) -> None:
20 """Pushing a DateTime[] value"""
21 now = _utcnow()
22 models = [
23 client.lists.create({}),
24 client.lists.create(
25 data={
26 'dates': [now, now + timedelta(hours=3)],
27 },
28 ),
29 ]
31 model = client.lists.update(
32 where={
33 'id': models[0].id,
34 },
35 data={
36 'dates': {
37 'push': [now, now + timedelta(days=5)],
38 },
39 },
40 )
41 assert model is not None
42 _assert_datelist_equal(model.dates, [now, now + timedelta(days=5)])
44 model = client.lists.update(
45 where={
46 'id': models[1].id,
47 },
48 data={
49 'dates': {
50 'push': [now + timedelta(hours=7)],
51 },
52 },
53 )
54 assert model is not None
55 _assert_datelist_equal(model.dates, [now, now + timedelta(hours=3), now + timedelta(hours=7)])