def test_create_view_addes_a_post(dummy_request, db_session): """Given a complete post create view adds it to the DB.""" assert len(db_session.query(Entry).all()) == 0 dummy_request.method = 'POST' dummy_request.POST = {'title': 'bobs post', 'body': 'stuff'} create_view(dummy_request) assert len(db_session.query(Entry).all()) == 1 assert db_session.query(Entry).first().title == 'bobs post'
def test_create_view_post_request_adds_new_db_item(db_session, dummy_request): """Posting to the create view adds an item.""" from .views.default import create_view dummy_request.method = "POST" dummy_request.POST["title"] = u"this new entry" dummy_request.POST["body"] = u"some text in the body" create_view(dummy_request) new_entry = db_session.query(Journal).first() assert new_entry.title == "this new entry" assert new_entry.body == "some text in the body"
def test_create_view_on_success_redirects(dummy_request): """Test that on creation of a new post redirects.""" dummy_request.method = 'POST' dummy_request.POST = {'title': 'morgans post', 'body': 'cake'} response = create_view(dummy_request) assert response.status_code == 302 assert isinstance(response, HTTPFound)
def test_create_view_post_with_data_redirects(post_request): from pyramid_learning_journal.views.default import create_view from pyramid.httpexceptions import HTTPFound data = {'title': 'blah blah', 'body': 'boo boo boo'} post_request.POST = data response = create_view(post_request) assert response.status_code == 302 assert isinstance(response, HTTPFound)
def test_create_view_post_empty_data_returns_empty_dict(post_request): from pyramid_learning_journal.views.default import create_view post_request.POST = { 'title': '', 'body': '' } response = create_view(post_request) assert response == {'title': '', 'body': ''}
def test_create_view_post_incomplete_data_returns_data(post_request): from pyramid_learning_journal.views.default import create_view data = {'title': 'blah blah', 'body': ''} post_request.POST = data response = create_view(post_request) assert 'title' in response assert 'body' in response assert response['title'] == 'blah blah' assert response['body'] == ''
def test_create_view_with_incomplete_post(dummy_request): """Test that create view returns the partial input.""" dummy_request.method = 'POST' dummy_request.POST = {'title': 'bobs post', 'body': ''} response = create_view(dummy_request) assert response['title'] == 'bobs post'
def test_create_view_returns_dict(dummy_request): """Test create view returns a dict when called.""" assert type(create_view(dummy_request)) == dict
def test_create_view_post_incomplete_data_returns_error(post_request): from pyramid_learning_journal.views.default import create_view data = {'title': '', 'body': ''} post_request.POST = data response = create_view(post_request) assert 'error' in response
def test_create_view_post_empty_data_returns_empty_dict(post_request): from pyramid_learning_journal.views.default import create_view response = create_view(post_request) assert response == {}