Beispiel #1
0
    def test_user_notification_settings_view_context_contains_organisation(self):
        notification_settings_view = UserNotificationSettings()

        notification_settings_view.object = MagicMock(spec=NotificationSettings)
        notification_settings_view.organization = create_fake_organization(id=2)
        context = notification_settings_view.get_context_data()
        self.assertIn("organization", context)
        self.assertTrue(context["organization"])
Beispiel #2
0
    def test_user_notification_settings_view_context_contains_organisation(
            self):
        notification_settings_view = UserNotificationSettings()

        notification_settings_view.object = MagicMock(
            spec=NotificationSettings)
        notification_settings_view.organization = create_fake_organization(
            id=2)
        context = notification_settings_view.get_context_data()
        self.assertIn('organization', context)
        self.assertTrue(context['organization'])
Beispiel #3
0
    def test_notification_settings_view_uses_notification_settings_form(self):
        user = UserFactory.build(id=1)
        organization = create_fake_organization(id=2, slug="test")

        request = RequestFactory().get("/")
        request.user = user

        context = UserNotificationSettings.as_view()(request, org_slug=organization.slug).context_data

        self.assertIsInstance(context["form"], NotificationSettingsForm)
Beispiel #4
0
    def test_notification_settings_view_uses_notification_settings_form(self):
        user = UserFactory.build(id=1)
        organization = create_fake_organization(id=2, slug='test')

        request = RequestFactory().get('/')
        request.user = user

        context = UserNotificationSettings.as_view()(
            request, org_slug=organization.slug).context_data

        self.assertIsInstance(context['form'], NotificationSettingsForm)
Beispiel #5
0
    def test_posting_valid_data_saves_settings(self, settings_obj):
        organization = create_fake_organization(id=2, slug='test')

        request = RequestFactory().post(
            reverse('notification_settings', args=[organization.slug]),
            {'notification_level': unicode(NO_NOTIFICATIONS)})

        user = UserFactory.build(id=1)
        request.user = user

        # This patch depends on the UsertNotificationSettings.model patch
        # It needs to return the object created by that patch, which is passed
        # in as a parameter.
        # The only way I've found to handle the dependency is to do this patch
        # here
        with patch('publicweb.views.UserNotificationSettings.model.objects',
                   get=lambda organization, user: settings_obj):
            UserNotificationSettings.as_view()(request,
                                               org_slug=organization.slug)

        self.assertTrue(settings_obj.save.called)
Beispiel #6
0
    def test_notification_settings_view_requires_login(self):
        request = RequestFactory().get("/")

        user = AnonymousUser()

        organization = create_fake_organization(id=2)

        request.user = user

        response = UserNotificationSettings.as_view()(request, organization=organization.id)

        self.assertIsInstance(response, HttpResponseRedirect)
Beispiel #7
0
    def test_notification_settings_view_requires_login(self):
        request = RequestFactory().get('/')

        user = AnonymousUser()

        organization = create_fake_organization(id=2)

        request.user = user

        response = UserNotificationSettings.as_view()(
            request, organization=organization.id)

        self.assertIsInstance(response, HttpResponseRedirect)
Beispiel #8
0
    def test_cancel_doesnt_save_settings(self, settings_obj):
        user = UserFactory.build(id=1)
        organization = create_fake_organization(id=2, slug="test")

        request = RequestFactory().post(
            reverse("notification_settings", args=[organization.id]),
            {"notification_level": unicode(NO_NOTIFICATIONS), "submit": "Cancel"},
        )

        request.user = user

        # This patch depends on the UsertNotificationSettings.model patch
        # It needs to return the object created by that patch, which is passed
        # in as a parameter.
        # The only way I've found to handle the dependency is to do this patch
        # here
        with patch(
            "publicweb.views.UserNotificationSettings.model.objects", get=lambda organization, user: settings_obj
        ):
            UserNotificationSettings.as_view()(request, org_slug=organization.slug)

        self.assertFalse(settings_obj.save.called)
Beispiel #9
0
    def test_posting_invalid_data_returns_form_with_errors(self, settings_obj):
        user = UserFactory.build(id=1)
        organization = create_fake_organization(id=2, slug="test")

        request = RequestFactory().post(reverse("notification_settings", args=[organization.id]))

        request.user = user

        # This patch depends on the UsertNotificationSettings.model patch
        # It needs to return the object created by that patch, which is passed
        # in as a parameter.
        # The only way I've found to handle the dependency is to do this patch
        # here
        with patch(
            "publicweb.views.UserNotificationSettings.model.objects", get=lambda organization, user: settings_obj
        ):
            response = UserNotificationSettings.as_view()(request, org_slug=organization.slug)

        self.assertIn("form", response.context_data)
        self.assertTrue(response.context_data["form"].errors)
Beispiel #10
0
    def test_posting_invalid_data_returns_form_with_errors(self, settings_obj):
        user = UserFactory.build(id=1)
        organization = create_fake_organization(id=2, slug='test')

        request = RequestFactory().post(
            reverse('notification_settings', args=[organization.id]))

        request.user = user

        # This patch depends on the UsertNotificationSettings.model patch
        # It needs to return the object created by that patch, which is passed
        # in as a parameter.
        # The only way I've found to handle the dependency is to do this patch
        # here
        with patch('publicweb.views.UserNotificationSettings.model.objects',
                   get=lambda organization, user: settings_obj):
            response = UserNotificationSettings.as_view()(
                request, org_slug=organization.slug)

        self.assertIn('form', response.context_data)
        self.assertTrue(response.context_data['form'].errors)
Beispiel #11
0
 def test_notifcation_settings_view_redirects_to_organization_list(self):
     notification_settings_view = UserNotificationSettings()
     self.assertEqual(reverse('organization_list'),
                      notification_settings_view.get_success_url())
Beispiel #12
0
 def test_notifcation_settings_view_redirects_to_organization_list(self):
     notification_settings_view = UserNotificationSettings()
     self.assertEqual(reverse("organization_list"), notification_settings_view.get_success_url())