"""conftest. This file gets picked up when running py.test tests: http://pytest.org/latest/writing_plugins.html#conftest """ import application from owslogger import flask_logger import pytest from lyrics.constants import header as header_consts @pytest.fixture def client(): """Return flask test client. Returns: flask client: flask test client """ return application.app.test_client() @pytest.fixture def context(): """Return flask app context, including a mock logger. Returns: AppContext: flask app context, including a mock logger. """ class MockLog(): """Mock Logging Class.""" def error(self): pass def info(self): pass def warning(self): pass context = application.app.app_context() context.g.ows = flask_logger.Ows() context.g.ows.log = MockLog return context @pytest.fixture def client_headers(): """Return test headers when using test client for functional tests. Returns: dict: header values. """ return { header_consts.CORRELATION_ID: 'abc-123', header_consts.CONTENT_TYPE: header_consts.CONTENT_TYPE_JSON_VAL, } @pytest.fixture def grass_headers(): """Return test headers when using test client for functional tests. Returns: dict: header values. """ return { header_consts.GRASS_ACCOUNT_TYPE: header_consts.GRASS_ACCOUNT_TYPE_VENDOR, header_consts.GRASS_ACCOUNT_ID: '1234', header_consts.CORRELATION_ID: 'abc-123', header_consts.CONTENT_TYPE: header_consts.CONTENT_TYPE_JSON_VAL, header_consts.ORCHARD_USER_ID: 'alw:123' } @pytest.fixture def grass_oa_headers(): """Return oa user headers when using test client for functional tests. Returns: dict: header values. """ return { header_consts.ORCHARD_USER_ID: '{}:1234'.format( header_consts.GRASS_ACCOUNT_TYPE_OA), header_consts.CORRELATION_ID: 'abc-123', header_consts.CONTENT_TYPE: header_consts.CONTENT_TYPE_JSON_VAL, } @pytest.fixture def authorization_mock(mocker): """Mock get_authorization in owsrequest.""" get_authorization = mocker.patch('owsrequest.model.get_authorization') get_authorization.return_value = { 'authorization': 'ows-lyrics:randomhmac123', 'created_at': 1580458555, 'secret': 'randomsecret123', 'sender': 'ows-track' }