add tests for task_order routes utility classes

This commit is contained in:
dandds 2018-12-19 11:33:58 -05:00
parent 49f036ab27
commit 62a8b0ec40
3 changed files with 64 additions and 8 deletions

View File

@ -13,9 +13,7 @@ class TaskOrders(object):
"app_migration",
"native_apps",
"complexity",
"complexity_other",
"dev_team",
"dev_team_other",
"team_experience",
],
"funding": [

View File

@ -367,10 +367,12 @@ class TaskOrderFactory(Base):
class Meta:
model = TaskOrder
clin_01 = random.randrange(100, 100_000)
clin_03 = random.randrange(100, 100_000)
clin_02 = random.randrange(100, 100_000)
clin_04 = random.randrange(100, 100_000)
workspace = factory.SubFactory(WorkspaceFactory)
clin_01 = factory.LazyFunction(lambda *args: random.randrange(100, 100_000))
clin_03 = factory.LazyFunction(lambda *args: random.randrange(100, 100_000))
clin_02 = factory.LazyFunction(lambda *args: random.randrange(100, 100_000))
clin_04 = factory.LazyFunction(lambda *args: random.randrange(100, 100_000))
defense_component = factory.LazyFunction(random_service_branch)
app_migration = random_choice(data.APP_MIGRATION)
@ -380,8 +382,12 @@ class TaskOrderFactory(Base):
team_experience = random_choice(data.TEAM_EXPERIENCE)
scope = factory.Faker("sentence")
start_date = random_future_date(year_min=1, year_max=1)
end_date = random_future_date(year_min=2, year_max=5)
start_date = factory.LazyFunction(
lambda *args: random_future_date(year_min=1, year_max=1)
)
end_date = factory.LazyFunction(
lambda *args: random_future_date(year_min=2, year_max=5)
)
ko_first_name = factory.Faker("first_name")
ko_last_name = factory.Faker("last_name")

View File

@ -2,6 +2,7 @@ import pytest
from flask import url_for
from atst.domain.task_orders import TaskOrders
from atst.routes.task_orders.new import ShowTaskOrderWorkflow, UpdateTaskOrderWorkflow
from tests.factories import UserFactory, TaskOrderFactory
@ -67,3 +68,54 @@ def test_create_new_task_order(client, user_session):
response.headers["Location"], data=oversight_data, follow_redirects=False
)
assert url_for("task_orders.new", screen=4) in response.headers["Location"]
def test_show_task_order():
workflow = ShowTaskOrderWorkflow()
assert workflow.task_order is None
task_order = TaskOrderFactory.create()
another_workflow = ShowTaskOrderWorkflow(task_order_id=task_order.id)
assert another_workflow.task_order == task_order
def test_show_task_order_form():
workflow = ShowTaskOrderWorkflow()
assert not workflow.form.data["app_migration"]
task_order = TaskOrderFactory.create()
another_workflow = ShowTaskOrderWorkflow(task_order_id=task_order.id)
assert (
another_workflow.form.data["defense_component"] == task_order.defense_component
)
def test_show_task_order_display_screen():
task_order = TaskOrderFactory.create()
workflow = ShowTaskOrderWorkflow(task_order_id=task_order.id)
screens = workflow.display_screens
# every form section is complete
for i in range(2):
assert screens[i]["complete"]
# the review section is not
assert not screens[3].get("complete")
def test_update_task_order_with_no_task_order():
user = UserFactory.create()
to_data = TaskOrderFactory.dictionary()
workflow = UpdateTaskOrderWorkflow(to_data, user)
assert workflow.task_order is None
workflow.update()
assert workflow.task_order
assert workflow.task_order.scope == to_data["scope"]
def test_update_task_order_with_existing_task_order():
user = UserFactory.create()
task_order = TaskOrderFactory.create()
to_data = serialize_dates(TaskOrderFactory.dictionary())
workflow = UpdateTaskOrderWorkflow(
to_data, user, screen=2, task_order_id=task_order.id
)
assert workflow.task_order.start_date != to_data["start_date"]
workflow.update()
assert workflow.task_order.start_date.strftime("%m/%d/%Y") == to_data["start_date"]