Ejemplo n.º 1
0
def app(request):

    app = Hypr()

    for provider, urls in request.cls.providers.items():

        if isinstance(provider, str):
            provider = getattr(
                request.module,
                provider,
                type(provider, (cp_provider_factory(),), {})
            )

        if not isinstance(urls, tuple):
            urls = urls,
        app.router.add_provider(provider, *urls)

    app.propagate()
    return app
Ejemplo n.º 2
0
import pytest
from hypr import Hypr, Provider, Response, checkpoint, abort

from test_tools import cp_provider_factory


BaseProvider = cp_provider_factory()


class Root(BaseProvider):

    def get(self):
        abort(404)


class TestCPPreempt:

    providers = {
        Root: '/<int:value>',
    }


    def test_cp_is_preemptive(self, app):

        with app.test_client() as client:
            vtt = client.get('/1')
            assert vtt.status == 403

Ejemplo n.º 3
0
from hypr import Provider
from test_tools import cp_provider_factory


BaseProvider = cp_provider_factory(scope=('propagate', 'alternate'))


class Root(BaseProvider):

    propagation_rules = {
        'propagate': 'Resource',
        'alternate': ('Resource', '/alt')
    }


class Resource(Provider):

    def get(self):
        return 'ok'

class TestCPMultiScope:

    providers = {
        'Root': '/<int:value>',
        'Resource': '/res'
    }

    def test_direct_accept0(self, app):

        with app.test_client() as client:
            vtt = client.get('/0')
Ejemplo n.º 4
0
"""Test checkpoint TARGET scope."""
from test_tools import cp_provider_factory
from hypr import Provider


BaseProvider = cp_provider_factory(scope=Provider.TARGET)


class Root(Provider):

    propagation_rules = {
        'propagate': 'Inter'
    }


class Inter(BaseProvider):

    propagation_rules = {
        'propagate': 'Resource',
    }


class TestScopeTARGET:

    providers = {
        'Root': '/root',
        'Inter': '/<int:value>',
        'Resource': '/resource'
    }

    def test_is_path(self, app):
Ejemplo n.º 5
0
from hypr import Provider
from test_tools import cp_provider_factory


BaseProvider = cp_provider_factory(scope=Provider.PATH)


class Root(Provider):

    propagation_rules = {"propagate": "Resource"}


class Resource(BaseProvider):

    pass


class TestCPPathScope:

    providers = {Root: "/root", Resource: "/<int:value>"}

    def test_not_path_accept0(self, app):

        with app.test_client() as client:
            vtt = client.get("/0")
            assert vtt.status == 200

    def test_not_path_accept1(self, app):

        with app.test_client() as client:
            vtt = client.get("/1")
Ejemplo n.º 6
0
from hypr import Provider
from test_tools import cp_provider_factory


BaseProvider = cp_provider_factory(scope=Provider.ENTRY)


class Root(Provider):

    propagation_rules = {
        'propagate': 'Resource',
    }


class Resource(BaseProvider):
    
    pass


class TestCPEntryScope:

    providers = {
        Root: '/root', 
        Resource: '/<int:value>',
    }


    def test_entry_accept(self, app):

        with app.test_client() as client:
            vtt = client.get('/0')
Ejemplo n.º 7
0
from hypr import Hypr, Provider, Response, checkpoint, abort
from hypr import Provider
from test_tools import cp_provider_factory


BaseProvider = cp_provider_factory(scope=Provider.TRANSFER)


class Root(BaseProvider):

    propagation_rules = {"propagate": "Resource", "alternate": ("Resource", "/alternate")}


class TestCPEntryScope:

    providers = {"Root": "/<int:value>", "Resource": "/resource"}

    def test_no_transfer_accept(self, app):

        with app.test_client() as client:
            vtt = client.get("/1")
            assert vtt.status == 200

    def test_transfer_reject(self, app):

        with app.test_client() as client:
            vtt = client.get("/1/resource")
            assert vtt.status == 403

    def test_transfer_accept(self, app):