From 013fa4f45b812aaeec219cb75abd40922f7bd528 Mon Sep 17 00:00:00 2001 From: DEENUU1 Date: Sat, 9 Dec 2023 09:45:42 +0100 Subject: [PATCH] Addd ContactViewUser unittest --- tests/test_payment/test_views.py | 5 ++--- tests/test_support/test_views.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 tests/test_support/test_views.py diff --git a/tests/test_payment/test_views.py b/tests/test_payment/test_views.py index c215672..845616c 100644 --- a/tests/test_payment/test_views.py +++ b/tests/test_payment/test_views.py @@ -1,5 +1,5 @@ import pytest -from rest_framework.test import force_authenticate, APIRequestFactory +from rest_framework.test import APIRequestFactory from payment.views import SuccessView, CancelView factory = APIRequestFactory() @@ -12,9 +12,8 @@ def test_success_return_success_view(): assert response.status_code == 200 - @pytest.mark.django_db def test_success_return_cancel_view(): request = factory.get("/payment/cancel") response = CancelView.as_view()(request) - assert response.status_code == 200 \ No newline at end of file + assert response.status_code == 200 diff --git a/tests/test_support/test_views.py b/tests/test_support/test_views.py new file mode 100644 index 0000000..f4cc03a --- /dev/null +++ b/tests/test_support/test_views.py @@ -0,0 +1,26 @@ +import pytest +from tests.fixtures import user, job_offer, job_offer_with_company, user_second, company +from rest_framework.test import force_authenticate, APIRequestFactory +from support.views import ContactViewUser, ReportCreateView +import json +from support.models import Contact, Report + +factory = APIRequestFactory() + + +@pytest.mark.django_db +def test_success_create_contact_object(): + request = factory.post( + '/api/support/', + json.dumps({ + "subject": "test message", + "message": "test message", + "email": "test@example.com", + }), + content_type='application/json' + ) + view = ContactViewUser.as_view({"post": "create"}) + response = view(request) + + assert response.status_code == 201 + assert Contact.objects.count() == 1 \ No newline at end of file