Beispiel #1
0
    def test_on_site_respects_SITE_ID_setting(self):
        site_1 = Site.objects.get(id=1)
        site_2 = Site.objects.create()
        site_1_emails = 3
        site_2_emails = site_1_emails + 1

        with TempSiteID(site_1.id):
            site_1_email_count = EmailNotification.objects.on_site().count()
        with TempSiteID(site_2.id):
            site_2_email_count = EmailNotification.objects.on_site().count()

        index = 0
        for i in range(site_1_emails):
            notification = EmailNotification.objects.create(name=index)
            notification.sites.add(site_1)
            index += 1
        for i in range(site_2_emails):
            notification = EmailNotification.objects.create(name=index)
            notification.sites.add(site_2)
            index += 1

        with TempSiteID(site_1.id):
            self.assertEqual(
                EmailNotification.objects.on_site().count(),
                site_1_email_count + site_1_emails,
            )
        with TempSiteID(site_2.id):
            self.assertEqual(
                EmailNotification.objects.on_site().count(),
                site_2_email_count + site_2_emails,
            )
Beispiel #2
0
    def test_multiple_added_sites_are_reflected_by_on_site(self):
        site_2 = Site.objects.create()
        notification = EmailNotification.objects.create()
        notification.sites.add(1)
        notification.sites.add(site_2)

        with TempSiteID(1):
            self.assertIn(notification, EmailNotification.objects.on_site())

        with TempSiteID(site_2.id):
            self.assertIn(notification, EmailNotification.objects.on_site())
    def test_demo_mode(self):
        Site.objects.get_or_create(id=4)

        with TempSiteID(4), patch.object(CustomNotificationApi, 'send_email') as api_logging:
            self.client_post_report_creation()
            self.client_post_reporting_end_step()

        self.assertEqual(api_logging.call_count, 2)
 def test_sets_site_id(self):
     temp_site_id = 3
     Site.objects.create(id=temp_site_id)
     with TempSiteID(temp_site_id):
         response = self.client.post(self.signup_url, self.DEFAULT_POST)
         self.assertIn(response.status_code, self.valid_statuses)
         self.assertEqual(
             User.objects.get(username="******").account.site_id, temp_site_id
         )
    def test_login_login_for_non_default_site(self):
        auth_info = {"username": "******", "password": "******"}
        user = User.objects.create_user(**auth_info)
        Account.objects.create(user=user, site_id=2)
        with TempSiteID(2):
            Site.objects.create(id=2)
            self.client.post(self.login_url, auth_info)

        self.assertTrue(get_user(self.client).is_authenticated)
Beispiel #6
0
    def test_site_only_added_when_no_default_set(self):
        email = EmailNotification.objects.create(
            name="example email", body="example email", subject="example email"
        )
        email.sites.add(1)

        with TempSiteID(2):
            email.save()

        self.assertEqual(email.sites.count(), 1)
    def test_demo_mode(self):
        Site.objects.get_or_create(id=4)

        with TempSiteID(4), patch.object(CustomNotificationApi, '_logging') as api_logging:
            self.client_post_report_creation()
            self.client_post_reporting_end_step()

        api_logging.assert_has_calls([
            call(notification_name='submit_confirmation'),
            call(notification_name='report_delivery'),
        ], any_order=True)
 def setUp(self):
     super().setUp()
     self.user = User.objects.create_user(username="******", password="******")
     Account.objects.create(
         user=self.user, site_id=1, school_email="*****@*****.**"
     )
     self.client.login(username="******", password="******")
     with TempSiteID(1):
         self.client_post_report_creation()
     self.verify_url = reverse(
         "reporting_email_confirmation", kwargs={"uuid": self.report.uuid}
     )
Beispiel #9
0
    def test_demo_mode(self):
        Site.objects.get_or_create(id=4)

        with TempSiteID(4), patch.object(CustomNotificationApi,
                                         "_logging") as api_logging:
            self.client_post_report_creation()
            self.client_post_reporting_end_step()

        api_logging.assert_has_calls(
            [call(DEMO_MODE=True),
             call(subject="[DEMO] report_delivery")],
            any_order=True,
        )
Beispiel #10
0
 def setUp(self):
     super().setUp()
     self.user = User.objects.create_user(
         username='******',
         password='******',
     )
     Account.objects.create(
         user=self.user,
         site_id=1,
         school_email='*****@*****.**',
     )
     self.client.login(
         username='******',
         password='******',
     )
     with TempSiteID(1):
         self.client_post_report_creation()
     self.verify_url = reverse(
         'reporting_email_confirmation',
         kwargs={'uuid': self.report.uuid},
     )
 def test_signup_disabled_doesnt_create_user(self):
     temp_site_id = 2
     Site.objects.create(id=temp_site_id)
     with TempSiteID(temp_site_id):
         response = self.client.post(self.signup_url, self.DEFAULT_POST)
         self.assertFalse(User.objects.filter(username="******"))
 def test_disable_signups_has_special_instructions(self):
     with TempSiteID(2):
         Site.objects.create(id=2)
         response = self.client.get(self.login_url)
     self.assertIsInstance(response.context["form"], AuthenticationForm)
     self.assertContains(response, "You should have gotten an email")