def test_post(self):
        # require super user permissions
        user = mixer.blend("auth.User", is_superuser=True)
        url = reverse(self.URL_NAME)
        data = {
            "title": "MyTitle",
            "type": "ERR",
            "summary_message": "This is a summary",
            "detailed_message": "This is the detail message"
        }
        request = RequestFactory().post(url, data=data)
        request.user = user

        response = views.add_notification(request)

        assert response.status_code == 302
        assert NotificationMessage.objects.count() == 1
        n = NotificationMessage.objects.filter(title="MyTitle").first()
        assert n.type == NotificationMessage.MESSAGE_ERROR

        # test with missing input
        data = {
            "title": "MyTitle",
            "type": "ERR",
            "detailed_message": "This is the detail message"
        }
        request = RequestFactory().post(url, data=data)
        request.user = user

        response = views.add_notification(request)

        assert response.status_code == 200
    def test_post(self):
        # require super user permissions
        user = mixer.blend("auth.User", is_superuser=True)
        url = reverse(self.URL_NAME)
        data = {
            "title": "MyTitle",
            "type": "ERR",
            "summary_message": "This is a summary",
            "detailed_message": "This is the detail message"
        }
        request = RequestFactory().post(url, data=data)
        request.user = user

        response = views.add_notification(request)

        assert response.status_code == 302
        assert NotificationMessage.objects.count() == 1
        n = NotificationMessage.objects.filter(title="MyTitle").first()
        assert n.type == NotificationMessage.MESSAGE_ERROR

        # test with missing input
        data = {
            "title": "MyTitle",
            "type": "ERR",
            "detailed_message": "This is the detail message"
        }
        request = RequestFactory().post(url, data=data)
        request.user = user

        response = views.add_notification(request)

        assert response.status_code == 200
    def test_authenticated_user(self):
        # require super user permissions
        user = mixer.blend("auth.User", is_superuser=False)
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = user

        with pytest.raises(PermissionDenied):
            views.add_notification(request)
Exemplo n.º 4
0
    def test_authenticated_user(self):
        # require super user permissions
        user = User.objects.create(username="******", is_superuser=False)
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = user

        with pytest.raises(PermissionDenied):
            views.add_notification(request)
    def test_authenticated_user(self):
        # require super user permissions
        user = mixer.blend("auth.User", is_superuser=False)
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = user

        with pytest.raises(PermissionDenied):
            views.add_notification(request)
    def test_anonymous_default(self):
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = AnonymousUser()
        response = views.add_notification(request)

        assert response.status_code == 302
        assert response.url.startswith("/productdb/login")
    def test_anonymous_default(self):
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = AnonymousUser()
        response = views.add_notification(request)

        assert response.status_code == 302
        assert response.url.startswith("/productdb/login")
    def test_superuser_access(self):
        # require super user permissions
        user = mixer.blend("auth.User", is_superuser=True)
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = user

        response = views.add_notification(request)

        assert response.status_code == 200
Exemplo n.º 9
0
    def test_superuser_access(self):
        # require super user permissions
        user = User.objects.create(username="******", is_superuser=True)
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = user

        response = views.add_notification(request)

        assert response.status_code == 200
Exemplo n.º 10
0
    def test_superuser_access(self):
        # require super user permissions
        user = mixer.blend("auth.User", is_superuser=True)
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = user

        response = views.add_notification(request)

        assert response.status_code == 200