Пример #1
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()
Пример #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
Пример #5
0
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
Пример #17
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_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