Beispiel #1
0
    def test_it_adds_a_limit_param_if_none_is_given(self):
        request = mock.MagicMock()
        request.params = {}

        views.stream_atom(request)

        params = request.api_client.get.call_args[1]["params"]
        assert "limit" in params
Beispiel #2
0
    def test_it_adds_a_limit_param_if_none_is_given(self):
        request = mock.MagicMock()
        request.params = {}

        views.stream_atom(request)

        params = request.api_client.get.call_args[1]["params"]
        assert "limit" in params
Beispiel #3
0
    def test_it_falls_back_to_100_if_limit_is_negative(self):
        """If given a negative number for limit it falls back to 100."""
        request = mock.MagicMock()
        request.params = {"limit": -50}

        views.stream_atom(request)

        params = request.api_client.get.call_args[1]["params"]
        assert params["limit"] == 100
Beispiel #4
0
    def test_it_falls_back_to_100_if_limit_is_negative(self):
        """If given a negative number for limit it falls back to 100."""
        request = mock.MagicMock()
        request.params = {"limit": -50}

        views.stream_atom(request)

        params = request.api_client.get.call_args[1]["params"]
        assert params["limit"] == 100
Beispiel #5
0
    def test_it_falls_back_to_100_if_limit_is_invalid(self):
        """If the user gives an invalid limit value it falls back to 100."""
        for limit in ("not a valid integer", None, [1, 2, 3]):
            request = mock.MagicMock()
            request.params = {"limit": limit}

            views.stream_atom(request)

            params = request.api_client.get.call_args[1]["params"]
            assert params["limit"] == 100
Beispiel #6
0
    def test_it_falls_back_to_100_if_limit_is_invalid(self):
        """If the user gives an invalid limit value it falls back to 100."""
        for limit in ("not a valid integer", None, [1, 2, 3]):
            request = mock.MagicMock()
            request.params = {"limit": limit}

            views.stream_atom(request)

            params = request.api_client.get.call_args[1]["params"]
            assert params["limit"] == 100
Beispiel #7
0
    def test_it_forwards_url_params_to_the_api(self):
        """Any URL params are forwarded to the search API."""
        request = mock.MagicMock()
        request.params = {"user": "******", "tags": "JavaScript", "foo": "bar"}

        views.stream_atom(request)

        params = request.api_client.get.call_args[1]["params"]
        assert params["user"] == "seanh"
        assert params["tags"] == "JavaScript"
        assert params["foo"] == "bar"
Beispiel #8
0
    def test_it_ignores_limits_greater_than_500(self):
        """It doesn't let the user specify a ``limit`` > 500.

        It just reduces the limit to 500.

        """
        request = mock.MagicMock()
        request.params = {"limit": 501}

        views.stream_atom(request)

        params = request.api_client.get.call_args[1]["params"]
        assert params["limit"] == 500
Beispiel #9
0
    def test_it_ignores_limits_greater_than_500(self):
        """It doesn't let the user specify a ``limit`` > 500.

        It just reduces the limit to 500.

        """
        request = mock.MagicMock()
        request.params = {"limit": 501}

        views.stream_atom(request)

        params = request.api_client.get.call_args[1]["params"]
        assert params["limit"] == 500
Beispiel #10
0
    def test_it_forwards_url_params_to_the_api(self):
        """Any URL params are forwarded to the search API."""
        request = mock.MagicMock()
        request.params = {
            "user": "******",
            "tags": "JavaScript",
            "foo": "bar"
        }

        views.stream_atom(request)

        params = request.api_client.get.call_args[1]["params"]
        assert params["user"] == "seanh"
        assert params["tags"] == "JavaScript"
        assert params["foo"] == "bar"
Beispiel #11
0
    def test_it_forwards_user_supplied_limits(self):
        """User-supplied ``limit`` params should be forwarded.

        If the user supplies a ``limit`` param < 500 this should be forwarded
        to the search API.

        """
        for limit in (0, 250, 500):
            request = mock.MagicMock()
            request.params = {"limit": limit}

            views.stream_atom(request)

            params = request.api_client.get.call_args[1]["params"]
            assert params["limit"] == limit
Beispiel #12
0
    def test_it_forwards_user_supplied_limits(self):
        """User-supplied ``limit`` params should be forwarded.

        If the user supplies a ``limit`` param < 500 this should be forwarded
        to the search API.

        """
        for limit in (0, 250, 500):
            request = mock.MagicMock()
            request.params = {"limit": limit}

            views.stream_atom(request)

            params = request.api_client.get.call_args[1]["params"]
            assert params["limit"] == limit
Beispiel #13
0
    def test_it_returns_the_annotations_from_the_search_api(self):
        annotations = factories.Annotation.create_batch(10)
        request = mock.MagicMock()
        request.api_client.get.return_value = {"rows": annotations}

        data = views.stream_atom(request)

        assert data["annotations"] == annotations
Beispiel #14
0
    def test_it_returns_the_annotations_from_the_search_api(self):
        annotations = factories.Annotation.create_batch(10)
        request = mock.MagicMock()
        request.api_client.get.return_value = {"rows": annotations}

        data = views.stream_atom(request)

        assert data["annotations"] == annotations
