Create CLINs when creating a TO
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import pytest
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
from atst.domain.task_orders import TaskOrders, TaskOrderError
|
||||
from atst.domain.exceptions import UnauthorizedError
|
||||
@@ -51,3 +53,91 @@ def test_all_sections_complete():
|
||||
assert not TaskOrders.all_sections_complete(task_order)
|
||||
task_order.scope = "str12345"
|
||||
assert TaskOrders.all_sections_complete(task_order)
|
||||
|
||||
|
||||
def test_create_adds_clins():
|
||||
portfolio = PortfolioFactory.create()
|
||||
clins = [
|
||||
{
|
||||
"jedi_clin_type": "JEDI_CLIN_1",
|
||||
"number": "12312",
|
||||
"start_date": date(2020, 1, 1),
|
||||
"end_date": date(2021, 1, 1),
|
||||
"obligated_amount": Decimal("5000"),
|
||||
"loas": ["123123123123", "345345234"],
|
||||
},
|
||||
{
|
||||
"jedi_clin_type": "JEDI_CLIN_1",
|
||||
"number": "12312",
|
||||
"start_date": date(2020, 1, 1),
|
||||
"end_date": date(2021, 1, 1),
|
||||
"obligated_amount": Decimal("5000"),
|
||||
"loas": ["78979087"],
|
||||
},
|
||||
]
|
||||
task_order = TaskOrders.create(
|
||||
creator=portfolio.owner,
|
||||
portfolio_id=portfolio.id,
|
||||
number="0123456789",
|
||||
clins=clins,
|
||||
)
|
||||
assert len(task_order.clins) == 2
|
||||
|
||||
|
||||
def test_update_adds_clins():
|
||||
task_order = TaskOrderFactory.create(number="1231231234")
|
||||
to_number = task_order.number
|
||||
clins = [
|
||||
{
|
||||
"jedi_clin_type": "JEDI_CLIN_1",
|
||||
"number": "12312",
|
||||
"start_date": date(2020, 1, 1),
|
||||
"end_date": date(2021, 1, 1),
|
||||
"obligated_amount": Decimal("5000"),
|
||||
"loas": ["123123123123", "345345234"],
|
||||
},
|
||||
{
|
||||
"jedi_clin_type": "JEDI_CLIN_1",
|
||||
"number": "12312",
|
||||
"start_date": date(2020, 1, 1),
|
||||
"end_date": date(2021, 1, 1),
|
||||
"obligated_amount": Decimal("5000"),
|
||||
"loas": ["78979087"],
|
||||
},
|
||||
]
|
||||
task_order = TaskOrders.create(
|
||||
creator=task_order.creator,
|
||||
portfolio_id=task_order.portfolio_id,
|
||||
number="0000000000",
|
||||
clins=clins,
|
||||
)
|
||||
assert task_order.number != to_number
|
||||
assert len(task_order.clins) == 2
|
||||
|
||||
|
||||
def test_update_does_not_duplicate_clins():
|
||||
task_order = TaskOrderFactory.create(number="3453453456", clins=["123", "456"])
|
||||
clins = [
|
||||
{
|
||||
"jedi_clin_type": "JEDI_CLIN_1",
|
||||
"number": "123",
|
||||
"start_date": date(2020, 1, 1),
|
||||
"end_date": date(2021, 1, 1),
|
||||
"obligated_amount": Decimal("5000"),
|
||||
"loas": ["123123123123", "345345234"],
|
||||
},
|
||||
{
|
||||
"jedi_clin_type": "JEDI_CLIN_1",
|
||||
"number": "111",
|
||||
"start_date": date(2020, 1, 1),
|
||||
"end_date": date(2021, 1, 1),
|
||||
"obligated_amount": Decimal("5000"),
|
||||
"loas": ["78979087"],
|
||||
},
|
||||
]
|
||||
task_order = TaskOrders.update(
|
||||
task_order_id=task_order.id, number="0000000000", clins=clins
|
||||
)
|
||||
assert len(task_order.clins) == 2
|
||||
for clin in task_order.clins:
|
||||
assert clin.number != "456"
|
||||
|
@@ -41,6 +41,10 @@ def random_future_date(year_min=1, year_max=5):
|
||||
return _random_date(year_min, year_max, operator.add)
|
||||
|
||||
|
||||
def random_loa_numbers():
|
||||
return ["".join(random.choices(string.digits, k=43))]
|
||||
|
||||
|
||||
def _random_date(year_min, year_max, operation):
|
||||
if year_min == year_max:
|
||||
inc = year_min
|
||||
@@ -267,6 +271,17 @@ class TaskOrderFactory(Base):
|
||||
|
||||
portfolio = factory.SubFactory(PortfolioFactory)
|
||||
number = factory.LazyFunction(random_task_order_number)
|
||||
creator = factory.SubFactory(UserFactory)
|
||||
|
||||
@classmethod
|
||||
def _create(cls, model_class, *args, **kwargs):
|
||||
with_clins = kwargs.pop("clins", [])
|
||||
task_order = super()._create(model_class, *args, **kwargs)
|
||||
|
||||
for clin in with_clins:
|
||||
CLINFactory.create(task_order=task_order, number=clin)
|
||||
|
||||
return task_order
|
||||
|
||||
|
||||
class CLINFactory(Base):
|
||||
|
@@ -44,19 +44,19 @@ def test_task_orders_update(client, user_session, portfolio):
|
||||
form_data = {
|
||||
"number": "0123456789",
|
||||
"pdf": pdf_upload,
|
||||
"clins-0-jedi_clin_type": "jedi_clin_0001",
|
||||
"clins-0-jedi_clin_type": "JEDI_CLIN_1",
|
||||
"clins-0-clin_number": "12312",
|
||||
"clins-0-start_date": "01/01/2020",
|
||||
"clins-0-end_date": "01/01/2021",
|
||||
"clins-0-obligated_funds": "5000",
|
||||
"clins-0-loas-0-loa": "123123123123",
|
||||
"clins-0-loas-1-loa": "345345234",
|
||||
"clins-1-jedi_clin_type": "jedi_clin_0001",
|
||||
"clins-1-clin_number": "12312",
|
||||
"clins-0-obligated_amount": "5000",
|
||||
"clins-0-loas-0": "123123123123",
|
||||
"clins-0-loas-1": "345345234",
|
||||
"clins-1-jedi_clin_type": "JEDI_CLIN_1",
|
||||
"clins-1-number": "12312",
|
||||
"clins-1-start_date": "01/01/2020",
|
||||
"clins-1-end_date": "01/01/2021",
|
||||
"clins-1-obligated_funds": "5000",
|
||||
"clins-1-loas-0-loa": "78979087",
|
||||
"clins-1-obligated_amount": "5000",
|
||||
"clins-1-loas-0": "78979087",
|
||||
}
|
||||
response = client.post(
|
||||
url_for("task_orders.update", portfolio_id=portfolio.id), data=form_data
|
||||
@@ -82,12 +82,12 @@ def test_task_orders_update_existing_to(client, user_session, task_order):
|
||||
user_session(task_order.creator)
|
||||
form_data = {
|
||||
"number": "0123456789",
|
||||
"clins-0-jedi_clin_type": "jedi_clin_0001",
|
||||
"clins-0-clin_number": "12312",
|
||||
"clins-0-jedi_clin_type": "JEDI_CLIN_1",
|
||||
"clins-0-number": "12312",
|
||||
"clins-0-start_date": "01/01/2020",
|
||||
"clins-0-end_date": "01/01/2021",
|
||||
"clins-0-obligated_funds": "5000",
|
||||
"clins-0-loas-0-loa": "123123123123",
|
||||
"clins-0-obligated_amount": "5000",
|
||||
"clins-0-loas-0": "123123123123",
|
||||
}
|
||||
response = client.post(
|
||||
url_for(
|
||||
|
Reference in New Issue
Block a user