Skip to content

Commit 7cb9181

Browse files
committed
feat(conftest): patch metadata return value
this will prevent cassettes to be invalidated due to the metadata end_timestamp changing Addresses #139
1 parent ab77d26 commit 7cb9181

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

ohsome/test/conftest.py

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,74 @@
22
# -*- coding: utf-8 -*-
33
"""Conftest for shared pytest fixtures"""
44
import logging
5+
from unittest.mock import patch, PropertyMock
6+
57
import pytest
8+
from urllib3 import Retry
9+
610
import ohsome
711

812
logger = logging.getLogger(__name__)
913

1014

15+
@pytest.fixture
16+
def mocked_metadata():
17+
"""A default metadata dictionary.
18+
19+
@return:
20+
"""
21+
return {
22+
"attribution": {
23+
"url": "https://ohsome.org/copyrights",
24+
"text": "© OpenStreetMap contributors",
25+
},
26+
"apiVersion": "1.10.1",
27+
"timeout": 600.0,
28+
"extractRegion": {
29+
"spatialExtent": {
30+
"type": "Polygon",
31+
"coordinates": [
32+
[
33+
[-180.0, -90.0],
34+
[180.0, -90.0],
35+
[180.0, 90.0],
36+
[-180.0, 90.0],
37+
[-180.0, -90.0],
38+
]
39+
],
40+
},
41+
"temporalExtent": {
42+
"fromTimestamp": "2007-10-08T00:00:00Z",
43+
"toTimestamp": "2023-11-25T13:00:00Z",
44+
},
45+
"replicationSequenceNumber": 99919,
46+
},
47+
}
48+
49+
1150
@pytest.fixture
1251
def base_client(mocked_metadata, tmpdir_factory):
1352
"""Session-wide test client."""
1453
temp_directory = tmpdir_factory.mktemp("base_client").mkdir("logs").strpath
15-
client = ohsome.OhsomeClient(log_dir=temp_directory)
16-
assert client.metadata # call metadata once to ensure it is cached
17-
yield client
54+
with patch(
55+
"ohsome.clients._OhsomeInfoClient.metadata",
56+
new_callable=PropertyMock,
57+
return_value=mocked_metadata,
58+
):
59+
client = ohsome.OhsomeClient(log_dir=temp_directory)
60+
yield client
1861

1962

2063
@pytest.fixture
2164
def base_client_without_log(mocked_metadata):
2265
"""Session-wide test client."""
23-
client = ohsome.OhsomeClient(log=False)
24-
assert client.metadata # call metadata once to ensure it is cached
25-
yield client
66+
with patch(
67+
"ohsome.clients._OhsomeInfoClient.metadata",
68+
new_callable=PropertyMock,
69+
return_value=mocked_metadata,
70+
):
71+
client = ohsome.OhsomeClient(log=False)
72+
yield client
2673

2774

2875
@pytest.fixture

0 commit comments

Comments
 (0)