Beispiel #15
0
    def test_it_returns_the_feed_subtitle(self):
        """It returns the 'h.feed.subtitle' from the config as 'subtitle'."""
        subtitle = "A feed of all our annotations"
        request = mock.MagicMock()

        def side_effect(arg):
            return {"h.feed.subtitle": subtitle}.get(arg)

        request.registry.settings.get.side_effect = side_effect

        data = views.stream_atom(request)

        assert data["subtitle"] == subtitle
Beispiel #16
0
    def test_it_returns_the_feed_subtitle(self):
        """It returns the 'h.feed.subtitle' from the config as 'subtitle'."""
        subtitle = "A feed of all our annotations"
        request = mock.MagicMock()

        def side_effect(arg):
            return {"h.feed.subtitle": subtitle}.get(arg)

        request.registry.settings.get.side_effect = side_effect

        data = views.stream_atom(request)

        assert data["subtitle"] == subtitle
Beispiel #17
0
    def test_it_returns_the_feed_title(self):
        """It returns the 'h.feed.title' from the config as 'title'."""
        title = "Hypothesis Atom Feed"
        request = mock.MagicMock()

        def side_effect(arg):
            return {"h.feed.title": title}.get(arg)

        request.registry.settings.get.side_effect = side_effect

        data = views.stream_atom(request)

        assert data["title"] == title
Beispiel #18
0
    def test_it_returns_the_feed_title(self):
        """It returns the 'h.feed.title' from the config as 'title'."""
        title = "Hypothesis Atom Feed"
        request = mock.MagicMock()

        def side_effect(arg):
            return {"h.feed.title": title}.get(arg)

        request.registry.settings.get.side_effect = side_effect

        data = views.stream_atom(request)

        assert data["title"] == title
Beispiel #19
0
    def test_it_returns_the_stream_url(self):
        """It returns the URL of the 'stream' route as 'html_url'.

        This is the URL to the HTML page corresponding to this feed.

        """
        html_url = "https://hypothes.is/stream"
        request = mock.MagicMock()

        def side_effect(arg):
            return {"stream": html_url}.get(arg)

        request.route_url.side_effect = side_effect

        data = views.stream_atom(request)

        assert data["html_url"] == html_url
Beispiel #20
0
    def test_it_returns_the_atom_url(self):
        """It returns the URL of the 'stream_atom' route as 'atom_url'.

        This is the URL to the Atom version of this Atom feed.

        """
        atom_url = "https://hypothes.is/stream.atom"
        request = mock.MagicMock()

        def side_effect(arg):
            return {"stream_atom": atom_url}.get(arg)

        request.route_url.side_effect = side_effect

        data = views.stream_atom(request)

        assert data["atom_url"] == atom_url
Beispiel #21
0
    def test_it_returns_the_atom_url(self):
        """It returns the URL of the 'stream_atom' route as 'atom_url'.

        This is the URL to the Atom version of this Atom feed.

        """
        atom_url = "https://hypothes.is/stream.atom"
        request = mock.MagicMock()

        def side_effect(arg):
            return {"stream_atom": atom_url}.get(arg)

        request.route_url.side_effect = side_effect

        data = views.stream_atom(request)

        assert data["atom_url"] == atom_url
Beispiel #22
0
    def test_it_returns_the_stream_url(self):
        """It returns the URL of the 'stream' route as 'html_url'.

        This is the URL to the HTML page corresponding to this feed.

        """
        html_url = "https://hypothes.is/stream"
        request = mock.MagicMock()

        def side_effect(arg):
            return {"stream": html_url}.get(arg)

        request.route_url.side_effect = side_effect

        data = views.stream_atom(request)

        assert data["html_url"] == html_url
Beispiel #23
0
    def test_it_raises_httpbadgateway_for_apierror(self):
        request = mock.MagicMock()
        request.api_client.get.side_effect = api_client.APIError

        with pytest.raises(pyramid.httpexceptions.HTTPBadGateway):
            views.stream_atom(request)
Beispiel #24
0
    def test_it_raises_httpgatewaytimeout_for_timeout(self):
        request = mock.MagicMock()
        request.api_client.get.side_effect = api_client.Timeout

        with pytest.raises(pyramid.httpexceptions.HTTPGatewayTimeout):
            views.stream_atom(request)
Beispiel #25
0
    def test_it_raises_httpserviceunavailable_for_connectionerror(self):
        request = mock.MagicMock()
        request.api_client.get.side_effect = api_client.ConnectionError

        with pytest.raises(pyramid.httpexceptions.HTTPServiceUnavailable):
            views.stream_atom(request)
Beispiel #26
0
    def test_it_raises_httpserviceunavailable_for_connectionerror(self):
        request = mock.MagicMock()
        request.api_client.get.side_effect = api_client.ConnectionError

        with pytest.raises(pyramid.httpexceptions.HTTPServiceUnavailable):
            views.stream_atom(request)
Beispiel #27
0
    def test_it_raises_httpgatewaytimeout_for_timeout(self):
        request = mock.MagicMock()
        request.api_client.get.side_effect = api_client.Timeout

        with pytest.raises(pyramid.httpexceptions.HTTPGatewayTimeout):
            views.stream_atom(request)
Beispiel #28
0
    def test_it_raises_httpbadgateway_for_apierror(self):
        request = mock.MagicMock()
        request.api_client.get.side_effect = api_client.APIError

        with pytest.raises(pyramid.httpexceptions.HTTPBadGateway):
            views.stream_atom(request)