def test_fail_to_create_user_using_existing_username(self): with self.app.app_context(): User.create("user1", "password") try: db.session.commit() except SQLAlchemyError: db.session.rollback() self.fail("failed to commit transaction") User.create("user1", "password") self.assertRaises(IntegrityError, db.session.commit)
def setUp(self): super(PagetagsTestsWithUser, self).setUp() with self.app.app_context(): user = User.create("user1", "password") try: db.session.commit() except SQLAlchemyError: db.session.rollback() self.fail("failed to load mock data") self.test_user_id = user.id self.test_user_username = user.username self.test_user_jti = user.jti self.test_user_password = "******"
def test_create_user(self): with self.app.app_context(): user = User.create("user1", "password") self.assertIsNone(user.id) self.assertEqual(user.username, "user1") self.assertTrue(check_password_hash(user.password, "password")) self.assertIsNotNone(user.jti) try: db.session.commit() except SQLAlchemyError: db.session.rollback() self.fail("failed to commit transaction") self.assertIsNotNone(user.id)
def run(self, username, password): User.create(username, password) db.session.commit()