tests for new task order endpoints, remove new workspace routes

This commit is contained in:
dandds
2018-12-18 13:22:54 -05:00
parent 9a12c14636
commit ad03b58dee
7 changed files with 97 additions and 87 deletions

View File

@@ -33,6 +33,23 @@ def random_service_branch():
return random_choice(data.SERVICE_BRANCHES)
def random_dod_id():
return "".join(random.choices(string.digits, k=10))
def random_future_date(year_min=1, year_max=5):
if year_min == year_max:
inc = year_min
else:
inc = random.randrange(year_min, year_max)
return datetime.date(
datetime.date.today().year + inc,
random.randrange(1, 12),
random.randrange(1, 28),
)
class Base(factory.alchemy.SQLAlchemyModelFactory):
@classmethod
def dictionary(cls, **attrs):
@@ -58,7 +75,7 @@ class UserFactory(Base):
first_name = factory.Faker("first_name")
last_name = factory.Faker("last_name")
atat_role = factory.SubFactory(RoleFactory)
dod_id = factory.LazyFunction(lambda: "".join(random.choices(string.digits, k=10)))
dod_id = factory.LazyFunction(random_dod_id)
phone_number = factory.LazyFunction(
lambda: "".join(random.choices(string.digits, k=10))
)
@@ -227,13 +244,7 @@ class LegacyTaskOrderFactory(Base):
number = factory.LazyFunction(
lambda: "".join(random.choices(string.ascii_uppercase + string.digits, k=13))
)
expiration_date = factory.LazyFunction(
lambda: datetime.date(
datetime.date.today().year + random.randrange(1, 5),
random.randrange(1, 12),
random.randrange(1, 28),
)
)
expiration_date = factory.LazyFunction(random_future_date)
clin_0001 = random.randrange(100, 100_000)
clin_0003 = random.randrange(100, 100_000)
clin_1001 = random.randrange(100, 100_000)
@@ -358,10 +369,29 @@ class TaskOrderFactory(Base):
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)
defense_component = random_service_branch()
defense_component = factory.LazyFunction(random_service_branch)
app_migration = random_choice(data.APP_MIGRATION)
native_apps = "no"
native_apps = random.choices(["yes", "no", "not_sure"])
complexity = random_choice(data.PROJECT_COMPLEXITY)
dev_team = random_choice(data.DEV_TEAM)
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)
ko_first_name = factory.Faker("first_name")
ko_last_name = factory.Faker("last_name")
ko_email = factory.Faker("email")
ko_dod_id = factory.LazyFunction(random_dod_id)
cor_first_name = factory.Faker("first_name")
cor_last_name = factory.Faker("last_name")
cor_email = factory.Faker("email")
cor_dod_id = factory.LazyFunction(random_dod_id)
so_first_name = factory.Faker("first_name")
so_last_name = factory.Faker("last_name")
so_email = factory.Faker("email")
so_dod_id = factory.LazyFunction(random_dod_id)

View File

@@ -1,10 +1,9 @@
import pytest
from flask import url_for
from atst.database import db
from atst.models.workspace import Workspace
from atst.domain.task_orders import TaskOrders
from tests.factories import UserFactory, WorkspaceFactory, TaskOrderFactory
from tests.factories import UserFactory, TaskOrderFactory
def test_new_task_order(client, user_session):
@@ -14,18 +13,43 @@ def test_new_task_order(client, user_session):
assert response.status_code == 200
def test_create_new_task_order(client, user_session):
creator = UserFactory.create()
task_order = TaskOrderFactory.create(
creator=creator, workspace=WorkspaceFactory.create()
)
user_session()
response = client.post(
url_for("task_orders.update", task_order_id=task_order.id),
data={**TaskOrderFactory.dictionary(), "clin_01": 12345, "clin_03": 12345},
def post_to_task_order_step(client, data, screen, task_order_id=None):
return client.post(
url_for("task_orders.update", screen=screen, task_order_id=task_order_id),
data=data,
follow_redirects=False,
)
assert response.status_code == 200
assert task_order.clin_01 == 12345
def slice_data_for_section(task_order_data, section):
attrs = TaskOrders.SECTIONS[section]
return {k: v for k, v in task_order_data.items() if k in attrs}
# TODO: this test will need to be more complicated when we add validation to
# the forms
def test_create_new_task_order(client, user_session):
creator = UserFactory.create()
user_session(creator)
task_order_data = TaskOrderFactory.dictionary()
app_info_data = slice_data_for_section(task_order_data, "app_info")
response = client.post(
url_for("task_orders.update", screen=1),
data=app_info_data,
follow_redirects=False,
)
assert url_for("task_orders.new", screen=2) in response.headers["Location"]
funding_data = slice_data_for_section(task_order_data, "funding")
response = client.post(
response.headers["Location"], data=funding_data, follow_redirects=False
)
assert url_for("task_orders.new", screen=3) in response.headers["Location"]
oversight_data = slice_data_for_section(task_order_data, "oversight")
response = client.post(
response.headers["Location"], data=oversight_data, follow_redirects=False
)
assert url_for("task_orders.new", screen=4) in response.headers["Location"]

View File

@@ -1,27 +0,0 @@
from flask import url_for
from atst.database import db
from atst.models.workspace import Workspace
def get_workspace_by_name(name):
return db.session.query(Workspace).filter_by(name=name).one()
def test_get_new_workspace(client, user_session):
user_session()
response = client.get(url_for("workspaces.new"))
assert response.status_code == 200
def test_create_new_workspace(client, user_session):
user_session()
ws_name = "mos-eisley"
response = client.post(
url_for("workspaces.create"), data={"name": ws_name}, follow_redirects=False
)
assert response.status_code == 302
workspace = get_workspace_by_name(ws_name)
assert workspace.name == ws_name
task_order = workspace.task_orders[0]
assert str(task_order.id) in response.headers.get("Location")