tests for new task order endpoints, remove new workspace routes
This commit is contained in:
parent
9a12c14636
commit
ad03b58dee
@ -1,4 +1,11 @@
|
|||||||
from flask import Blueprint, request as http_request, render_template, g, redirect, url_for
|
from flask import (
|
||||||
|
Blueprint,
|
||||||
|
request as http_request,
|
||||||
|
render_template,
|
||||||
|
g,
|
||||||
|
redirect,
|
||||||
|
url_for,
|
||||||
|
)
|
||||||
|
|
||||||
from atst.domain.task_orders import TaskOrders
|
from atst.domain.task_orders import TaskOrders
|
||||||
from atst.domain.workspaces import Workspaces
|
from atst.domain.workspaces import Workspaces
|
||||||
@ -77,7 +84,6 @@ class ShowTaskOrderWorkflow:
|
|||||||
return screen_info
|
return screen_info
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateTaskOrderWorkflow(ShowTaskOrderWorkflow):
|
class UpdateTaskOrderWorkflow(ShowTaskOrderWorkflow):
|
||||||
def __init__(self, form_data, user, screen=1, task_order_id=None):
|
def __init__(self, form_data, user, screen=1, task_order_id=None):
|
||||||
self.form_data = form_data
|
self.form_data = form_data
|
||||||
@ -129,7 +135,13 @@ def update(screen, task_order_id=None):
|
|||||||
|
|
||||||
if workflow.validate():
|
if workflow.validate():
|
||||||
workflow.update()
|
workflow.update()
|
||||||
return redirect(url_for("task_orders.new", screen=screen+1, task_order_id=workflow.task_order.id))
|
return redirect(
|
||||||
|
url_for(
|
||||||
|
"task_orders.new",
|
||||||
|
screen=screen + 1,
|
||||||
|
task_order_id=workflow.task_order.id,
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return render_template(
|
return render_template(
|
||||||
workflow.template,
|
workflow.template,
|
||||||
|
@ -6,7 +6,6 @@ from . import index
|
|||||||
from . import projects
|
from . import projects
|
||||||
from . import members
|
from . import members
|
||||||
from . import invitations
|
from . import invitations
|
||||||
from . import new
|
|
||||||
from atst.domain.exceptions import UnauthorizedError
|
from atst.domain.exceptions import UnauthorizedError
|
||||||
from atst.domain.workspaces import Workspaces
|
from atst.domain.workspaces import Workspaces
|
||||||
from atst.domain.authz import Authorization
|
from atst.domain.authz import Authorization
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
from flask import g, redirect, url_for, render_template, request as http_request
|
|
||||||
|
|
||||||
from . import workspaces_bp
|
|
||||||
from atst.domain.task_orders import TaskOrders
|
|
||||||
from atst.domain.workspaces import Workspaces
|
|
||||||
from atst.forms.workspace import WorkspaceForm
|
|
||||||
|
|
||||||
|
|
||||||
@workspaces_bp.route("/workspaces/new")
|
|
||||||
def new():
|
|
||||||
form = WorkspaceForm()
|
|
||||||
return render_template("workspaces/new.html", form=form)
|
|
||||||
|
|
||||||
|
|
||||||
@workspaces_bp.route("/workspaces/new", methods=["POST"])
|
|
||||||
def create():
|
|
||||||
form = WorkspaceForm(http_request.form)
|
|
||||||
if form.validate():
|
|
||||||
ws = Workspaces.create(g.current_user, form.name.data)
|
|
||||||
task_order = TaskOrders.create(workspace=ws, creator=g.current_user)
|
|
||||||
return redirect(url_for("task_orders.edit", task_order_id=task_order.id))
|
|
||||||
else:
|
|
||||||
return render_template("workspaces/new.html", form=form)
|
|
@ -11,14 +11,9 @@
|
|||||||
]
|
]
|
||||||
) }}
|
) }}
|
||||||
|
|
||||||
{{ SidenavItem("Workspaces",
|
{% if g.current_user.has_workspaces %}
|
||||||
href="/workspaces",
|
{{ SidenavItem("Workspaces", href="/workspaces", icon="cloud", active=g.matchesPath('/workspaces')) }}
|
||||||
icon="cloud",
|
{% endif %}
|
||||||
active=g.matchesPath('/workspaces'),
|
|
||||||
subnav=[
|
|
||||||
{"label":"New Workspace", "href":url_for("workspaces.new"), "icon": "plus", "active": g.matchesPath('/workspaces/new')},
|
|
||||||
]
|
|
||||||
) }}
|
|
||||||
|
|
||||||
{% if g.Authorization.has_atat_permission(g.current_user, g.Permissions.VIEW_AUDIT_LOG) %}
|
{% if g.Authorization.has_atat_permission(g.current_user, g.Permissions.VIEW_AUDIT_LOG) %}
|
||||||
{{ SidenavItem("Activity History", url_for('atst.activity_history'), icon="time", active=g.matchesPath('/activity-history')) }}
|
{{ SidenavItem("Activity History", url_for('atst.activity_history'), icon="time", active=g.matchesPath('/activity-history')) }}
|
||||||
|
@ -33,6 +33,23 @@ def random_service_branch():
|
|||||||
return random_choice(data.SERVICE_BRANCHES)
|
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):
|
class Base(factory.alchemy.SQLAlchemyModelFactory):
|
||||||
@classmethod
|
@classmethod
|
||||||
def dictionary(cls, **attrs):
|
def dictionary(cls, **attrs):
|
||||||
@ -58,7 +75,7 @@ class UserFactory(Base):
|
|||||||
first_name = factory.Faker("first_name")
|
first_name = factory.Faker("first_name")
|
||||||
last_name = factory.Faker("last_name")
|
last_name = factory.Faker("last_name")
|
||||||
atat_role = factory.SubFactory(RoleFactory)
|
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(
|
phone_number = factory.LazyFunction(
|
||||||
lambda: "".join(random.choices(string.digits, k=10))
|
lambda: "".join(random.choices(string.digits, k=10))
|
||||||
)
|
)
|
||||||
@ -227,13 +244,7 @@ class LegacyTaskOrderFactory(Base):
|
|||||||
number = factory.LazyFunction(
|
number = factory.LazyFunction(
|
||||||
lambda: "".join(random.choices(string.ascii_uppercase + string.digits, k=13))
|
lambda: "".join(random.choices(string.ascii_uppercase + string.digits, k=13))
|
||||||
)
|
)
|
||||||
expiration_date = factory.LazyFunction(
|
expiration_date = factory.LazyFunction(random_future_date)
|
||||||
lambda: datetime.date(
|
|
||||||
datetime.date.today().year + random.randrange(1, 5),
|
|
||||||
random.randrange(1, 12),
|
|
||||||
random.randrange(1, 28),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
clin_0001 = random.randrange(100, 100_000)
|
clin_0001 = random.randrange(100, 100_000)
|
||||||
clin_0003 = random.randrange(100, 100_000)
|
clin_0003 = random.randrange(100, 100_000)
|
||||||
clin_1001 = 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_01 = random.randrange(100, 100_000)
|
||||||
clin_03 = 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)
|
app_migration = random_choice(data.APP_MIGRATION)
|
||||||
native_apps = "no"
|
native_apps = random.choices(["yes", "no", "not_sure"])
|
||||||
complexity = random_choice(data.PROJECT_COMPLEXITY)
|
complexity = random_choice(data.PROJECT_COMPLEXITY)
|
||||||
dev_team = random_choice(data.DEV_TEAM)
|
dev_team = random_choice(data.DEV_TEAM)
|
||||||
team_experience = random_choice(data.TEAM_EXPERIENCE)
|
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)
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
|
|
||||||
from atst.database import db
|
from atst.domain.task_orders import TaskOrders
|
||||||
from atst.models.workspace import Workspace
|
|
||||||
|
|
||||||
from tests.factories import UserFactory, WorkspaceFactory, TaskOrderFactory
|
from tests.factories import UserFactory, TaskOrderFactory
|
||||||
|
|
||||||
|
|
||||||
def test_new_task_order(client, user_session):
|
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
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_create_new_task_order(client, user_session):
|
def post_to_task_order_step(client, data, screen, task_order_id=None):
|
||||||
creator = UserFactory.create()
|
return client.post(
|
||||||
task_order = TaskOrderFactory.create(
|
url_for("task_orders.update", screen=screen, task_order_id=task_order_id),
|
||||||
creator=creator, workspace=WorkspaceFactory.create()
|
data=data,
|
||||||
)
|
|
||||||
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},
|
|
||||||
follow_redirects=False,
|
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"]
|
||||||
|
@ -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")
|
|
Loading…
x
Reference in New Issue
Block a user