def test_return_test_g(self): with app.test_client() as client: a = client.get('/g') self.assertEqual(401, a.status_code) create_one_user(client) b = client.post('/login', data=dict(username='******', password='******'), follow_redirects=True) self.assertEqual(200, b.status_code)
def test_login_logout_inside(self): with app.test_client() as client: username, password = create_one_user(client) login_one_user(client, username, password) logout(client) # The decorator login_required catch the function and return 'no_login.html', 411 self.assertEqual(411, client.get('/inside').status_code)
def test_login_one_user(self): with app.test_client() as client: username, password = create_one_user(client) login_one_user(client, username, password) # We check if user was logged in, we verify it, requesting the session with client.session_transaction() as sess: self.assertEqual(username, sess.get('username'))
def test_create_one_user_no_mail_validation(self): with app.test_client() as client: username, password = create_one_user(client) self.assertNotEqual(None, User.query.filter_by(id=username).first()) with client.session_transaction() as sess: self.assertEqual(None, sess.get('username'))
def test_login_then_logout_two_times(self): with app.test_client() as client: username, password = create_one_user(client) login_one_user(client, username, password) # First logout should work as normal self.assertEqual(200, client.get('/logout').status_code) # Decorator login_required catch the function and return 'no_login.html', 411 self.assertEqual(411, client.get('/logout').status_code)
def test_login_3_users_logout_2(self): with app.test_client() as client: username1, password1 = create_one_user(client, username="******", email="*****@*****.**") username2, password2 = create_one_user(client, username="******", email="*****@*****.**") username3, password3 = create_one_user(client, username="******", email="*****@*****.**") login_one_user(client, username1, password1) login_one_user(client, username2, password2) login_one_user(client, username3, password3) # First logout should work as normal self.assertEqual(200, client.get('/logout').status_code) # Decorator login_required catch the function and return 'no_login.html', 411 self.assertEqual(411, client.get('/logout').status_code)
def test_sign_in_one_user_check_session(self): with app.test_client() as client: username, password = create_one_user(client) # We sign in with the recent user self.assertEqual( 200, client.post('/login', data=dict(username=username, password=password), follow_redirects=True).status_code) # We check if user's session was caught with client.session_transaction() as sess: self.assertEqual('Fernando', sess.get('username', None))
def test_sign_in_bad_username(self): with app.test_client() as client: username, password = create_one_user(client) # We sign in with the recent user self.assertEqual( 450, client.post('/login', data=dict(username='******', password='******'), follow_redirects=True).status_code) # We check if user's session was caught, result should be None cause it was not supposed to be in with client.session_transaction() as sess: self.assertEqual(None, sess.get('username', None))
def test_sign_in_short_username(self): with app.test_client() as client: username, password = create_one_user(client) # We sign in with the recent user self.assertEqual( 800, client.post('/login', data=dict(username='******', password=password), follow_redirects=True).status_code) # 800 means it was a successful GET, or an invalid POST FORM # We check if user's session was caught, result should be None cause it was not supposed to be in with client.session_transaction() as sess: self.assertEqual(None, sess.get('username', None))
def test_sing_in_two_times_same_user(self): with app.test_client() as client: username, password = create_one_user(client) # We log in two times the user self.assertEqual( 200, client.post('/login', data=dict(username=username, password=password), follow_redirects=True).status_code) self.assertEqual( 200, client.post('/login', data=dict(username=username, password=password), follow_redirects=True).status_code) # We check last session, should be the user, our app does not care about double log in yet with client.session_transaction() as sess: self.assertEqual("Fernando", sess.get("username"))
def test_login_then_logout(self): with app.test_client() as client: username, password = create_one_user(client) login_one_user(client, username, password) self.assertEqual(200, client.get('/logout').status_code)
def test_inside_without_login(self): with app.test_client() as client: create_one_user(client) # The decorator login_required catch the function and return 'no_login.html', 411 self.assertEqual(411, client.get('/inside', follow_redirects=True).status_code)
def test_create_one_user(self): with app.test_client() as client: username, password = create_one_user(client) # We check if user was saved in the database self.assertNotEqual(None, User.query.filter_by(id=username).first())