"""Utility for handler testing.""" import copy from project_manager.constant import header_const from project_manager.util import handler_util def test_access_check_success_grass(monkeypatch, header): """Test valid Grass headers in request.""" access_check_response = handler_util.access_check(header) assert access_check_response.status == 200 account_type = access_check_response.message.get('account_type') assert account_type == header[header_const.GRASS_ACCOUNT_TYPE] account_id = access_check_response.message.get('account_id') assert account_id == header[header_const.GRASS_ACCOUNT_ID] def test_access_check_no_grass_headers_success(monkeypatch): """Test valid Grass headers in request.""" access_check_response = handler_util.access_check({}) assert access_check_response.status == 200 assert access_check_response.message.get('account_type') is None assert access_check_response.message.get('account_id') is None def test_access_check_success_non_grass(monkeypatch, header): """Test valid non-Grass headers in request.""" mutated_header = copy.copy(header) mutated_header.pop(header_const.GRASS_ACCOUNT_TYPE) mutated_header.pop(header_const.GRASS_ACCOUNT_ID) access_check_response = handler_util.access_check(mutated_header) assert access_check_response.status == 200 assert access_check_response.message.get('account_type') is None assert access_check_response.message.get('account_id') is None def test_access_check_fail_bad_headers(monkeypatch, header): """Test auth error response when grass account type missing.""" mutated_header = copy.copy(header) mutated_header.pop(header_const.GRASS_ACCOUNT_TYPE) access_check_response = handler_util.access_check(mutated_header) assert access_check_response.status == 403 mutated_header = copy.copy(header) mutated_header.pop(header_const.GRASS_ACCOUNT_ID) access_check_response = handler_util.access_check(mutated_header) assert access_check_response.status == 403