def test_app():
    """configure our app for use in testing"""
    app.config['DATABASE'] = TEST_DSN
    app.config['TESTING'] = True
    init_db()

    with app.test_request_context('/'):
        app.test_client().post(
            '/add', data=lettuce.world.entry_data, follow_redirects=True)
        # manually commit transaction here to avoid rollback
        # due to handled Exception
        get_database_connection().commit()
示例#2
0
def test_app():
    """configure our app for use in testing"""
    app.config['DATABASE'] = TEST_DSN
    app.config['TESTING'] = True
    init_db()

    with app.test_request_context('/'):
        app.test_client().post('/add',
                               data=lettuce.world.entry_data,
                               follow_redirects=True)
        # manually commit transaction here to avoid rollback
        # due to handled Exception
        get_database_connection().commit()
示例#3
0
def test_start_as_anonymous(db):

    client = app.test_client()

    anon_home = client.get('/').data

    assert SUBMIT_BTN not in anon_home
示例#4
0
def test_logout(db):
    home = login_helper('admin', 'admin').data
    assert SUBMIT_BTN in home
    client = app.test_client()
    response = client.get('/logout')
    assert SUBMIT_BTN not in response.data
    assert response.status_code == 302
def test_update_entry(db):
    entry_data = {
        u'title': u'Hello',
        u'text': u'This is a post',
        }
    with app.test_client() as c:
        actual = c.post(
            '/add', data=entry_data, follow_redirects=True
            ).data
        assert 'No entries here so far' not in actual
        for expected in entry_data.values():
            assert expected in actual

        """
        CMGTODO: How to test the edit?

        edit_data = {
            u'title':  u"Hello Again",
            u'text':   u"This is an edited post",
        }
        actual = c.post(
            '/submit/1', data=edit_data, follow_redirects=True
            ).data
        for expected in edit_data.values():
            assert expected in actual
        """

    return
示例#6
0
def test_logout(db):
    home = login_helper('admin', 'admin').data
    assert SUBMIT_BTN in home
    client = app.test_client()
    response = client.get('/logout')
    assert SUBMIT_BTN not in response.data
    assert response.status_code == 302
示例#7
0
def login_helper(username, password):
    login_data = {
        'username': username, 'password': password
    }
    client = app.test_client()
    return client.post(
        '/login', data=login_data, follow_redirects=True)
示例#8
0
def click_edit(step):
    login_data = {
        'username': '******', 'password': '******'
    }
    with app.test_client() as c:
        c.post('/login', data=login_data)  # Logically this should be in the
        response = c.get('/edit/1')        # login step, but it doesn't persist
        world.page = response.data
示例#9
0
def use_update_form(step, string1):
    entry_data = {
        'title': string1,
        'text': string1
    }
    world.page = app.test_client().post(
        '/update/1', data=entry_data, follow_redirects=True
    ).data
def login_helper(username, password):
    login_data = {
        'username': username, 'password': password
    }
    client = app.test_client()
    return client.post(
        '/login', data=login_data, follow_redirects=True
    )
示例#11
0
def test_listing(with_entry):

    expected = with_entry
    actual = app.test_client().get('/').data

    for value in expected:

        assert value in actual
示例#12
0
def login(step):
    login_data = {
        'username': '******', 'password': '******'
    }
    client = app.test_client()
    response = client.post(
        '/login', data=login_data, follow_redirects=True
    )
    world.page = response.data
示例#13
0
def test_add_entries(db):
    entry_data = {
        u'title': u'Hello',
        u'text': u'This is a post',
    }
    actual = app.test_client().post(
        '/add', data=entry_data, follow_redirects=True).data
    assert 'No entries here so far' not in actual
    for expected in entry_data.values():
        assert expected in actual
示例#14
0
def test_add_entries(db):
    entry_data = {
        u'title': u'Hello',
        u'text': u'This is a post',
    }
    actual = app.test_client().post('/add',
                                    data=entry_data,
                                    follow_redirects=True).data
    assert 'No entries here so far' not in actual
    for expected in entry_data.values():
        assert expected in actual
