예제 #1
0
def test_reserved_routes():
    response = client.get('/login')
    data = response.data.decode('utf8')
    assert '<form action="/login" method="post">' in data

    response = client.get('/logout')
    assert response.status_code == 302

    with temp_file('manufactorum/templates/_login.html', 'no content'):
        response = client.get('/login')
        data = response.data.decode('utf8')
        assert '<form action="/login" method="post">' in data
        assert 'no content' not in data

    with temp_file('manufactorum/templates/_logout.html', 'no content'):
        response = client.get('/logout')
        assert response.status_code == 302

    response = client.get('/update-text')
    assert response.status_code == 404

    response = client.post('/update-text')
    assert response.status_code == 401
예제 #2
0
def test_routes():
    response = client.get('/')
    assert response.status_code == 200

    response = client.get('/test_routes')
    assert response.status_code == 404

    content = ('This is my unit test. '
               'There are many like it but this one is mine')
    with temp_file('manufactorum/templates/_test_routes.html', content):
        response = client.get('/test_routes')
        assert response.data.decode('utf8') == content

    cache.clear()

    response = client.get('/test_routes')
    assert response.status_code == 404
예제 #3
0
def test_load_users():
    with temp_file('testusers.dat'):
        with patch('manufactorum.users.USERS_FILE', 'testusers.dat'):
            assert users.load_users() == []

            users.add_user('test_load_users_user',
                           'test_load_users_user_password')

            assert len(users.load_users()) == 1
            assert users.user_exists('test_load_users_user') is True
            assert users.user_exists('Someone') is False

            user = users.get_user('test_load_users_user')
            assert user is not None
            assert user.username == 'test_load_users_user'
            assert user.check_password('test_load_users_user_password') is True

            users.remove_user('test_load_users_user')
예제 #4
0
def test_load_users():
    with temp_file('testusers.dat'):
        with patch('manufactorum.users.USERS_FILE', 'testusers.dat'):
            assert users.load_users() == []

            users.add_user(
                'test_load_users_user',
                'test_load_users_user_password'
            )

            assert len(users.load_users()) == 1
            assert users.user_exists('test_load_users_user') is True
            assert users.user_exists('Someone') is False

            user = users.get_user('test_load_users_user')
            assert user is not None
            assert user.username == 'test_load_users_user'
            assert user.check_password('test_load_users_user_password') is True

            users.remove_user('test_load_users_user')