feat(contacts): store contact submissions
This commit is contained in:
1
apps/contacts/tests/__init__.py
Normal file
1
apps/contacts/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
44
apps/contacts/tests/test_api_views.py
Normal file
44
apps/contacts/tests/test_api_views.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
from apps.contacts.models import ContactSubmission
|
||||
|
||||
|
||||
class ContactSubmissionApiTests(APITestCase):
|
||||
def test_public_user_can_submit_contact_form(self):
|
||||
response = self.client.post(
|
||||
reverse("contacts:contact-submit"),
|
||||
{
|
||||
"first_name": "Amin",
|
||||
"last_name": "Test",
|
||||
"email": "amin@example.com",
|
||||
"mobile": "09938228438",
|
||||
"message": "I need help with Qlockify reports.",
|
||||
},
|
||||
format="json",
|
||||
HTTP_X_FORWARDED_FOR="203.0.113.10",
|
||||
HTTP_USER_AGENT="test-agent",
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
submission = ContactSubmission.objects.get()
|
||||
self.assertEqual(submission.email, "amin@example.com")
|
||||
self.assertEqual(submission.ip_address, "203.0.113.10")
|
||||
self.assertEqual(submission.user_agent, "test-agent")
|
||||
|
||||
def test_rejects_short_message(self):
|
||||
response = self.client.post(
|
||||
reverse("contacts:contact-submit"),
|
||||
{
|
||||
"first_name": "Amin",
|
||||
"last_name": "Test",
|
||||
"email": "amin@example.com",
|
||||
"mobile": "09938228438",
|
||||
"message": "Hi",
|
||||
},
|
||||
format="json",
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertFalse(ContactSubmission.objects.exists())
|
||||
Reference in New Issue
Block a user