def test_invalid_user_registration_duplicate_username(self): response = register(self.app, 'testuser', '*****@*****.**', 'FlaskIsAwesome', 'FlaskIsAwesome', True) self.assertEqual(response.status_code, 200) response = register(self.app, 'testuser', '*****@*****.**', 'FlaskIsAwesome', 'FlaskIsAwesome', True) self.assertIn(b'Please use a different username.', response.data)
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 setUp(self): app = create_app(TestConfig) self.app_context = app.app_context() self.app_context.push() self.app = app.test_client() db.create_all() register(self.app, 'test123', '*****@*****.**', 'cat', 'cat', True)
def test_invalid_user_registration_different_passwords(self): response = register(self.app, 'testuser', '*****@*****.**', 'FlaskIsAwesome', 'FlaskIsNotAwesome', True) self.assertIn(b'Field must be equal to password.', response.data)
def test_valid_user_registration_redirect(self): response = register(self.app, 'testuser', '*****@*****.**', 'FlaskIsAwesome', 'FlaskIsAwesome', False) self.assertEqual('http://localhost/auth/login', response.location)
def test_valid_user_registration(self): response = register(self.app, 'testuser', '*****@*****.**', 'FlaskIsAwesome', 'FlaskIsAwesome', True) self.assertEqual(200, response.status_code) self.assertIn(b'Congratulations, you are now a registered user!', response.data)