Пример #1
0
    def test_renders_camo(self, monkeypatch):
        html = "<img src=http://example.com/image.jpg>"
        monkeypatch.setattr(readme_renderer.rst, "render", lambda raw: html)

        gen_camo_url = pretend.call_recorder(
            lambda curl, ckey, url: "https://camo.example.net/image.jpg")
        monkeypatch.setattr(filters, "_camo_url", gen_camo_url)

        ctx = {
            "request":
            pretend.stub(registry=pretend.stub(settings={
                "camo.url": "https://camo.example.net/",
                "camo.key": "fake key",
            }, ), ),
        }

        result = filters.readme(ctx, "raw thing", format="rst")

        assert result == jinja2.Markup(
            "<img src=https://camo.example.net/image.jpg>")
        assert gen_camo_url.calls == [
            pretend.call(
                "https://camo.example.net/",
                "fake key",
                "http://example.com/image.jpg",
            ),
        ]
Пример #2
0
    def test_renders_camo(self, monkeypatch):
        html = "<img src=http://example.com/image.jpg>"
        monkeypatch.setattr(readme_renderer.rst, "render", lambda raw: html)

        gen_camo_url = pretend.call_recorder(
            lambda curl, ckey, url: "https://camo.example.net/image.jpg")
        monkeypatch.setattr(filters, "_camo_url", gen_camo_url)

        ctx = {
            "request":
            pretend.stub(
                registry=pretend.stub(
                    settings={
                        "camo.url": "https://camo.example.net/",
                        "camo.key": "fake key",
                    }, ), ),
        }

        result = filters.readme(ctx, "raw thing", format="rst")

        assert result == jinja2.Markup(
            "<img src=https://camo.example.net/image.jpg>")
        assert gen_camo_url.calls == [
            pretend.call(
                "https://camo.example.net/",
                "fake key",
                "http://example.com/image.jpg",
            ),
        ]
Пример #3
0
    def test_renders_camo_no_src(self, monkeypatch):
        html = "<img>"
        monkeypatch.setattr(readme_renderer.rst, "render", lambda raw: html)

        request = pretend.stub(registry=pretend.stub(settings={
            "camo.url": "https://camo.example.net/",
            "camo.key": "fake key",
        }, ), )
        camo_url = partial(filters._camo_url, request)
        request.camo_url = camo_url

        ctx = {"request": request}

        gen_camo_url = pretend.call_recorder(
            lambda curl, ckey, url: "https://camo.example.net/image.jpg")
        monkeypatch.setattr(filters, "_camo_url", gen_camo_url)

        result = filters.readme(
            ctx,
            "raw thing",
            description_content_type="text/x-rst",
        )

        assert result == jinja2.Markup("<img>")
        assert gen_camo_url.calls == []
Пример #4
0
    def test_can_render(self, monkeypatch):
        monkeypatch.setattr(
            readme_renderer.rst,
            "render",
            lambda raw: "rendered",
        )

        ctx = {
            "request":
            pretend.stub(registry=pretend.stub(settings={
                "camo.url": "https://camo.example.net/",
                "camo.key": "fake key",
            }, ), ),
        }

        result = filters.readme(ctx, "raw thing", format="rst")

        assert result == jinja2.Markup("rendered")
Пример #5
0
    def test_can_render(self, monkeypatch):
        monkeypatch.setattr(
            readme_renderer.rst,
            "render",
            lambda raw: "rendered",
        )

        ctx = {
            "request":
            pretend.stub(
                registry=pretend.stub(
                    settings={
                        "camo.url": "https://camo.example.net/",
                        "camo.key": "fake key",
                    }, ), ),
        }

        result = filters.readme(ctx, "raw thing", format="rst")

        assert result == jinja2.Markup("rendered")
Пример #6
0
    def test_can_render_plaintext(self, monkeypatch):
        renderer = pretend.call_recorder(lambda raw: "rendered")
        monkeypatch.setattr(readme_renderer.txt, "render", renderer)

        ctx = {
            "request":
            pretend.stub(registry=pretend.stub(settings={
                "camo.url": "https://camo.example.net/",
                "camo.key": "fake key",
            }, ), ),
        }

        result = filters.readme(
            ctx,
            "raw thing",
            description_content_type="text/plain",
        )

        assert result == jinja2.Markup("rendered")
        assert renderer.calls == [pretend.call('raw thing')]
Пример #7
0
    def test_can_render_missing_content_type(self, monkeypatch):
        renderer = pretend.call_recorder(lambda raw: "rendered")
        monkeypatch.setattr(readme_renderer.rst, "render", renderer)

        request = pretend.stub(registry=pretend.stub(settings={
            "camo.url": "https://camo.example.net/",
            "camo.key": "fake key",
        }, ), )
        camo_url = partial(filters._camo_url, request)
        request.camo_url = camo_url

        ctx = {"request": request}

        result = filters.readme(
            ctx,
            "raw thing",
            description_content_type=None,
        )

        assert result == jinja2.Markup("rendered")
        assert renderer.calls == [pretend.call('raw thing')]
Пример #8
0
    def test_renders_camo(self, monkeypatch):
        html = "<img src=http://example.com/image.jpg>"
        monkeypatch.setattr(readme_renderer.rst, "render", lambda raw: html)

        request = pretend.stub(registry=pretend.stub(settings={
            "camo.url": "https://camo.example.net/",
            "camo.key": "fake key",
        }, ), )
        camo_url = partial(filters._camo_url, request)
        request.camo_url = camo_url

        ctx = {"request": request}

        result = filters.readme(
            ctx,
            "raw thing",
            description_content_type="text/x-rst",
        )

        assert result == jinja2.Markup(
            '<img src="https://camo.example.net/'
            'b410d235a3d2fc44b50ccab827e531dece213062/'
            '687474703a2f2f6578616d706c652e636f6d2f696d6167652e6a7067">')