def test_create_user_role_ok_response(self, mock_andela_service_get_user, mock_role_controller_request_params, mock_auth_get_location, mock_user_role_repo_get_unpaginated, mock_role_repo_get, mock_user_role_repo_new_user_role): '''Test create_user_role when user is already assigned to the role. ''' # Arrange with self.app.app_context(): mock_role_controller_request_params.return_value = ( 1, '*****@*****.**') mock_andela_service_get_user.return_value = { 'id': 1, 'mail': '*****@*****.**' } mock_auth_get_location.return_value = 1 mock_user_role_repo_get_unpaginated.return_value = None mock_role_repo_get.return_value = self.mock_role mock_user_role_repo_new_user_role.return_value = \ self.mock_user_role role_controler = RoleController(self.request_context) # Act result = role_controler.create_user_role() # Assert assert result.status_code == 201 assert result.get_json()['msg'] == 'OK'
def test_create_user_role_when_user_already_assigned_to_role( self, mock_andela_service_get_user, mock_role_controller_request_params, mock_auth_get_location, mock_user_role_repo_get_unpaginated): '''Test create_user_role when user is already assigned to the role. ''' # Arrange with self.app.app_context(): mock_role_controller_request_params.return_value = ( 1, '*****@*****.**') mock_andela_service_get_user.return_value = { 'id': 1, 'mail': '*****@*****.**' } mock_auth_get_location.return_value = 1 mock_user_role_repo_get_unpaginated.return_value = \ self.mock_user_role role_controler = RoleController(self.request_context) # Act result = role_controler.create_user_role() # Assert assert result.status_code == 400 assert result.get_json()['msg'] == 'This User ' \ 'has this Role already'
def test_create_user_role_ok_response( self, mock_user_repo_find_first, mock_role_controller_request_params, mock_auth_get_location, mock_user_role_repo_get_unpaginated, mock_role_repo_get, mock_user_role_repo_new_user_role, ): """Test create_user_role when user is already assigned to the role.""" # Arrange with self.app.app_context(): mock_role_controller_request_params.return_value = (1, "*****@*****.**") mock_auth_get_location.return_value = 1 mock_user_repo_find_first.return_value = self.mock_user mock_user_role_repo_get_unpaginated.return_value = None mock_role_repo_get.return_value = self.mock_role mock_user_role_repo_new_user_role.return_value = self.mock_user_role role_controller = RoleController(self.request_context) # Act result = role_controller.create_user_role() # Assert assert result.status_code == 201 assert result.get_json()["msg"] == "OK"
def test_create_user_role_when_user_doesnot_exist( self, mock_andela_service_get_user, mock_role_controller_request_params, mock_auth_get_location): '''Test create_user_role when user doesn't exist. ''' # Arrange with self.app.app_context(): mock_role_controller_request_params.return_value = ( 1, '*****@*****.**') mock_andela_service_get_user.return_value = None mock_auth_get_location.return_value = 1 role_controler = RoleController(self.request_context) # Act result = role_controler.create_user_role() # Assert assert result.status_code == 400 assert result.get_json()['msg'] == 'This user record does' \ ' not exist'
def test_create_user_role_when_user_doesnot_exist( self, mock_user_repo_find_first, mock_role_controller_request_params, mock_auth_get_location, ): """Test create_user_role when user doesn't exist.""" # Arrange with self.app.app_context(): mock_role_controller_request_params.return_value = (1, "*****@*****.**") mock_user_repo_find_first.return_value = None mock_auth_get_location.return_value = 1 role_controler = RoleController(self.request_context) # Act result = role_controler.create_user_role() # Assert assert result.status_code == 400 assert result.get_json()["msg"] == "This user record does not exist"
def test_create_user_role_when_user_already_assigned_to_role( self, mock_user_repo_find_first, mock_role_controller_request_params, mock_auth_get_location, mock_user_role_repo_get_unpaginated, ): """Test create_user_role when user is already assigned to the role.""" # Arrange with self.app.app_context(): mock_role_controller_request_params.return_value = (1, "*****@*****.**") mock_user_repo_find_first.return_value = self.mock_user mock_auth_get_location.return_value = 1 mock_user_role_repo_get_unpaginated.return_value = self.mock_user_role role_controler = RoleController(self.request_context) # Act result = role_controler.create_user_role() # Assert assert result.status_code == 400 assert result.get_json()["msg"] == "This User " "has this Role already"