Example #1
0
class TestPydanticView(View):
    breadcrumbs_resources: str = injected(FakePydanticAdapter, attr='name')
    callable: FakePydanticCallableAdapter
    injected_resource_title: str = injected(Resource, attr='title')

    viewservice_config: ViewServiceConfig
    name: str = 'One Pydantic View'
Example #2
0
class BreadcrumbsAdapter:
    resources: Dict[str, SampleResource] = injected(Request, attr='resources')
    resourceid: str = injected(Resource, attr='id')

    def __call__(self):
        resources = []
        targetid = self.resourceid
        while targetid is not None:
            resource = self.resources[targetid]
            resources.insert(0, resource)
            targetid = resource.parentid

        return Breadcrumbs(resources=resources)
def test_other_data():
    # Ensure the field can have other stuff in it
    i = injected(BogusResource, attr='title', metadata=dict(a=1), init=False)
    assert BogusResource == i.metadata['injected']['type_']
    assert 'title' == i.metadata['injected']['attr']
    assert 1 is i.metadata['a']
    assert False is i.init
Example #4
0
class ArticleView:
    breadcrumbs: Breadcrumbs
    resource_title: str = injected(Resource, attr='title')
    name: str = 'Article View'

    @property
    def breadcrumb_titles(self):
        return ' >> '.join([r.title for r in self.breadcrumbs.resources])
Example #5
0
class ArticleView:
    resources: Dict[str, SampleResource] = injected(Request, attr='resources')
    resourceid: str = injected(Resource, attr='id')
    resource_title: str = injected(Resource, attr='title')
    name: str = 'Article View'

    @property
    def breadcrumb_titles(self):
        return ' >> '.join([r.title for r in self.breadcrumbs])

    @property
    def breadcrumbs(self) -> List[SampleResource]:
        resources = []
        targetid = self.resourceid
        while targetid is not None:
            resource = self.resources[targetid]
            resources.insert(0, resource)
            targetid = resource.parentid

        return resources
def test_invalid_both_attr_and_key():
    with pytest.raises(InjectedArgumentException) as exc:
        injected(BogusResource, attr='title', key='name')
    msg = 'Cannot supply both attr and key arguments to inject'
    assert msg == str(exc.value)
def test_default():
    i = injected(BogusResource)
    assert BogusResource == i.metadata['injected']['type_']
    assert True is i.metadata['injected']['call']
def test_call():
    i = injected(BogusResource, call=False)
    assert BogusResource == i.metadata['injected']['type_']
    assert False is i.metadata['injected']['call']
def test_key():
    i = injected(BogusResource, key='title')
    assert BogusResource == i.metadata['injected']['type_']
    assert 'title' == i.metadata['injected']['key']
Example #10
0
 class InjectedAthlete:
     shoe_size: int = injected(CallableShoe)
Example #11
0
class ArticleView:
    resource_title: str = injected(Resource, attr='title')
    name: str = 'Article View'
Example #12
0
class TestNocallAdapterView(View):
    nocall: FakeNocallAdapter = injected(FakeNocallMarker, call=False)
    name: str = 'Use a Nocall Adapter View'
Example #13
0
class TestInjectedResourceIdAdapterView(View):
    breadcrumbs_resources: FakeBreadcrumbsResources
    viewservice_config: ViewServiceConfig
    adapter_flag: str = injected(FakeBreadcrumbsResources,
                                 attr='injected_flag')
    name: str = 'Use a ResourceId Injected Adapter'
Example #14
0
class ResourceView:
    resource_title: str = injected(Resource, attr='title')
    name: str = 'Resource View'
Example #15
0
 class InjectedAthlete:
     shoe_size: int = injected(Jersey, attr='size')
def test_attr():
    i = injected(BogusResource, attr='title')
    assert BogusResource == i.metadata['injected']['type_']
    assert 'title' == i.metadata['injected']['attr']
Example #17
0
 class InjectedAthlete:
     shoe_size: int = injected(Shoe, attr='size')