Skip to content

Commit

Permalink
More tests for dynamic deps.
Browse files Browse the repository at this point in the history
  • Loading branch information
wRAR committed Jul 2, 2024
1 parent efdbed1 commit f6461cc
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/test_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,56 @@ def callback(dd: DynamicDeps):
expected_kwargs,
)

@inlineCallbacks
def test_dynamic_deps_page(self):
def callback(dd: DynamicDeps):
pass

injector = get_injector_for_testing({})

response = get_response_for_testing(callback, meta={"inject": [PricePO]})
request = response.request

plan = injector.build_plan(response.request)
kwargs = yield from injector.build_callback_dependencies(request, response)
kwargs_types = {key: type(value) for key, value in kwargs.items()}
assert kwargs_types == {
"dd": DynamicDeps,
}
dd_types = {key: type(value) for key, value in kwargs["dd"].items()}
assert dd_types == {
PricePO: PricePO,
}

instances = yield from injector.build_instances(request, response, plan)
assert set(instances) == {Html, PricePO, DynamicDeps}

@inlineCallbacks
def test_dynamic_deps_item(self):
def callback(dd: DynamicDeps):
pass

rules = [ApplyRule(Patterns(include=()), use=TestItemPage, to_return=TestItem)]
registry = RulesRegistry(rules=rules)
injector = get_injector_for_testing({}, registry=registry)

response = get_response_for_testing(callback, meta={"inject": [TestItem]})
request = response.request

plan = injector.build_plan(response.request)
kwargs = yield from injector.build_callback_dependencies(request, response)
kwargs_types = {key: type(value) for key, value in kwargs.items()}
assert kwargs_types == {
"dd": DynamicDeps,
}
dd_types = {key: type(value) for key, value in kwargs["dd"].items()}
assert dd_types == {
TestItem: TestItem,
}

instances = yield from injector.build_instances(request, response, plan)
assert set(instances) == {TestItemPage, TestItem, DynamicDeps}


class Html(Injectable):
url = "http://example.com"
Expand Down

0 comments on commit f6461cc

Please sign in to comment.