From b35b6b7839c43df75d01303c2afac7fcb2ffdaee Mon Sep 17 00:00:00 2001 From: ShamaineChung Date: Mon, 19 Feb 2024 10:52:17 +0800 Subject: [PATCH] #1 completed unit testing tutorial --- notes/test_notes_views.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/notes/test_notes_views.py b/notes/test_notes_views.py index c941ec1d..846c4ad5 100644 --- a/notes/test_notes_views.py +++ b/notes/test_notes_views.py @@ -18,3 +18,19 @@ def test_list_endpoint_return_user_notes(client,logged_user): content=str(response.content) assert note.title in content assert 1 ==content.count('

') + +@pytest.mark.django_db +def test_create_endpoint_receives_form_data(client,logged_user): + form_data = {'title':'An Impressive title', 'text':'A really interesting text'} + + response =client.post(path='/smart/notes/new',data = form_data,follow=True) + + assert 200 == response.status_code + + #check if we receive the final template we expect + assert 'notes/notes_list.html' in response.template_name + # to make sure the user has at least 1 note + assert 1 ==logged_user.notes.count() + + +