Skip to content

Commit

Permalink
feat(conftest): patch metadata return value
Browse files Browse the repository at this point in the history
this will prevent cassettes to be invalidated due to the metadata end_timestamp changing

Addresses #139
  • Loading branch information
SlowMo24 committed Feb 16, 2024
1 parent ab77d26 commit 7cb9181
Showing 1 changed file with 53 additions and 6 deletions.
59 changes: 53 additions & 6 deletions ohsome/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,74 @@
# -*- coding: utf-8 -*-
"""Conftest for shared pytest fixtures"""
import logging
from unittest.mock import patch, PropertyMock

import pytest
from urllib3 import Retry

import ohsome

logger = logging.getLogger(__name__)


@pytest.fixture
def mocked_metadata():
"""A default metadata dictionary.
@return:
"""
return {
"attribution": {
"url": "https://ohsome.org/copyrights",
"text": "© OpenStreetMap contributors",
},
"apiVersion": "1.10.1",
"timeout": 600.0,
"extractRegion": {
"spatialExtent": {
"type": "Polygon",
"coordinates": [
[
[-180.0, -90.0],
[180.0, -90.0],
[180.0, 90.0],
[-180.0, 90.0],
[-180.0, -90.0],
]
],
},
"temporalExtent": {
"fromTimestamp": "2007-10-08T00:00:00Z",
"toTimestamp": "2023-11-25T13:00:00Z",
},
"replicationSequenceNumber": 99919,
},
}


@pytest.fixture
def base_client(mocked_metadata, tmpdir_factory):
"""Session-wide test client."""
temp_directory = tmpdir_factory.mktemp("base_client").mkdir("logs").strpath
client = ohsome.OhsomeClient(log_dir=temp_directory)
assert client.metadata # call metadata once to ensure it is cached
yield client
with patch(
"ohsome.clients._OhsomeInfoClient.metadata",
new_callable=PropertyMock,
return_value=mocked_metadata,
):
client = ohsome.OhsomeClient(log_dir=temp_directory)
yield client


@pytest.fixture
def base_client_without_log(mocked_metadata):
"""Session-wide test client."""
client = ohsome.OhsomeClient(log=False)
assert client.metadata # call metadata once to ensure it is cached
yield client
with patch(
"ohsome.clients._OhsomeInfoClient.metadata",
new_callable=PropertyMock,
return_value=mocked_metadata,
):
client = ohsome.OhsomeClient(log=False)
yield client


@pytest.fixture
Expand Down

0 comments on commit 7cb9181

Please sign in to comment.