def test_update_user_skill_ok_response( self, mock_user_skill_repo_get, mock_user_skill_controller_request_params, mock_user_skill_repo_find_first, ): """Test update_user_skill when role doesn't exist.""" # Arrange with self.app.app_context(): mock_user_skill_repo_get.return_value = self.mock_user_skill mock_user_skill_repo_find_first.return_value = self.mock_user_skill mock_user_skill_controller_request_params.return_value = ( self.user.id, self.mock_user_skill.id, "expert", 5, self.skill_one.id, ) user_skill_controller = UserSkillController(self.request_context) # Act result = user_skill_controller.update_user_skill( self.mock_user_skill.id) print(result) # Assert assert result.status_code == 200 assert result.get_json()["msg"] == "OK" assert (result.get_json()["payload"]["user_skill"]["skill_id"] == self.skill_one.id)
def test_update_user_skill_when_user_skill_doesnot_exist( self, mock_user_skill_repo_get, mock_user_skill_controller_request_params, ): """Test update_user_skill when role doesn't exist.""" # Arrange with self.app.app_context(): mock_user_skill_repo_get.return_value = None mock_user_skill_controller_request_params.return_value = ( None, None, None, None, None, ) user_skill_controller = UserSkillController(self.request_context) # Act result = user_skill_controller.update_user_skill(1) # Assert assert result.status_code == 400 assert (result.get_json()["msg"] == "Invalid or incorrect " "user_skill_id provided")
def test_create_user_skill_ok_response( self, mock_user_skill_repo_find_first, mock_user_skill_controller_request_params, ): """Test create_user_skill OK response.""" # Arrange user = UserFactoryFake.build() with self.app.app_context(): mock_user_skill_controller_request_params.return_value = ( "expert", 5, self.skill_one.id, user.id, ) mock_user_skill_repo_find_first.return_value = None user_skill_controller = UserSkillController(self.request_context) # Act result = user_skill_controller.create_user_skill() # Assert assert result.status_code == 201 assert result.get_json()["msg"] == "OK" assert (result.get_json()["payload"]["user_skill"]["skill_id"] == self.skill_one.id)
def test_get_user_skill_ok_response(self, mock_user_skill_repo_get): """Test get_user_skill OK response.""" # Arrange with self.app.app_context(): mock_user_skill_repo_get.return_value = self.mock_user_skill user_skill_controller = UserSkillController(self.request_context) # Act result = user_skill_controller.get_user_skill(1) # Assert assert result.status_code == 200 assert result.get_json()["msg"] == "OK"
def test_get_user_skill_when_invalid_or_missing(self, mock_user_skill_repo_get): """Test get_user_skill invalid repo response.""" # Arrange with self.app.app_context(): mock_user_skill_repo_get.return_value = None user_skill_controller = UserSkillController(self.request_context) # Act result = user_skill_controller.get_user_skill(99) # Assert assert result.status_code == 400 assert (result.get_json()["msg"] == "Invalid User Project or Missing user_skill_id")
def test_delete_user_skill_ok_response(self, mock_user_skill_repo_update, mock_user_skill_repo_get): """Test delete_user_skill when the role is invalid.""" # Arrange with self.app.app_context(): mock_user_skill_repo_get.return_value = self.mock_user_skill mock_user_skill_repo_update.return_value = self.mock_user_skill user_skill_controller = UserSkillController(self.request_context) # Act result = user_skill_controller.delete_user_skill(1) # Assert assert result.status_code == 200 assert result.get_json()["msg"] == "user skill deleted"
def test_delete_user_skill_when_user_skill_is_invalid( self, mock_user_skill_repo_get): """Test delete_user_skill when the role is invalid.""" # Arrange with self.app.app_context(): mock_user_skill_repo_get.return_value = None user_skill_controller = UserSkillController(self.request_context) # Act result = user_skill_controller.delete_user_skill(1) # Assert assert result.status_code == 404 assert (result.get_json()["msg"] == "Invalid or incorrect " "user_skill_id provided")
def test_list_user_skills_ok_response( self, mock_user_skill_repo_get_unpaginated, ): """Test list_user_skills OK response.""" # Arrange with self.app.app_context(): mock_user_skill_repo_get_unpaginated.return_value.items = [ self.mock_user_skill, ] user_skill_controller = UserSkillController(self.request_context) # Act result = user_skill_controller.list_user_skills(1) # Assert assert result.status_code == 200 assert result.get_json()["msg"] == "OK"
from flask_cors import cross_origin from app.blueprints.base_blueprint import ( Blueprint, BaseBlueprint, request, Security, Auth, ) from app.controllers.user_skill_controller import UserSkillController url_prefix = "{}/user_skill".format(BaseBlueprint.base_url_prefix) user_skill_blueprint = Blueprint("user_skill", __name__, url_prefix=url_prefix) user_skill_controller = UserSkillController(request) @user_skill_blueprint.route("/user/<int:user_id>", methods=["GET"]) # @cross_origin(supports_credentials=True) @Auth.has_permission(["view_user_skill"]) # @swag_from('documentation/get_all_user_skill.yml') def list_user_skills(user_id): return user_skill_controller.list_user_skills(user_id) @user_skill_blueprint.route("/user-single/<int:user_skill_id>", methods=["GET"]) # @cross_origin(supports_credentials=True) @Auth.has_permission(["view_user_skill"]) # @swag_from('documentation/get_user_skill_by_id.yml') def get_user_skill(user_skill_id): return user_skill_controller.get_user_skill(user_skill_id)