class MongoDBAuthenticationBackendTestCase(unittest2.TestCase): hash_function = MongoDBAuthenticationBackend._hash_function fixtures = [ { 'username': '******', 'salt': 'salty', 'password': hash_function('saltytestpassword').hexdigest() } ] def setUp(self): self._backend = MongoDBAuthenticationBackend(db_name='st2authtest') # Clear database self._backend._collection.remove() # Add fixtures for fixture in self.fixtures: self._backend._collection.insert(fixture) def tearDown(self): # Clear database self._backend._collection.remove() def test_authenticate(self): # Inexistent user self.assertFalse(self._backend.authenticate(username='******', password='******')) # Existent user, invalid password self.assertFalse(self._backend.authenticate(username='******', password='******')) # Valid password self.assertTrue(self._backend.authenticate(username='******', password='******'))
def setUp(self): self._backend = MongoDBAuthenticationBackend(db_name='st2authtest') # Clear database self._backend._collection.remove() # Add fixtures for fixture in self.fixtures: self._backend._collection.insert(fixture)