Look up major database resources in a before_request
hook.
A `before_request` hook queries the database for portfolios, requests, and task orders based on the route arguments. The resources are added as attributes on `g`. The portfolio context processor and the access decorator now rely on those resources being available on `g`. WIP: find major resources in before_request hook, apply to g WIP: use g.portfolio for portfolio context processor WIP: the access decorator should rely on the resources being available on g
This commit is contained in:
24
tests/utils/test_context_processors.py
Normal file
24
tests/utils/test_context_processors.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from atst.utils.context_processors import get_resources_from_context
|
||||
|
||||
from tests.factories import *
|
||||
|
||||
|
||||
def test_get_resources_from_context():
|
||||
portfolio = PortfolioFactory.create()
|
||||
task_order = TaskOrderFactory.create(portfolio=portfolio)
|
||||
application = ApplicationFactory.create(portfolio=portfolio)
|
||||
environment = EnvironmentFactory.create(application=application)
|
||||
|
||||
assert get_resources_from_context({"portfolio_id": portfolio.id}) == (portfolio,)
|
||||
assert get_resources_from_context({"application_id": application.id}) == (
|
||||
portfolio,
|
||||
application,
|
||||
)
|
||||
assert get_resources_from_context({"environment_id": environment.id}) == (
|
||||
portfolio,
|
||||
application,
|
||||
)
|
||||
assert get_resources_from_context({"task_order_id": task_order.id}) == (
|
||||
portfolio,
|
||||
task_order,
|
||||
)
|
Reference in New Issue
Block a user