1import dateutil
2import pytest
3
4
5
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 'application/json' in response.headers['Content-Type']
11 assert response.json() == {'now': '2019-12-31T11:22:33+00:00'}
12
13
14 mocked_time.sleep(671)
15 await service_client.update_server_state()
16
17 response = await service_client.get('/now')
18 assert response.status == 200
19 assert 'application/json' in response.headers['Content-Type']
20 assert response.json() == {'now': '2019-12-31T11:33:44+00:00'}
21
22
23
24@pytest.mark.now('2019-12-31T10:00:00+0545')
25async def test_now_timezone_custom(service_client, mocked_time):
26 response = await service_client.get('/now')
27 assert response.status == 200
28 assert 'application/json' in response.headers['Content-Type']
29 assert response.json() == {'now': '2019-12-31T04:15:00+00:00'}
30
31 mocked_time.set(dateutil.parser.parse('2019-12-31T10:00:00+0400'))
32
33 response = await service_client.get('/now')
34 assert response.status == 200
35 assert 'application/json' in response.headers['Content-Type']
36 assert response.json() == {'now': '2019-12-31T06:00:00+00:00'}