Ejemplo n.º 1
0
    def test_it_loads_redirects(self, patch):
        parse_redirects = patch("h.tweens.parse_redirects")

        tweens.redirect_tween_factory(handler=None, registry=None)

        parse_redirects.assert_called_once_with(
            # Check parse_redirects is called with a file like object
            Any.object.with_attrs({"readlines": Any.callable()}))
Ejemplo n.º 2
0
def test_tween_redirect_loads_redirects(patch):
    open_ = patch('h.tweens.open')
    parse_redirects = patch('h.tweens.parse_redirects')

    tweens.redirect_tween_factory(handler=None, registry=None)

    open_.assert_called_once_with('h/redirects', encoding='utf-8')
    # Parse redirects is called with the value returned by the context manager
    parse_redirects.assert_called_once_with(open_.return_value.__enter__.return_value)
Ejemplo n.º 3
0
def test_tween_redirect_loads_redirects(patch):
    open_ = patch('h.tweens.open')
    parse_redirects = patch('h.tweens.parse_redirects')

    tweens.redirect_tween_factory(handler=None, registry=None)

    open_.assert_called_once_with('h/redirects', encoding='utf-8')
    # Parse redirects is called with the value returned by the context manager
    parse_redirects.assert_called_once_with(open_.return_value.__enter__.return_value)
Ejemplo n.º 4
0
    def test_it_loads_redirects(self, patch):
        open_ = patch("h.tweens.open")
        parse_redirects = patch("h.tweens.parse_redirects")

        tweens.redirect_tween_factory(handler=None, registry=None)

        open_.assert_called_once_with(Any.string.matching("^.*h/redirects$"),
                                      encoding="utf-8")
        # Parse redirects is called with the value returned by the context manager
        parse_redirects.assert_called_once_with(
            open_.return_value.__enter__.return_value)
Ejemplo n.º 5
0
def test_tween_redirect_non_redirected_route(pyramid_request):
    redirects = [('/foo', 'bar')]

    pyramid_request.path = '/quux'

    tween = tweens.redirect_tween_factory(lambda req: req.response,
                                          pyramid_request.registry, redirects)

    response = tween(pyramid_request)

    assert response.status_code == 200
Ejemplo n.º 6
0
def test_tween_redirect_non_redirected_route(pyramid_request):
    redirects = [('/foo', 'bar')]

    pyramid_request.path = '/quux'

    tween = tweens.redirect_tween_factory(
        lambda req: req.response,
        pyramid_request.registry,
        redirects)

    response = tween(pyramid_request)

    assert response.status_code == 200
Ejemplo n.º 7
0
def test_tween_redirect_non_redirected_route(pyramid_request):
    redirects = [
        Redirect(src='/foo', dst='http://bar', internal=False, prefix=False)
    ]

    pyramid_request.path = '/quux'

    tween = tweens.redirect_tween_factory(lambda req: req.response,
                                          pyramid_request.registry, redirects)

    response = tween(pyramid_request)

    assert response.status_code == 200
Ejemplo n.º 8
0
def test_tween_redirect_redirected_route(pyramid_request, pyramid_config):
    redirects = [('/foo', 'bar')]

    pyramid_config.add_route('bar', '/bar')

    pyramid_request.path = '/foo'

    tween = tweens.redirect_tween_factory(lambda req: req.response,
                                          pyramid_request.registry, redirects)

    response = tween(pyramid_request)

    assert response.status_code == 301
    assert response.location == 'http://example.com/bar'
Ejemplo n.º 9
0
    def test_it_does_not_redirect_for_non_redirected_routes(self, pyramid_request):
        redirects = [
            Redirect(src="/foo", dst="http://bar", internal=False, prefix=False)
        ]

        pyramid_request.path = "/quux"

        tween = tweens.redirect_tween_factory(
            lambda req: req.response, pyramid_request.registry, redirects
        )

        response = tween(pyramid_request)

        assert response.status_code == 200
Ejemplo n.º 10
0
    def test_it_redirects_for_redirected_routes(self, pyramid_request, pyramid_config):
        redirects = [
            Redirect(src="/foo", dst="http://bar", internal=False, prefix=False)
        ]

        pyramid_request.path = "/foo"

        tween = tweens.redirect_tween_factory(
            lambda req: req.response, pyramid_request.registry, redirects
        )

        response = tween(pyramid_request)

        assert response.status_code == 301
        assert response.location == "http://bar"
Ejemplo n.º 11
0
def test_tween_redirect_non_redirected_route(pyramid_request):
    redirects = [
        Redirect(src='/foo', dst='http://bar', internal=False, prefix=False)
    ]

    pyramid_request.path = '/quux'

    tween = tweens.redirect_tween_factory(
        lambda req: req.response,
        pyramid_request.registry,
        redirects)

    response = tween(pyramid_request)

    assert response.status_code == 200
Ejemplo n.º 12
0
def test_tween_redirect_redirected_route(pyramid_request, pyramid_config):
    redirects = [('/foo', 'bar')]

    pyramid_config.add_route('bar', '/bar')

    pyramid_request.path = '/foo'

    tween = tweens.redirect_tween_factory(
        lambda req: req.response,
        pyramid_request.registry,
        redirects)

    response = tween(pyramid_request)

    assert response.status_code == 301
    assert response.location == 'http://example.com/bar'
Ejemplo n.º 13
0
    def test_it_redirects_for_redirected_routes(self, pyramid_request, pyramid_config):
        redirects = [
            Redirect(src='/foo', dst='http://bar', internal=False, prefix=False)
        ]

        pyramid_request.path = '/foo'

        tween = tweens.redirect_tween_factory(
            lambda req: req.response,
            pyramid_request.registry,
            redirects)

        response = tween(pyramid_request)

        assert response.status_code == 301
        assert response.location == 'http://bar'
Ejemplo n.º 14
0
    def test_it_does_not_redirect_for_non_redirected_routes(
            self, pyramid_request):
        redirects = [
            Redirect(src="/foo",
                     dst="http://bar",
                     internal=False,
                     prefix=False)
        ]

        pyramid_request.path = "/quux"

        tween = tweens.redirect_tween_factory(lambda req: req.response,
                                              pyramid_request.registry,
                                              redirects)

        response = tween(pyramid_request)

        assert response.status_code == 200
Ejemplo n.º 15
0
 def test_it_loads_successfully(self):
     # Don't mock parse_redirects out to check the file actually parses
     tweens.redirect_tween_factory(handler=None, registry=None)