Beispiel #1
0
    def setUp(self):
        from sqlalchemy import MetaData

        meta = MetaData(bind=dao.engine)
        meta.reflect()

        for table in reversed(meta.sorted_tables):
            dao.engine.execute(table.delete())

        self.expected_username = "******"
        self.expected_hash = "somehash"
        user = User(username=self.expected_username,
                    hash=self.expected_hash)
        dao.save_user(user)
Beispiel #2
0
    def test_save_user_returns_false_when_the_hash_is_missing(self):
        expected_username = '******'

        user = User(username=expected_username)

        success = dao.save_user(user)
        self.assertFalse(success, "Persisting a user with a missing hash"
                                  "should not succeed.")
Beispiel #3
0
    def test_save_user(self):
        expected_username = '******'
        expected_hash = 'some_hash'

        user = User(username=expected_username, hash=expected_hash)
        success = dao.save_user(user)
        self.assertTrue(success, "The user was not successfully persisted"
                                 "to the database.")

        session = dao.DBSession()
        users = session.query(User).all()

        self.assertEqual(len(users), 1,
                         "Expected only 1 user to be returned!")
        persisted_user = users[0]
        self.assertEqual(expected_username, persisted_user.username,
                         "The persisted username did not match the "
                         "expected username.")
        self.assertEqual(expected_hash, persisted_user.hash,
                         "The persisted hash did not match the expected hash.")