Example #1
0
def test_change_password():
    response = register('test_user', '12345678', '1111111111')
    assert response.status_code == 200
    assert 'Successfully created new account for test_user' in str(
        response.data)
    response = login('test_user', '12345678')
    assert response.status_code == 200
    response = test_client.get(
        '/settings',
        follow_redirects=True)
    assert response.status_code == 200
    response = test_client.post(
        '/settings',
        data=dict(
            current_password='******',
            new_password='******',
            new_password_check='dankmemes',
        ),
        follow_redirects=True)
    assert response.status_code == 200
    assert "Successfully changed password" in str(response.data)
    response = logout()
    assert response.status_code == 200
    assert 'test_user' not in str(response.data)
    response = login('test_user', '12345678')
    assert response.status_code == 200
    assert 'test_user' not in str(response.data)
    response = login('test_user', 'dankmemes')
    assert response.status_code == 200
    assert 'test_user' in str(response.data)

    # We have to do this to prevent test_client issues.
    logout()
Example #2
0
    def test_login_with_valid_credentials_should_redirect_to_user_specific_page(
            self):
        credentials = {'username': '******', 'password': '******'}
        response = test_client.post('/users/login',
                                    data=credentials,
                                    follow_redirects=True)

        self.assertIn(b'Student Homepage', response.data)
Example #3
0
    def test_student_successfully_enroll_in_a_course(self):
        credentials = {'username': '******', 'password': '******'}
        test_client.post('/users/login',
                         data=credentials,
                         follow_redirects=True)  # login first

        response = test_client.get('/courses/1')
        self.assertIn(b'Student count: 0', response.data)
        self.assertIn(b'You can enroll in this course.', response.data)

        response = test_client.post('/courses/1/enroll', follow_redirects=True)
        self.assertIn(b'Student Homepage', response.data)
        self.assertIn(b'Basic Course', response.data)

        response = test_client.get('/courses/1')
        self.assertIn(b'Student count: 1', response.data)
        self.assertIn(b'You are enrolled in this course.', response.data)
Example #4
0
    def test_login_with_invalid_credentials_should_show_error_message(self):
        credentials = {
            'username': '******',
            'password': "******"
        }
        response = test_client.post('/users/login',
                                    data=credentials,
                                    follow_redirects=True)

        self.assertIn(b'Invalid credentials', response.data)
Example #5
0
def test_mismatched_passwords():
    response = register('test_user', '12345678', '1111111111')
    assert response.status_code == 200
    assert 'Successfully created new account for test_user' in str(
        response.data)
    response = login('test_user', '12345678')
    assert response.status_code == 200
    response = test_client.get(
        '/settings',
        follow_redirects=True)
    assert response.status_code == 200
    response = test_client.post(
        '/settings',
        data=dict(
            current_password='******',
            new_password='******',
            new_password_check='surrealmemes',
        ),
        follow_redirects=True)
    assert response.status_code == 200
    assert "New passwords do not match" in str(response.data)
    logout()
Example #6
0
def test_bad_password():
    response = register('test_user', '12345678', '1111111111')
    assert response.status_code == 200
    assert 'Successfully created new account for test_user' in str(
        response.data)
    response = login('test_user', '12345678')
    assert response.status_code == 200
    response = test_client.get(
        '/settings',
        follow_redirects=True)
    assert response.status_code == 200
    response = test_client.post(
        '/settings',
        data=dict(
            current_password='******',
            new_password='******',
            new_password_check='dankmemes',
        ),
        follow_redirects=True)
    assert response.status_code == 200
    assert "Current password is invalid" in str(response.data)
    logout()