def test_student_login(self): # Ensure login behaves correctly. with self.client: self.client.get('/logout', follow_redirects=True) response = self.client.post( '/login', data=dict( email='*****@*****.**', password='******', confirm='student_user' ), follow_redirects=True ) self.assertIn( b'Welcome, <em>[email protected]</em>!', response.data ) self.assertIn( b'<li><a href="/student/courses">View Courses</a></li>', response.data ) self.assertIn( b'<li><a href="/password">Update Password</a></li>', response.data ) self.assertTrue(current_user.email == "*****@*****.**") self.assertTrue(current_user.is_authenticated) self.assertTrue(current_user.is_active) self.assertFalse(current_user.is_anonymous()) self.assertTrue(current_user.is_student()) self.assertFalse(current_user.is_teacher()) self.assertFalse(current_user.is_admin()) self.assertEqual(response.status_code, 200)
def test_update_password2(self): # Ensure update password behaves correctly. with self.client: self.client.post( '/login', data=dict( email='*****@*****.**', password='******', ), follow_redirects=True ) response = self.client.post( '/password', data=dict( password='******', confirm='short' ), follow_redirects=True ) self.assertIn( b'<h1>Update Password</h1>', response.data ) self.assertIn( b'Field must be between 6 and 25 characters long.', response.data ) self.assertTrue(current_user.email == '*****@*****.**') self.assertTrue(current_user.is_authenticated()) self.assertTrue(current_user.is_active()) self.assertFalse(current_user.is_anonymous()) self.assertTrue(current_user.is_student()) self.assertFalse(current_user.is_teacher()) self.assertFalse(current_user.is_admin()) self.assertEqual(response.status_code, 200)
def test_update_password(self): # Ensure update password behaves correctly. with self.client: self.client.post('/login', data=dict( email='*****@*****.**', password='******', ), follow_redirects=True) self.client.post('/password', data=dict(password='******', confirm='updated_student_password'), follow_redirects=True) self.client.get('/logout', follow_redirects=True) response = self.client.post( '/login', data=dict( email='*****@*****.**', password='******', ), follow_redirects=True) self.assertIn(b'<h1>Welcome, <em>[email protected]</em>!</h1>', response.data) self.assertTrue(current_user.email == '*****@*****.**') self.assertTrue(current_user.is_authenticated()) self.assertTrue(current_user.is_active()) self.assertFalse(current_user.is_anonymous()) self.assertTrue(current_user.is_student()) self.assertFalse(current_user.is_teacher()) self.assertFalse(current_user.is_admin()) self.assertEqual(response.status_code, 200)
def decorated_function(*args, **kwargs): if current_user.is_student() is False: flash( 'You do not have the correct permissions to view that page.', 'warning' ) return redirect(url_for('user.login', next=request.url)) return f(*args, **kwargs)
def test_student_registration(self): # Ensure registration behaves correctly. with self.client: response = self.client.post('/register', data=dict(email='*****@*****.**', password='******', confirm='testing'), follow_redirects=True) self.assertIn(b'<h1>Welcome, <em>[email protected]</em>!</h1>', response.data) self.assertTrue(current_user.email == '*****@*****.**') self.assertTrue(current_user.is_authenticated()) self.assertTrue(current_user.is_active()) self.assertFalse(current_user.is_anonymous()) self.assertTrue(current_user.is_student()) self.assertFalse(current_user.is_teacher()) self.assertFalse(current_user.is_admin()) self.assertEqual(response.status_code, 200)
def test_student_registration(self): # Ensure registration behaves correctly. with self.client: response = self.client.post('/register', data=dict(email='*****@*****.**', password='******', confirm='student_user'), follow_redirects=True) self.assertIn(b'Welcome, <em>[email protected]</em>!', response.data) self.assertIn( b'<li><a href="/student/courses">View Courses</a></li>', response.data) self.assertTrue(current_user.email == "*****@*****.**") self.assertTrue(current_user.is_authenticated) self.assertTrue(current_user.is_active) self.assertFalse(current_user.is_anonymous()) self.assertTrue(current_user.is_student()) self.assertFalse(current_user.is_teacher()) self.assertFalse(current_user.is_admin()) self.assertEqual(response.status_code, 200)
def test_update_password(self): # Ensure update password behaves correctly. with self.client: self.client.post( '/login', data=dict( email='*****@*****.**', password='******', ), follow_redirects=True ) self.client.post( '/password', data=dict( password='******', confirm='updated_student_password' ), follow_redirects=True ) self.client.get('/logout', follow_redirects=True) response = self.client.post( '/login', data=dict( email='*****@*****.**', password='******', ), follow_redirects=True ) self.assertIn( b'<h1>Welcome, <em>[email protected]</em>!</h1>', response.data ) self.assertTrue(current_user.email == '*****@*****.**') self.assertTrue(current_user.is_authenticated()) self.assertTrue(current_user.is_active()) self.assertFalse(current_user.is_anonymous()) self.assertTrue(current_user.is_student()) self.assertFalse(current_user.is_teacher()) self.assertFalse(current_user.is_admin()) self.assertEqual(response.status_code, 200)
def test_admin_login(self): # Ensure login behaves correctly. with self.client: self.client.get('/logout') response = self.client.post('/login', data=dict(email='*****@*****.**', password='******', confirm='admin_user'), follow_redirects=True) self.assertIn(b'Welcome, <em>[email protected]</em>!', response.data) self.assertIn( b'<li><a href="/admin/dashboard/">Dashboard</a></li>', response.data) self.assertIn(b'<li><a href="/password">Update Password</a></li>', response.data) self.assertTrue(current_user.email == "*****@*****.**") self.assertTrue(current_user.is_authenticated) self.assertTrue(current_user.is_active) self.assertFalse(current_user.is_anonymous()) self.assertFalse(current_user.is_student()) self.assertFalse(current_user.is_teacher()) self.assertTrue(current_user.is_admin()) self.assertEqual(response.status_code, 200)
def test_update_password2(self): # Ensure update password behaves correctly. with self.client: self.client.post('/login', data=dict( email='*****@*****.**', password='******', ), follow_redirects=True) response = self.client.post('/password', data=dict(password='******', confirm='short'), follow_redirects=True) self.assertIn(b'<h1>Update Password</h1>', response.data) self.assertIn(b'Field must be between 6 and 25 characters long.', response.data) self.assertTrue(current_user.email == '*****@*****.**') self.assertTrue(current_user.is_authenticated()) self.assertTrue(current_user.is_active()) self.assertFalse(current_user.is_anonymous()) self.assertTrue(current_user.is_student()) self.assertFalse(current_user.is_teacher()) self.assertFalse(current_user.is_admin()) self.assertEqual(response.status_code, 200)
def test_student_registration(self): # Ensure registration behaves correctly. with self.client: response = self.client.post( '/register', data=dict( email='*****@*****.**', password='******', confirm='testing' ), follow_redirects=True ) self.assertIn( b'<h1>Welcome, <em>[email protected]</em>!</h1>', response.data ) self.assertTrue(current_user.email == '*****@*****.**') self.assertTrue(current_user.is_authenticated()) self.assertTrue(current_user.is_active()) self.assertFalse(current_user.is_anonymous()) self.assertTrue(current_user.is_student()) self.assertFalse(current_user.is_teacher()) self.assertFalse(current_user.is_admin()) self.assertEqual(response.status_code, 200)
def decorated_function(*args, **kwargs): if current_user.is_student() is False: flash('You do not have the correct permissions to view that page.', 'warning') return redirect(url_for('user.login', next=request.url)) return f(*args, **kwargs)