Add defense_component to Portfolio when new task_order is created without an existing portfolio
This commit is contained in:
parent
f8a6d04d64
commit
7ee8858cc7
@ -16,8 +16,10 @@ class PortfolioError(Exception):
|
|||||||
|
|
||||||
class Portfolios(object):
|
class Portfolios(object):
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, user, name):
|
def create(cls, user, name, defense_component):
|
||||||
portfolio = PortfoliosQuery.create(name=name)
|
portfolio = PortfoliosQuery.create(
|
||||||
|
name=name, defense_component=defense_component
|
||||||
|
)
|
||||||
Portfolios._create_portfolio_role(
|
Portfolios._create_portfolio_role(
|
||||||
user, portfolio, "owner", status=PortfolioRoleStatus.ACTIVE
|
user, portfolio, "owner", status=PortfolioRoleStatus.ACTIVE
|
||||||
)
|
)
|
||||||
|
@ -53,7 +53,6 @@ class TaskOrder(Base, mixins.TimestampsMixin):
|
|||||||
dd_254 = relationship("DD254")
|
dd_254 = relationship("DD254")
|
||||||
|
|
||||||
scope = Column(String) # Cloud Project Scope
|
scope = Column(String) # Cloud Project Scope
|
||||||
defense_component = Column(String) # Department of Defense Component
|
|
||||||
app_migration = Column(String) # App Migration
|
app_migration = Column(String) # App Migration
|
||||||
native_apps = Column(String) # Native Apps
|
native_apps = Column(String) # Native Apps
|
||||||
complexity = Column(ARRAY(String)) # Application Complexity
|
complexity = Column(ARRAY(String)) # Application Complexity
|
||||||
@ -172,6 +171,10 @@ class TaskOrder(Base, mixins.TimestampsMixin):
|
|||||||
def portfolio_name(self):
|
def portfolio_name(self):
|
||||||
return self.portfolio.name
|
return self.portfolio.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def defense_component(self):
|
||||||
|
return self.portfolio.defense_component
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_pending(self):
|
def is_pending(self):
|
||||||
return self.status == Status.PENDING
|
return self.status == Status.PENDING
|
||||||
|
@ -149,6 +149,8 @@ class UpdateTaskOrderWorkflow(ShowTaskOrderWorkflow):
|
|||||||
to_data = self.form.data.copy()
|
to_data = self.form.data.copy()
|
||||||
if "portfolio_name" in to_data:
|
if "portfolio_name" in to_data:
|
||||||
to_data.pop("portfolio_name")
|
to_data.pop("portfolio_name")
|
||||||
|
if "defense_component" in to_data:
|
||||||
|
to_data.pop("defense_component")
|
||||||
|
|
||||||
# don't save other text in DB unless "other" is checked
|
# don't save other text in DB unless "other" is checked
|
||||||
if "complexity" in to_data and "other" not in to_data["complexity"]:
|
if "complexity" in to_data and "other" not in to_data["complexity"]:
|
||||||
@ -184,7 +186,11 @@ class UpdateTaskOrderWorkflow(ShowTaskOrderWorkflow):
|
|||||||
if self.portfolio_id:
|
if self.portfolio_id:
|
||||||
pf = Portfolios.get(self.user, self.portfolio_id)
|
pf = Portfolios.get(self.user, self.portfolio_id)
|
||||||
else:
|
else:
|
||||||
pf = Portfolios.create(self.user, self.form.portfolio_name.data)
|
pf = Portfolios.create(
|
||||||
|
self.user,
|
||||||
|
self.form.portfolio_name.data,
|
||||||
|
self.form.defense_component.data,
|
||||||
|
)
|
||||||
self._task_order = TaskOrders.create(portfolio=pf, creator=self.user)
|
self._task_order = TaskOrders.create(portfolio=pf, creator=self.user)
|
||||||
TaskOrders.update(self.user, self.task_order, **self.task_order_form_data)
|
TaskOrders.update(self.user, self.task_order, **self.task_order_form_data)
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{{ ReviewField(("task_orders.new.review.portfolio" | translate), task_order.portfolio_name) }}
|
{{ ReviewField(("task_orders.new.review.portfolio" | translate), task_order.portfolio_name) }}
|
||||||
{{ ReviewField(("task_orders.new.review.dod" | translate), task_order.defense_component, filter="normalizeOrder") }}
|
{{ ReviewField(("task_orders.new.review.dod" | translate), task_order.portfolio.defense_component, filter="normalizeOrder") }}
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{{ ReviewField(("task_orders.new.review.scope" | translate), task_order.scope) }}
|
{{ ReviewField(("task_orders.new.review.scope" | translate), task_order.scope) }}
|
||||||
|
@ -18,12 +18,12 @@ def test_section_completion_status():
|
|||||||
section = dict_keys[0]
|
section = dict_keys[0]
|
||||||
attrs = TaskOrders.SECTIONS[section].copy()
|
attrs = TaskOrders.SECTIONS[section].copy()
|
||||||
attrs.remove("portfolio_name")
|
attrs.remove("portfolio_name")
|
||||||
|
attrs.remove("defense_component")
|
||||||
task_order = TaskOrderFactory.create(**{k: None for k in attrs})
|
task_order = TaskOrderFactory.create(**{k: None for k in attrs})
|
||||||
leftover = attrs.pop()
|
leftover = attrs.pop()
|
||||||
|
|
||||||
for attr in attrs:
|
for attr in attrs:
|
||||||
setattr(task_order, attr, "str12345")
|
setattr(task_order, attr, "str12345")
|
||||||
|
|
||||||
assert TaskOrders.section_completion_status(task_order, section) == "draft"
|
assert TaskOrders.section_completion_status(task_order, section) == "draft"
|
||||||
|
|
||||||
setattr(task_order, leftover, "str12345")
|
setattr(task_order, leftover, "str12345")
|
||||||
|
@ -104,6 +104,7 @@ class PortfolioFactory(Base):
|
|||||||
model = Portfolio
|
model = Portfolio
|
||||||
|
|
||||||
name = factory.Faker("name")
|
name = factory.Faker("name")
|
||||||
|
defense_component = factory.LazyFunction(random_service_branch)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _create(cls, model_class, *args, **kwargs):
|
def _create(cls, model_class, *args, **kwargs):
|
||||||
@ -227,7 +228,6 @@ class TaskOrderFactory(Base):
|
|||||||
clin_02 = 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))
|
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)
|
app_migration = random_choice(data.APP_MIGRATION)
|
||||||
native_apps = random.choice(["yes", "no", "not_sure"])
|
native_apps = random.choice(["yes", "no", "not_sure"])
|
||||||
complexity = [random_choice(data.APPLICATION_COMPLEXITY)]
|
complexity = [random_choice(data.APPLICATION_COMPLEXITY)]
|
||||||
|
@ -51,7 +51,9 @@ def test_create_new_task_order(client, user_session, pdf_upload):
|
|||||||
task_order_data = TaskOrderFactory.dictionary()
|
task_order_data = TaskOrderFactory.dictionary()
|
||||||
app_info_data = slice_data_for_section(task_order_data, "app_info")
|
app_info_data = slice_data_for_section(task_order_data, "app_info")
|
||||||
portfolio_name = "Mos Eisley"
|
portfolio_name = "Mos Eisley"
|
||||||
|
defense_component = "Defense Health Agency"
|
||||||
app_info_data["portfolio_name"] = portfolio_name
|
app_info_data["portfolio_name"] = portfolio_name
|
||||||
|
app_info_data["defense_component"] = defense_component
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
url_for("task_orders.update", screen=1),
|
url_for("task_orders.update", screen=1),
|
||||||
@ -64,6 +66,8 @@ def test_create_new_task_order(client, user_session, pdf_upload):
|
|||||||
created_task_order = TaskOrders.get(creator, created_task_order_id)
|
created_task_order = TaskOrders.get(creator, created_task_order_id)
|
||||||
assert created_task_order.portfolio is not None
|
assert created_task_order.portfolio is not None
|
||||||
assert created_task_order.portfolio.name == portfolio_name
|
assert created_task_order.portfolio.name == portfolio_name
|
||||||
|
assert created_task_order.portfolio is not None
|
||||||
|
assert created_task_order.portfolio.defense_component == defense_component
|
||||||
|
|
||||||
funding_data = slice_data_for_section(task_order_data, "funding")
|
funding_data = slice_data_for_section(task_order_data, "funding")
|
||||||
funding_data = serialize_dates(funding_data)
|
funding_data = serialize_dates(funding_data)
|
||||||
@ -89,6 +93,8 @@ def test_create_new_task_order_for_portfolio(client, user_session):
|
|||||||
app_info_data = slice_data_for_section(task_order_data, "app_info")
|
app_info_data = slice_data_for_section(task_order_data, "app_info")
|
||||||
portfolio_name = "This is ignored for now"
|
portfolio_name = "This is ignored for now"
|
||||||
app_info_data["portfolio_name"] = portfolio_name
|
app_info_data["portfolio_name"] = portfolio_name
|
||||||
|
defense_component = "Defense Health Agency" # this is also ignored
|
||||||
|
app_info_data["defense_component"] = defense_component
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
url_for("task_orders.update", screen=1, portfolio_id=portfolio.id),
|
url_for("task_orders.update", screen=1, portfolio_id=portfolio.id),
|
||||||
@ -203,7 +209,8 @@ def test_show_task_order_form(task_order):
|
|||||||
task_order.creator, task_order_id=task_order.id
|
task_order.creator, task_order_id=task_order.id
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
another_workflow.form.data["defense_component"] == task_order.defense_component
|
another_workflow.form.data["defense_component"]
|
||||||
|
== task_order.portfolio.defense_component
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user