Example #1
0
def test_annotation_flags(popclient):
    """Test the view page for annotation flags for a particular annotation."""
    app, client = popclient

    with app.test_request_context():
        annotation = Annotation.query.first()
        user = User.query.filter_by(email=TESTUSER).first()
        username = user.displayname

        login(user, client)
        flags = AnnotationFlag.enum_cls.query.all()
        for flag in flags:
            AnnotationFlag.flag(annotation, flag, user)
        db.session.commit()
        logout(client)

        user = User.query.filter_by(email=TESTADMIN).first()
        login(user, client)
        url = url_for('admin.annotation_flags', annotation_id=annotation.id)
        entities = AnnotationFlag.query.count()

    max_pages = int(math.ceil(entities / app.config['NOTIFICATIONS_PER_PAGE']))
    sorts = [
        'marked', 'marked_invert', 'flag', 'flag_invert', 'thrower',
        'thrower_invert', 'time', 'time_invert', 'resolver', 'resolver_invert',
        'time_resolved', 'time_resolved_invert'
    ]

    tests = [username]
    looptest(url=url,
             tests=tests,
             sorts=sorts,
             client=client,
             max_pages=max_pages)
Example #2
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 #3
0
def test_login_and_logout(client):
    # Access to logout view before login should fail.
    response = logout(client)
    assert b"Please log in to access this page." in response.data
    register('sam')
    response = login(client, 'sam')
    assert b'Login successful.' in response.data
    # Should successfully logout the currently logged in user.
    response = logout(client)
    assert b"You were logged out." in response.data
    # Incorrect login credentials should fail.
    response = login(client, "sam", "wrongpassword")
    assert b"Wrong user ID or password." in response.data
    # Correct credentials should login
    response = login(client, "sam")
    assert b"Login successful." in response.data
Example #4
0
def test_create_duplicate_user():
    response = register('test_user', '12345678', '1111111111')
    assert response.status_code == 200
    response = logout()
    assert response.status_code == 200
    response = register('test_user', '12345678', '1111111111')
    assert response.status_code == 200
    assert 'Username not available' in str(response.data)
Example #5
0
    def testLogout(self, client):
        rv = register(client, self.app.config['EMAIL'],
                      self.app.config['USERNAME'], self.app.config['PASSWORD'])
        rv = login(client, self.app.config['USERNAME'],
                   self.app.config['PASSWORD'])

        response = logout(client)

        assert 200 == response.status_code
        assert 'Logout successful.' in response.json['message']
Example #6
0
def test_login_and_logout(client):
    # Access to logout view before login should fail.
    response = logout(client)
    assert b"Please log in to access this page." in response.data

    register()
    response = login(client, "*****@*****.**")
    assert response.status_code == 200

    # Should successfully logout the currently logged in user.
    response = logout(client)
    assert response.status_code == 200

    # Incorrect login credentials should fail.
    response = login(client, "*****@*****.**", "wrongpassword")
    assert b"Wrong email or password." in response.data

    # Correct credentials should login
    response = login(client, "*****@*****.**")
    assert response.status_code == 200
Example #7
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 #8
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()
def test_login_logout():
    response = register('test_user', '12345678', '1111111111')
    assert response.status_code == 200
    assert ('Successfully created new account for test_user'
            in str(response.data))
    assert 'Logout' in str(response.data)
    response = login('test_user', '12345678')
    assert response.status_code == 200
    assert 'Logged in successfully' in str(response.data)
    assert 'test_user' in str(response.data)
    response = logout()
    assert response.status_code == 200
    assert 'test_user' not in str(response.data)
    assert 'Logout' not in str(response.data)
def test_bad_logout():
    response = logout()
    assert response.status_code == 401