def test_lazy_proctor_groups_load_with_none_dict(self, mock_load_group_dict): mock_load_group_dict.return_value = None params = create_proctor_parameters({'account': 1234}, defined_tests=['fake_proctor_test']) lazy_proctor_groups = LazyProctorGroups(params) try: lazy_proctor_groups.load() except AttributeError: pytest.fail("Attribute error thrown on proctor group load when loading with self._group_dict == None")
def test_proctor_response_and_cacher_are_none(self, mock_call_proctor_identify): mock_call_proctor_identify.return_value = None params = create_proctor_parameters({'account': 1234}, defined_tests=['fake_proctor_test']) # Call load_group_dict with a cacher set to None (default) group = identify.load_group_dict(params) # There should be no exceptions raised and the group value should be the default assert group['fake_proctor_test'].value is None
def test_response_has_no_group_data(self): params = create_proctor_parameters({}) mock_requests = mock_http_get_json({'data': {}}) # When with patch_python_logger() as mock_logger: identify.identify_groups(params, http=mock_requests) # Then mock_logger.error.assert_called_once_with(ANY, ANY, 'missing groups field', ANY)
def test_cached_result_used(self): params = create_proctor_parameters({'account': 1234}, defined_tests=['fake_proctor_test']) mock_requests = mock_http_get_data({'fake_proctor_test': {'name': 'active', 'value': 1}}) cacher = cache.CacheCacher() # When called twice identify.identify_groups(params, cacher=cacher, http=mock_requests) identify.identify_groups(params, cacher=cacher, http=mock_requests) # Then request only made once mock_requests.get.assert_called_once()
def test_lazy_proctor_groups_load_with_none_dict(self, mock_load_group_dict): mock_load_group_dict.return_value = None params = create_proctor_parameters({'account': 1234}, defined_tests=['fake_proctor_test']) lazy_proctor_groups = LazyProctorGroups(params) try: lazy_proctor_groups.load() except AttributeError: pytest.fail( "Attribute error thrown when loading with self._group_dict == None" )
def test_api_error_message(self): params = create_proctor_parameters({}) mock_requests = mock_http_get_data( group_data={}, added_data={'meta': {'error': 'scary message'}}, status_code=500, ) # When with patch_python_logger() as mock_logger: identify.identify_groups(params, http=mock_requests) # Then mock_logger.error.assert_called_once_with(ANY, ANY, ANY, ANY, 'scary message')
def test_requested_group_resolved(self): params = create_proctor_parameters({'account': 1234}, defined_tests=['fake_proctor_test']) mock_requests = mock_http_get_data({'fake_proctor_test': {'name': 'active', 'value': 1}}) # When groups = identify.identify_groups(params, http=mock_requests) # Then mock_requests.get.assert_called_once_with( 'fake-proctor-api-url/groups/identify', params={'id.account': 1234, 'ctx.ua': '', 'test': 'fake_proctor_test'}, timeout=ANY, ) assert groups.fake_proctor_test.value == 1 assert groups.fake_proctor_test.group == 'active'
def test_cached_result_used(self): params = create_proctor_parameters({'account': 1234}, defined_tests=['fake_proctor_test']) mock_requests = mock_http_get_data( {'fake_proctor_test': { 'name': 'active', 'value': 1 }}) cacher = cache.CacheCacher() # When called twice identify.identify_groups(params, cacher=cacher, http=mock_requests) identify.identify_groups(params, cacher=cacher, http=mock_requests) # Then request only made once mock_requests.get.assert_called_once()
def test_api_error_message(self): params = create_proctor_parameters({}) mock_requests = mock_http_get_data( group_data={}, added_data={'meta': { 'error': 'scary message' }}, status_code=500, ) # When with patch_python_logger() as mock_logger: identify.identify_groups(params, http=mock_requests) # Then mock_logger.error.assert_called_once_with(ANY, ANY, ANY, ANY, 'scary message')
def test_requested_group_resolved(self): params = create_proctor_parameters({'account': 1234}, defined_tests=['fake_proctor_test']) mock_requests = mock_http_get_data( {'fake_proctor_test': { 'name': 'active', 'value': 1 }}) # When groups = identify.identify_groups(params, http=mock_requests) # Then mock_requests.get.assert_called_once_with( 'fake-proctor-api-url/groups/identify', params={ 'id.account': 1234, 'ctx.ua': '', 'test': 'fake_proctor_test' }, timeout=ANY, ) assert groups.fake_proctor_test.value == 1 assert groups.fake_proctor_test.group == 'active'