コード例 #1
0
    def __then_user_object_is_saved_in_db(self):
        user = UserModel.find_all()[-1]
        is_password_correct = check_password_hash(user.password,
                                                  self.data["password"])

        self.assertEqual(user.username, self.data["username"])
        self.assertTrue(is_password_correct)
コード例 #2
0
    def test_find_all(self):
        """Test if all the users which exist in the database are returned"""
        user1 = self._create_sample_user("test1")
        user2 = self._create_sample_user("user2")
        found_users = UserModel.find_all()

        self.assertIn(user1, found_users)
        self.assertIn(user2, found_users)
コード例 #3
0
 def get(cls):
     """Get method"""
     return (
         {
             "users":
             [user_schema.dump(user) for user in UserModel.find_all()]
         },
         200,
     )
コード例 #4
0
    def test_does_not_register_user_if_already_exists(self):
        users_number = len(UserModel.find_all())
        self.__given_test_user_is_created()
        self.__given_existing_data_is_prepared()

        self.__when_post_request_is_sent("register", self.data)

        self.__then_status_code_is_400_bad_request()
        self.__then_no_new_user_is_registered(users_number)
コード例 #5
0
    def test_get_users_data(self):
        """Test if the correct data is returned
        if the logged in user is the admin"""
        self._create_sample_user()

        response = self.client.get(
            path="admin/users/",
            headers={
                "Content-Type": "application/json",
                "Authorization": f"Bearer {self.admin_access_token}",
            },
        )

        users_data = user_list_schema.dump(UserModel.find_all())

        self.assertEqual(len(response.json["users"]), 2)
        self.assertEqual(users_data, response.json["users"])
コード例 #6
0
    def get(cls):
        """Get the user list"""
        claims = get_jwt_claims()
        if not claims["is_admin"]:
            return (
                {
                    "message": "You don't have permission to perform this action."
                },
                403,
            )

        return (
            {
                "users": [
                    user_schema.dump(user) for user in UserModel.find_all()
                ]
            },
            200,
        )
コード例 #7
0
    def test_find_all_no_users(self):
        """Test if an empty list is returned
        if there are no users in the database"""
        found_users = UserModel.find_all()

        self.assertEqual(found_users, [])
コード例 #8
0
 def get(cls):
     # refactor later:
     users_number = len(UserModel.find_all())
     return {"users_number": users_number}, 200
コード例 #9
0
    def __then_no_new_user_is_registered(self, previous_number):
        new_users_number = len(UserModel.find_all())

        self.assertNotEqual(new_users_number, previous_number)
コード例 #10
0
    def __then_correct_user_list_data_is_returned(self):
        trainings_data = user_list_schema.dump(UserModel.find_all())

        self.assertEqual(len(self.response.json["users"]), 2)
        self.assertEqual(self.response.json["users"], trainings_data)