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.status(request)
예제 #2
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.status(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.status(request)
    def test_with_inactive_workers(self, monkeypatch):
        monkeypatch.setattr(views.WorkerState.objects, "all", lambda: MockWorker())
        cache.delete("CISCO_EOX_API_TEST")  # ensure that cache is not set
        global MOCK_WORKER_STATE
        MOCK_WORKER_STATE = False

        # 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.status(request)

        assert response.status_code == 200
        assert cache.get("CISCO_EOX_API_TEST", None) is True
        expected_content = [
            "Only unregistered backend worker found",
            "successful connected to the Cisco EoX API"
        ]
        for line in expected_content:
            assert line in response.content.decode()

        # cleanup
        cache.delete("CISCO_EOX_API_TEST")
    def test_anonymous_default(self):
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = AnonymousUser()
        response = views.status(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.status(request)

        assert response.status_code == 302
        assert response.url.startswith("/productdb/login")
    def test_access_with_broken_api_by_exception(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.status(request)

        assert response.status_code == 200
        assert cache.get("CISCO_EOX_API_TEST", None) is None

        # cleanup
        cache.delete("CISCO_EOX_API_TEST")
예제 #8
0
    def test_access_with_broken_api(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.status(request)

        assert response.status_code == 200
        assert cache.get("CISCO_EOX_API_TEST", None) is False

        # cleanup
        cache.delete("CISCO_EOX_API_TEST")
    def test_access_with_broken_api_by_exception(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.status(request)

        assert response.status_code == 200
        assert cache.get("CISCO_EOX_API_TEST", None) is None

        # cleanup
        cache.delete("CISCO_EOX_API_TEST")
예제 #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.status(request)

        assert response.status_code == 200
        expected_content = [
            "No backend worker found, asynchronous and scheduled tasks are not executed.",
            "successful connected to the Cisco EoX API"
        ]
        for line in expected_content:
            assert line in response.content.decode()

        assert cache.get("CISCO_EOX_API_TEST", None) is True

        # cleanup
        cache.delete("CISCO_EOX_API_TEST")
예제 #11
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.status(request)

        assert response.status_code == 200
        expected_content = [
            "All backend worker offline, asynchronous and scheduled tasks are not executed.",
            "successful connected to the Cisco EoX API"
        ]
        for line in expected_content:
            assert line in response.content.decode()

        assert cache.get("CISCO_EOX_API_TEST", None) is True

        # cleanup
        cache.delete("CISCO_EOX_API_TEST")
예제 #12
0
    def test_with_inactive_workers(self, monkeypatch):
        monkeypatch.setattr(celery, "is_worker_active", lambda: False)
        cache.delete("CISCO_EOX_API_TEST")  # ensure that cache is not set

        # 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.status(request)

        assert response.status_code == 200
        assert cache.get("CISCO_EOX_API_TEST", None) is True
        expected_content = [
            "No backend worker found, asynchronous and scheduled tasks are not executed.",
            "successful connected to the Cisco EoX API"
        ]
        for line in expected_content:
            assert line in response.content.decode()

        # cleanup
        cache.delete("CISCO_EOX_API_TEST")
예제 #13
0
    def test_with_active_workers(self, monkeypatch):
        monkeypatch.setattr(celery, "is_worker_active", lambda: True)
        cache.delete("CISCO_EOX_API_TEST")  # ensure that cache is not set

        # 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.status(request)

        assert response.status_code == 200
        assert cache.get("CISCO_EOX_API_TEST", None) is True
        expected_content = [
            "Backend worker found.",
            "successful connected to the Cisco EoX API"
        ]
        print(response.content.decode())
        for line in expected_content:
            assert line in response.content.decode()

        # cleanup
        cache.delete("CISCO_EOX_API_TEST")