1
e11sync/app/signup/tests.py

34 lines
1.3 KiB
Python
Raw Permalink Normal View History

2024-01-11 23:36:15 +02:00
from django.test import TestCase, Client
from django.urls import reverse
2024-01-12 00:05:57 +02:00
from .models import Signup
2024-01-15 09:09:39 +02:00
2024-01-12 00:05:57 +02:00
class SignupViewTest(TestCase):
2024-01-11 23:36:15 +02:00
def setUp(self):
self.client = Client()
def test_index(self):
resp = self.client.get(reverse("index"))
2024-01-12 00:05:57 +02:00
self.assertEqual(resp.status_code, 200)
2024-01-17 09:00:44 +02:00
self.assertContains(resp, "Hosted Syncthing")
2024-01-11 23:36:15 +02:00
2024-03-05 12:06:51 +02:00
def test_signup_ok(self):
2024-01-11 23:36:15 +02:00
resp = self.client.post(reverse("index"), {"email": "foo@example.com"},
2024-01-15 09:09:39 +02:00
follow=True,
HTTP_USER_AGENT="foo-agent",
2024-02-27 18:30:20 +02:00
REMOTE_ADDR="127.0.0.2",
HTTP_REFERRER="example.org/good-place")
2024-01-12 00:11:23 +02:00
self.assertEqual(resp.redirect_chain, [('/?success=subscribed', 302)])
2024-01-11 23:36:15 +02:00
self.assertContains(resp, "You are now subscribed!")
2024-01-12 00:11:23 +02:00
obj = Signup.objects.get()
self.assertEqual(obj.email, "foo@example.com")
self.assertEqual(obj.anonymized_ip, "127.0.0.0")
self.assertEqual(obj.user_agent, "foo-agent")
2024-02-27 18:30:20 +02:00
self.assertEqual(obj.referrer, "example.org/good-place")
2024-03-05 12:06:51 +02:00
def test_signup_badmail(self):
resp = self.client.post(reverse("index"), {"email": "x@x.x"})
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, "Enter a valid email address.")