Example #1
0
    def put(cls, userprofile_id: int):
        """Put method"""
        user_profile = UserProfileModel.find_by_id(userprofile_id)
        if not user_profile:
            return {"message": f"User profile not found."}, 404

        current_user_id = get_jwt_identity()

        if userprofile_id != current_user_id:
            return (
                {
                    "message":
                    "You don't have permission to perform this action."
                },
                403,
            )

        user_profile_data = user_profile_schema.load(request.get_json())
        user_profile.gender = user_profile_data.gender
        user_profile.age = user_profile_data.age
        user_profile.height = user_profile_data.height
        user_profile.weight = user_profile_data.weight
        user_profile.calculate_bmi()

        try:
            user_profile.save_to_db()
        except:
            return (
                {
                    "message":
                    "An error has occurred updating the user profile."
                },
                500,
            )

        return user_profile_schema.dump(user_profile), 200
    def test_find_by_id_no_user(self):
        """Test if None is returned
        if the user profile with the given id doesn't exist"""
        found_userprofile = UserProfileModel.find_by_id(1)

        self.assertIsNone(found_userprofile)
    def test_find_by_id(self):
        """Test if the user profile is found"""
        self._create_sample_user("test")
        found_userprofile = UserProfileModel.find_by_id(1)

        self.assertIsNotNone(found_userprofile)
Example #4
0
    def __given_user_profile_is_none(self, user_profile_id):
        user_profile = UserProfileModel.find_by_id(user_profile_id)

        self.assertIsNone(user_profile)