def test_france_country_is_set_by_default(self): data = {"email": "*****@*****.**", "location_zip": "01337", "type": "LFI"} send_confirmation_email(**data) self.assertEqual(len(mail.outbox), 1) confirmation_url = reverse("subscription_confirm") match = re.search(confirmation_url + r'\?[^" \n)]+', mail.outbox[0].body) self.assertIsNotNone(match) url_with_params = match.group(0) response = self.client.get(url_with_params) self.assertEqual(response.status_code, status.HTTP_302_FOUND) self.assertTrue( response.url.startswith( "https://lafranceinsoumise.fr/bienvenue/", )) # check that the person has been created person = Person.objects.get_by_natural_key("*****@*****.**") # check if france is set by default self.assertEqual("France", person.location_country.name)
def test_can_subscribe_with_nsp(self): data = { "email": "*****@*****.**", "location_zip": "20322", "type": "NSP", } send_confirmation_email(**data) self.assertEqual(len(mail.outbox), 1) confirmation_url = reverse("subscription_confirm") match = re.search(confirmation_url + r'\?[^" \n)]+', mail.outbox[0].body) self.assertIsNotNone(match) url_with_params = match.group(0) response = self.client.get(url_with_params) self.assertEqual(response.status_code, status.HTTP_302_FOUND) # check that the person has been created p = Person.objects.get_by_natural_key("*****@*****.**") self.assertTrue(p.is_2022) self.assertAlmostEqual( datetime.fromisoformat(p.meta["subscriptions"]["NSP"]["date"]), timezone.now(), delta=timedelta(seconds=1), )
def test_can_receive_specific_email_if_already_subscribed(self): p = Person.objects.create_person("*****@*****.**") data = {"email": "*****@*****.**", "location_zip": "75001"} send_confirmation_email(**data) self.assertEqual(len(mail.outbox), 1) self.assertRegex(mail.outbox[0].body, r"vous êtes déjà avec nous !")
def test_can_receive_mail_and_confirm_subscription(self): data = {"email": "*****@*****.**", "location_zip": "75001"} send_confirmation_email(**data) self.assertEqual(len(mail.outbox), 1) confirmation_url = reverse("subscription_confirm") match = re.search(confirmation_url + r'\?[^" \n)]+', mail.outbox[0].body) self.assertIsNotNone(match) url_with_params = match.group(0) response = self.client.get(url_with_params) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertContains(response, "Bienvenue !") # check that the person has been created Person.objects.get_by_natural_key("*****@*****.**")
def test_can_subscribe_with_nsp(self): data = { "email": "*****@*****.**", "location_zip": "20322", "location_country": "VE", "type": "NSP", } send_confirmation_email(**data) self.assertEqual(len(mail.outbox), 1) confirmation_url = reverse("subscription_confirm") match = re.search(confirmation_url + r'\?[^" \n)]+', mail.outbox[0].body) self.assertIsNotNone(match) url_with_params = match.group(0) avant = timezone.now() response = self.client.get( url_with_params + "&android=1") # we add &android=1 cause it should work also in app apres = timezone.now() self.assertEqual(response.status_code, status.HTTP_302_FOUND) # check that the person has been created p = Person.objects.get_by_natural_key("*****@*****.**") p.ensure_role_exists() self.assertTrue(p.is_2022) self.assertEqual(p.location_country, "VE") subscription_time = datetime.fromisoformat( p.meta["subscriptions"]["NSP"]["date"]) self.assertTrue(avant <= subscription_time <= apres)