45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
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())
|