userver: samples/testsuite-support/tests/test_mocked_time.py
Loading...
Searching...
No Matches
samples/testsuite-support/tests/test_mocked_time.py
1import dateutil
2import pytest
3
4
5# /// [mocked_time]
6@pytest.mark.now('2019-12-31T11:22:33Z')
7async def test_now(service_client, mocked_time):
8 response = await service_client.get('/now')
9 assert response.status == 200
10 assert response.json() == {'now': '2019-12-31T11:22:33+00:00'}
11
12 # Change mocked time and sync state
13 mocked_time.sleep(671)
14 await service_client.update_server_state()
15
16 response = await service_client.get('/now')
17 assert response.status == 200
18 assert response.json() == {'now': '2019-12-31T11:33:44+00:00'}
19 # /// [mocked_time]
20
21
22@pytest.mark.now('2019-12-31T10:00:00+0545')
23async def test_now_timezone_custom(service_client, mocked_time):
24 response = await service_client.get('/now')
25 assert response.status == 200
26 assert response.json() == {'now': '2019-12-31T04:15:00+00:00'}
27
28 mocked_time.set(dateutil.parser.parse('2019-12-31T10:00:00+0400'))
29
30 response = await service_client.get('/now')
31 assert response.status == 200
32 assert response.json() == {'now': '2019-12-31T06:00:00+00:00'}