userver: samples/http_caching/tests/conftest.py
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
samples/http_caching/tests/conftest.py
1import pytest
2
3from testsuite import utils
4
5
6# /// [patch configs]
7pytest_plugins = ['pytest_userver.plugins.core']
8
9USERVER_CONFIG_HOOKS = ['userver_config_translations']
10
11
12@pytest.fixture(scope='session')
13def userver_config_translations(mockserver_info):
14 def do_patch(config_yaml, config_vars):
15 components = config_yaml['components_manager']['components']
16 components['cache-http-translations'][
17 'translations-url'
18 ] = mockserver_info.url('v1/translations')
19
20 return do_patch
21 # /// [patch configs]
22
23
24# /// [mockserver]
25@pytest.fixture(autouse=True)
26def mock_translations(mockserver, translations, mocked_time):
27 @mockserver.json_handler('/v1/translations')
28 def mock(request):
29 return {
30 'content': translations,
31 'update_time': utils.timestring(mocked_time.now()),
32 }
33
34 return mock
35 # /// [mockserver]
36
37
38# /// [translations]
39@pytest.fixture
40def translations():
41 return {
42 'hello': {'en': 'hello', 'ru': 'Привет'},
43 'welcome': {'ru': 'Добро пожаловать', 'en': 'Welcome'},
44 }
45 # /// [translations]