Refactor requests index route for easier testing
This commit is contained in:
@@ -11,7 +11,6 @@ from atst.models.task_order import TaskOrder
|
||||
from atst.models.user import User
|
||||
from atst.models.role import Role
|
||||
from atst.models.workspace import Workspace
|
||||
from atst.models.request_status_event import RequestStatusEvent
|
||||
from atst.domain.roles import Roles
|
||||
|
||||
|
||||
@@ -33,6 +32,10 @@ class UserFactory(factory.alchemy.SQLAlchemyModelFactory):
|
||||
atat_role = factory.SubFactory(RoleFactory)
|
||||
dod_id = factory.LazyFunction(lambda: "".join(random.choices(string.digits, k=10)))
|
||||
|
||||
@classmethod
|
||||
def from_atat_role(cls, atat_role_name, **kwargs):
|
||||
role = Roles.get(atat_role_name)
|
||||
return cls.create(atat_role=role, **kwargs)
|
||||
|
||||
class RequestStatusEventFactory(factory.alchemy.SQLAlchemyModelFactory):
|
||||
class Meta:
|
||||
|
23
tests/routes/test_requests_index.py
Normal file
23
tests/routes/test_requests_index.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from atst.routes.requests.index import RequestsIndex
|
||||
from tests.factories import RequestFactory, UserFactory
|
||||
from atst.domain.requests import Requests
|
||||
|
||||
|
||||
def test_action_required_mission_owner():
|
||||
creator = UserFactory.create()
|
||||
requests = RequestFactory.create_batch(5, creator=creator)
|
||||
Requests.submit(requests[0])
|
||||
context = RequestsIndex(creator).execute()
|
||||
|
||||
assert context['requests'][0]['action_required'] == False
|
||||
|
||||
|
||||
def test_action_required_ccpo():
|
||||
creator = UserFactory.create()
|
||||
requests = RequestFactory.create_batch(5, creator=creator)
|
||||
Requests.submit(requests[0])
|
||||
|
||||
ccpo = UserFactory.from_atat_role("ccpo")
|
||||
context = RequestsIndex(ccpo).execute()
|
||||
|
||||
assert context['num_action_required'] == 1
|
Reference in New Issue
Block a user