示例#15
0
def test_empty_listing(db):

    # "app.test_client() returns a mock HTTP client,
    # like a web browser for development."
    # "Because this test actually creates a request, we don't need to use
    # the req_context fixture. Having an initialized database is enough"
    # "The data attribute of the response returned by client.get()
    # holds the full rendered HTML of our page."
    actual = app.test_client().get('/').data
    expected = 'No entries here so far'
    assert expected in actual
示例#16
0
def test_add_entries(db):
    entry_data = {
        u'title': u'Hello',
        u'text': u'This is a post',
    }
    with app.test_client() as c:
        with c.session_transaction() as sess:
            sess['logged_in'] = True
        actual = c.post('/add', data=entry_data, follow_redirects=True).data
    assert 'No entries here so far' not in actual
    for expected in entry_data.values():
        assert expected in actual
def test_add_entries(db):
    entry_data = {
        u'title': u'Hello',
        u'text': u'This is a post',
    }
    with app.test_client() as c:
        with c.session_transaction() as sess:
            sess['logged_in'] = True
        actual = c.post(
            '/add', data=entry_data, follow_redirects=True).data
    assert 'No entries here so far' not in actual
    for expected in entry_data.values():
        assert expected in actual
def test_edit_entries(req_context):
    entry_data = {
        u'title': u'Hello2',
        u'text': u'This is a post2',
    }
    actual = ''
    with app.test_client() as c:
        with c.session_transaction() as sess:
            sess['logged_in'] = True
        actual = c.post(
            '/edit/4?id=4', data=entry_data, follow_redirects=True).data
    assert actual != ''
    assert 'No entries here so far' not in actual
    for expected in entry_data.values():
        assert expected in actual
示例#19
0
def test_add_entries(db):

    entry_data = {
        u'title': u'Hello',
        u'text': u'This is a post',
    }

    # "The post method of the Flask test_client sends an HTTP POST
    # request to the provided URL."
    actual = app.test_client().post(
        '/add', data=entry_data, follow_redirects=True
    ).data

    assert 'No entries here so far' not in actual

    for expected in entry_data.values():

        # "assert that the line in entry data is also in the actual data"
        assert expected in actual
示例#20
0
def test_listing(with_entry):
    expected = with_entry
    actual = app.test_client().get('/').data
    for value in expected:
        assert value in actual
示例#21
0
def anonymous_user(step):
    with app.test_client() as client:
        lettuce.world.client = client
示例#22
0
def logged_in_user(step):
    with app.test_client() as client:
        with client.session_transaction() as sess:
            sess['logged_in'] = True
        lettuce.world.client = client
示例#23
0
def test_empty_listing(db):
    actual = app.test_client().get('/').data
    expected = 'No entries here so far'
    assert expected in actual
示例#24
0
def test_empty_listing(db):
    # returns the html of the page as a string
    actual = app.test_client().get('/').data
    expected = 'No entries here so far'
    # checks to see if expected is a substring of actual
    assert expected in actual
示例#25
0
def anonymous_user(step):
    with app.test_client() as client:
        with client.session_transaction() as sess:
            sess['logged_in'] = False
        lettuce.world.client = client
示例#26
0
def logged_in_user(step):
    with app.test_client() as client:
        with client.session_transaction() as sess:
            sess['logged_in'] = True
        lettuce.world.client = client
示例#27
0
def anonymous_user(step):
    with app.test_client() as client:
        with client.session_transaction() as sess:
            sess['logged_in'] = False
        lettuce.world.client = client
示例#28
0
def logout(step):
    client = app.test_client()
    response = client.get('/')
    world.page = response.data
示例#29
0
def test_start_as_anonymous(db):
    client = app.test_client()
    anon_home = client.get('/').data
    assert SUBMIT_BTN not in anon_home
示例#30
0
def post_contains(step):
    client = app.test_client()
    response = client.get('/')
    print response.data
    assert step.multiline in response.data
示例#31
0
def test_empty_listing(db):
    actual = app.test_client().get('/').data
    expected = 'No entries here so far'
    assert expected in actual
示例#32
0
def anonymous_user(step):
    with app.test_client() as client:
        lettuce.world.client = client