def test_main_page(self): with self.app as a: register(self.app, 'test123', '*****@*****.**', 'cat', 'cat', True) login(a, 'test123', 'cat', True) response = self.app.get('/', follow_redirects=True) self.assertEqual(response.status_code, 200)
def test_user_invalid_credentials(self): response = login(self.app, 'invalihhhhd', 'abc123', follow_redirects=True) self.assertIn(b'Invalid username or password', response.data) response = login(self.app, 'tester', 'abc1234', follow_redirects=True) self.assertIn(b'Invalid username or password', response.data)
def test_user_login(self): user = User(username='******', email='*****@*****.**') user.set_password('abc123') db.session.add(user) db.session.commit() response = login(self.app, 'tester', 'abc123', follow_redirects=True) self.assertEqual(200, response.status_code) response = login(self.app, 'invalid', 'abc123', follow_redirects=False) self.assertEqual('http://localhost/index', response.location)
def test_index(self): with self.app as a: login(a, 'test123', 'cat', True) response = self.app.get('index') self.assertEqual(200, response.status_code) self.assertIn(b'Hello, test123!', response.data)
def test_valid_recipe_added(self): with self.app: login(self.app, 'test123', 'cat', True) response = add_recipe(self.app, submitted_by_user_id=1, follow_redirects=True) self.assertEqual(200, response.status_code)