def test_two_factor_check_without_feature_flag(self): mock_fn_to_call = Mock(return_value="Function was called!") mock_fn_to_call.__name__ = 'test_name' request = self.request api_key = None view_func = 'dummy_view_func' two_factor_check_fn = two_factor_check(view_func, api_key) function_getting_checked_with_auth = two_factor_check_fn(mock_fn_to_call) with mock.patch('corehq.apps.domain.decorators._ensure_request_couch_user', return_value=request.couch_user): response = function_getting_checked_with_auth(request, self.domain.name) self.assertEqual(response, 'Function was called!') mock_fn_to_call.assert_called_once()
def test_two_factor_check_without_feature_flag(self): mock_fn_to_call = Mock(return_value="Function was called!") mock_fn_to_call.__name__ = 'test_name' if six.PY3 else b'test_name' request = self.request api_key = None view_func = 'dummy_view_func' two_factor_check_fn = two_factor_check(view_func, api_key) function_getting_checked_with_auth = two_factor_check_fn(mock_fn_to_call) with mock.patch('corehq.apps.domain.decorators._ensure_request_couch_user', return_value=request.couch_user): response = function_getting_checked_with_auth(request, self.domain.name) self.assertEqual(response, 'Function was called!') mock_fn_to_call.assert_called_once()
def test_two_factor_check_with_feature_flag(self): mock_fn_to_call = Mock(return_value='Function was called!') mock_fn_to_call.__name__ = 'test_name' request = self.request api_key = None view_func = 'dummy_view_func' two_factor_check_fn = two_factor_check(view_func, api_key) function_getting_checked_with_auth = two_factor_check_fn(mock_fn_to_call) with mock.patch('corehq.apps.domain.decorators._ensure_request_couch_user', return_value=request.couch_user): response = function_getting_checked_with_auth(request, self.domain.name) self.assertEqual(response.status_code, 401) mock_fn_to_call.assert_not_called() data = json.loads(response.content) self.assertDictEqual(data, OTP_AUTH_FAIL_RESPONSE)
def test_two_factor_check_with_feature_flag(self): mock_fn_to_call = Mock(return_value='Function was called!') mock_fn_to_call.__name__ = 'test_name' if six.PY3 else b'test_name' request = self.request api_key = None view_func = 'dummy_view_func' two_factor_check_fn = two_factor_check(view_func, api_key) function_getting_checked_with_auth = two_factor_check_fn(mock_fn_to_call) with mock.patch('corehq.apps.domain.decorators._ensure_request_couch_user', return_value=request.couch_user): response = function_getting_checked_with_auth(request, self.domain.name) self.assertEqual(response.status_code, 401) mock_fn_to_call.assert_not_called() data = json.loads(response.content) self.assertDictEqual(data, OTP_AUTH_FAIL_RESPONSE)
def test_two_factor_check_with_feature_flag(self): mock_fn_to_call = Mock(return_value='Function was called!') mock_fn_to_call.__name__ = b'test_name' request = self.request api_key = None view_func = 'dummy_view_func' two_factor_check_fn = two_factor_check(view_func, api_key) function_getting_checked_with_auth = two_factor_check_fn( mock_fn_to_call) with mock.patch( 'corehq.apps.domain.decorators._ensure_request_couch_user', return_value=request.couch_user): response = function_getting_checked_with_auth( request, self.domain.name) data = json.loads(response.content) mock_fn_to_call.assert_not_called() self.assertDictEqual( data, {'error': 'must send X-CommcareHQ-OTP header'})