def test_post_with_inactive_api(self):
        # require super user permissions
        user = mixer.blend("auth.User", is_superuser=True)
        url = reverse(self.URL_NAME)
        data = {
            "cisco_api_enabled": "on",
        }
        request = RequestFactory().post(url, data=data)
        request.user = user
        msgs = patch_contrib_messages(request)

        response = views.change_configuration(request)

        assert response.status_code == 302
        assert response.url == "/productdb/config/change/"
        assert msgs.added_new

        data = {"cisco_api_enabled": "on", "cisco_api_client_id": "client_id"}
        request = RequestFactory().post(url, data=data)
        request.user = user
        msgs = patch_contrib_messages(request)

        response = views.change_configuration(request)

        assert response.status_code == 302
        assert response.url == "/productdb/config/change/"
        assert msgs.added_new
    def test_post_with_inactive_api(self):
        # require super user permissions
        user = mixer.blend("auth.User", is_superuser=True)
        url = reverse(self.URL_NAME)
        data = {
            "cisco_api_enabled": "on",
        }
        request = RequestFactory().post(url, data=data)
        request.user = user
        msgs = patch_contrib_messages(request)

        response = views.change_configuration(request)

        assert response.status_code == 302
        assert response.url == "/productdb/config/change/"
        assert msgs.added_new

        data = {
            "cisco_api_enabled": "on",
            "cisco_api_client_id": "client_id"
        }
        request = RequestFactory().post(url, data=data)
        request.user = user
        msgs = patch_contrib_messages(request)

        response = views.change_configuration(request)

        assert response.status_code == 302
        assert response.url == "/productdb/config/change/"
        assert msgs.added_new
    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.change_configuration(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.change_configuration(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.change_configuration(request)
    def test_anonymous_default(self):
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = AnonymousUser()
        response = views.change_configuration(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.change_configuration(request)

        assert response.status_code == 302
        assert response.url.startswith("/productdb/login")
Exemplo n.º 8
0
    def test_post_with_active_api(self):
        # require super user permissions
        user = User.objects.create(username="******", is_superuser=True)
        url = reverse(self.URL_NAME)
        data = {}
        request = RequestFactory().post(url, data=data)
        request.user = user
        patch_contrib_messages(request)

        response = views.change_configuration(request)

        assert response.status_code == 302
        assert response.url == "/productdb/config/change/"

        # test with invalid post value
        data = {
            "cisco_api_enabled": "on",
            "cisco_api_client_id": "client_id",
            "eox_api_blacklist": "("
        }
        request = RequestFactory().post(url, data=data)
        request.user = user
        msgs = patch_contrib_messages(request)

        response = views.change_configuration(request)

        assert response.status_code == 200
        assert msgs.added_new

        data = {
            "cisco_api_client_id": "my changed client ID",
            "cisco_api_client_secret": "my changed client secret",
        }
        request = RequestFactory().post(url, data=data)
        request.user = user
        patch_contrib_messages(request)

        response = views.change_configuration(request)

        assert response.status_code == 302
        assert response.url == "/productdb/config/change/"
    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
        patch_contrib_messages(request)

        response = views.change_configuration(request)

        assert response.status_code == 200

        for content in models.TextBlock.objects.all().values_list("html_content", flat=True):
            assert escape(content) in response.content.decode()
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
        patch_contrib_messages(request)

        response = views.change_configuration(request)

        assert response.status_code == 200

        for content in TextBlock.objects.all().values_list("html_content", flat=True):
            assert escape(content) in response.content.decode()
Exemplo n.º 11
0
    def test_global_options_are_visible(self):
        app_config = AppSettings()
        test_internal_id = "My custom Internal ID"
        app_config.set_internal_product_id_label(test_internal_id)

        # require super user permissions
        user = mixer.blend("auth.User", is_superuser=True)
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = user
        patch_contrib_messages(request)

        response = views.change_configuration(request)

        assert response.status_code == 200
        assert test_internal_id in response.content.decode()
Exemplo n.º 12
0
    def test_global_options_are_visible(self):
        app_config = AppSettings()
        test_internal_id = "My custom Internal ID"
        app_config.set_internal_product_id_label(test_internal_id)

        # require super user permissions
        user = mixer.blend("auth.User", is_superuser=True)
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = user
        patch_contrib_messages(request)

        response = views.change_configuration(request)

        assert response.status_code == 200
        assert test_internal_id in response.content.decode()