Пример #1
0
    def test_password(self):
        """UserManager.hash_password and UserManager.check_passwords work"""
        with self.app.app_context():
            user = {
                    "username": "******",
                    "password": user_manager.hash_password("testpassword"),
                    }
            user_manager.collection.save(user)

            fetched_user = user_manager.collection.find_one({"username": "******"})
            self.assertTrue(user_manager.check_passwords("testpassword", fetched_user["password"]))
            self.assertFalse(user_manager.check_passwords("nottestpassword", fetched_user["password"]))
Пример #2
0
    def test_check_login(self):
        """UserManager.check_login returns user or None"""
        with self.app.app_context():
            user = {
                    "username": "******",
                    "password": user_manager.hash_password("testpassword"),
                    }
            user_manager.collection.save(user)

            self.assertNotEqual(user_manager.check_login("Testuser1", "testpassword"), None)
            self.assertEqual(user_manager.check_login("Testuser2", "testpassword"), None)
            self.assertEqual(user_manager.check_login("Testuser1", "nottestpassword"), None)