Better ergonomics for creating factory portfolios w/ TOs

This commit is contained in:
richard-dds 2019-09-10 14:33:35 -04:00
parent f6cb6f2a31
commit 6b7db2ca46
4 changed files with 17 additions and 8 deletions

View File

@ -163,12 +163,12 @@ class EnvQueryTest:
} }
], ],
task_orders=[ task_orders=[
TaskOrderFactory.create( {
clins=[ "create_clins": [
CLINFactory.create(start_date=start_date, end_date=end_date) {"start_date": start_date, "end_date": end_date}
for (start_date, end_date) in start_and_end_dates for (start_date, end_date) in start_and_end_dates
] ]
) }
], ],
) )

View File

@ -135,7 +135,7 @@ def test_update_adds_clins():
def test_update_does_not_duplicate_clins(): def test_update_does_not_duplicate_clins():
task_order = TaskOrderFactory.create( task_order = TaskOrderFactory.create(
number="3453453456", create_clins=["123", "456"] number="3453453456", create_clins=[{"number": "123"}, {"number": "456"}]
) )
clins = [ clins = [
{ {
@ -165,7 +165,9 @@ def test_update_does_not_duplicate_clins():
def test_delete_task_order_with_clins(session): def test_delete_task_order_with_clins(session):
task_order = TaskOrderFactory.create(create_clins=[1, 2, 3]) task_order = TaskOrderFactory.create(
create_clins=[{"number": 1}, {"number": 2}, {"number": 3}]
)
TaskOrders.delete(task_order.id) TaskOrders.delete(task_order.id)
assert not session.query( assert not session.query(

View File

@ -118,6 +118,7 @@ class PortfolioFactory(Base):
with_applications = kwargs.pop("applications", []) with_applications = kwargs.pop("applications", [])
owner = kwargs.pop("owner", UserFactory.create()) owner = kwargs.pop("owner", UserFactory.create())
members = kwargs.pop("members", []) members = kwargs.pop("members", [])
with_task_orders = kwargs.pop("task_orders", [])
portfolio = super()._create(model_class, *args, **kwargs) portfolio = super()._create(model_class, *args, **kwargs)
@ -126,6 +127,11 @@ class PortfolioFactory(Base):
for p in with_applications for p in with_applications
] ]
task_orders = [
TaskOrderFactory.create(portfolio=portfolio, **to)
for to in with_task_orders
]
PortfolioRoleFactory.create( PortfolioRoleFactory.create(
portfolio=portfolio, portfolio=portfolio,
user=owner, user=owner,
@ -154,6 +160,7 @@ class PortfolioFactory(Base):
) )
portfolio.applications = applications portfolio.applications = applications
portfolio.task_orders = task_orders
return portfolio return portfolio
@ -279,7 +286,7 @@ class TaskOrderFactory(Base):
task_order = super()._create(model_class, *args, **kwargs) task_order = super()._create(model_class, *args, **kwargs)
for clin in create_clins: for clin in create_clins:
CLINFactory.create(task_order=task_order, number=clin) CLINFactory.create(task_order=task_order, **clin)
return task_order return task_order

View File

@ -29,7 +29,7 @@ def completed_task_order():
task_order = TaskOrderFactory.create( task_order = TaskOrderFactory.create(
creator=portfolio.owner, creator=portfolio.owner,
portfolio=portfolio, portfolio=portfolio,
create_clins=["1234567890123456789012345678901234567890123"], create_clins=[{"number": "1234567890123456789012345678901234567890123"}],
) )
return task_order return task_order