|
2 | 2 | # -*- coding: utf-8 -*-
|
3 | 3 | """Conftest for shared pytest fixtures"""
|
4 | 4 | import logging
|
| 5 | +from unittest.mock import patch, PropertyMock |
| 6 | + |
5 | 7 | import pytest
|
| 8 | +from urllib3 import Retry |
| 9 | + |
6 | 10 | import ohsome
|
7 | 11 |
|
8 | 12 | logger = logging.getLogger(__name__)
|
9 | 13 |
|
10 | 14 |
|
| 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 | + |
11 | 50 | @pytest.fixture
|
12 | 51 | def base_client(mocked_metadata, tmpdir_factory):
|
13 | 52 | """Session-wide test client."""
|
14 | 53 | 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 |
18 | 61 |
|
19 | 62 |
|
20 | 63 | @pytest.fixture
|
21 | 64 | def base_client_without_log(mocked_metadata):
|
22 | 65 | """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 |
26 | 73 |
|
27 | 74 |
|
28 | 75 | @pytest.fixture
|
|
0 commit comments