コード例 #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
コード例 #2
0
ファイル: views_test.py プロジェクト: robertknight/h
    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
コード例 #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
コード例 #4
0
ファイル: views_test.py プロジェクト: robertknight/h
    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
コード例 #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
コード例 #6
0
ファイル: views_test.py プロジェクト: robertknight/h
    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
コード例 #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"
コード例 #8
0
ファイル: views_test.py プロジェクト: robertknight/h
    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
コード例 #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
コード例 #10
0
ファイル: views_test.py プロジェクト: robertknight/h
    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"
コード例 #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
コード例 #12
0
ファイル: views_test.py プロジェクト: robertknight/h
    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
コード例 #13
0
ファイル: views_test.py プロジェクト: robertknight/h
    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
コード例 #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
コード例 #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
コード例 #16
0
ファイル: views_test.py プロジェクト: robertknight/h
    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
コード例 #17
0
ファイル: views_test.py プロジェクト: robertknight/h
    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
コード例 #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
コード例 #19
0
ファイル: views_test.py プロジェクト: robertknight/h
    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
コード例 #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
コード例 #21
0
ファイル: views_test.py プロジェクト: robertknight/h
    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
コード例 #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
コード例 #23
0
ファイル: views_test.py プロジェクト: robertknight/h
    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)
コード例 #24
0
ファイル: views_test.py プロジェクト: robertknight/h
    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)
コード例 #25
0
ファイル: views_test.py プロジェクト: robertknight/h
    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)
コード例 #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)
コード例 #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)
コード例 #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)