Add new tests and refactor existing tests
This commit is contained in:
parent
4dc5f2aa91
commit
5c7dfc428e
@ -30,6 +30,7 @@ from atst.jobs import (
|
|||||||
from tests.factories import (
|
from tests.factories import (
|
||||||
ApplicationFactory,
|
ApplicationFactory,
|
||||||
ApplicationRoleFactory,
|
ApplicationRoleFactory,
|
||||||
|
CLINFactory,
|
||||||
EnvironmentFactory,
|
EnvironmentFactory,
|
||||||
EnvironmentRoleFactory,
|
EnvironmentRoleFactory,
|
||||||
PortfolioFactory,
|
PortfolioFactory,
|
||||||
@ -494,8 +495,8 @@ class TestSendTaskOrderFiles:
|
|||||||
|
|
||||||
|
|
||||||
class TestCreateBillingInstructions:
|
class TestCreateBillingInstructions:
|
||||||
def test_update_clin_last_sent_at(self, session):
|
@pytest.fixture
|
||||||
# create portfolio with one active clin
|
def unsent_clin(self):
|
||||||
start_date = pendulum.now().subtract(days=1)
|
start_date = pendulum.now().subtract(days=1)
|
||||||
portfolio = PortfolioFactory.create(
|
portfolio = PortfolioFactory.create(
|
||||||
csp_data={
|
csp_data={
|
||||||
@ -505,19 +506,20 @@ class TestCreateBillingInstructions:
|
|||||||
},
|
},
|
||||||
task_orders=[{"create_clins": [{"start_date": start_date}]}],
|
task_orders=[{"create_clins": [{"start_date": start_date}]}],
|
||||||
)
|
)
|
||||||
unsent_clin = portfolio.task_orders[0].clins[0]
|
return portfolio.task_orders[0].clins[0]
|
||||||
|
|
||||||
|
def test_update_clin_last_sent_at(self, session, unsent_clin):
|
||||||
assert not unsent_clin.last_sent_at
|
assert not unsent_clin.last_sent_at
|
||||||
|
|
||||||
# The session needs to be nested to prevent detached SQLAlchemy instance
|
# The session needs to be nested to prevent detached SQLAlchemy instance
|
||||||
session.begin_nested()
|
session.begin_nested()
|
||||||
create_billing_instruction()
|
create_billing_instruction()
|
||||||
session.rollback()
|
|
||||||
|
|
||||||
# check that last_sent_at has been updated
|
# check that last_sent_at has been updated
|
||||||
assert unsent_clin.last_sent_at
|
assert unsent_clin.last_sent_at
|
||||||
|
session.rollback()
|
||||||
|
|
||||||
def test_failure(self, monkeypatch, session):
|
def test_failure(self, monkeypatch, session, unsent_clin):
|
||||||
def _create_billing_instruction(MockCloudProvider, object_name):
|
def _create_billing_instruction(MockCloudProvider, object_name):
|
||||||
raise AzureError("something went wrong")
|
raise AzureError("something went wrong")
|
||||||
|
|
||||||
@ -526,22 +528,41 @@ class TestCreateBillingInstructions:
|
|||||||
_create_billing_instruction,
|
_create_billing_instruction,
|
||||||
)
|
)
|
||||||
|
|
||||||
# create portfolio with one active clin
|
# The session needs to be nested to prevent detached SQLAlchemy instance
|
||||||
start_date = pendulum.now().subtract(days=1)
|
session.begin_nested()
|
||||||
|
create_billing_instruction()
|
||||||
|
|
||||||
|
# check that last_sent_at has not been updated
|
||||||
|
assert not unsent_clin.last_sent_at
|
||||||
|
session.rollback()
|
||||||
|
|
||||||
|
def test_task_order_with_multiple_clins(self, session):
|
||||||
|
start_date = pendulum.now(tz="UTC").subtract(days=1)
|
||||||
portfolio = PortfolioFactory.create(
|
portfolio = PortfolioFactory.create(
|
||||||
csp_data={
|
csp_data={
|
||||||
"tenant_id": str(uuid4()),
|
"tenant_id": str(uuid4()),
|
||||||
"billing_account_name": "fake",
|
"billing_account_name": "fake",
|
||||||
"billing_profile_name": "fake",
|
"billing_profile_name": "fake",
|
||||||
},
|
},
|
||||||
task_orders=[{"create_clins": [{"start_date": start_date}]}],
|
task_orders=[
|
||||||
|
{
|
||||||
|
"create_clins": [
|
||||||
|
{"start_date": start_date, "last_sent_at": start_date}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
)
|
)
|
||||||
unsent_clin = portfolio.task_orders[0].clins[0]
|
task_order = portfolio.task_orders[0]
|
||||||
|
sent_clin = task_order.clins[0]
|
||||||
|
|
||||||
|
# Add new CLIN to the Task Order
|
||||||
|
new_clin = CLINFactory.create(task_order=task_order)
|
||||||
|
assert not new_clin.last_sent_at
|
||||||
|
|
||||||
# The session needs to be nested to prevent detached SQLAlchemy instance
|
|
||||||
session.begin_nested()
|
session.begin_nested()
|
||||||
create_billing_instruction()
|
create_billing_instruction()
|
||||||
session.rollback()
|
|
||||||
|
|
||||||
# check that last_sent_at has not been updated
|
# check that last_sent_at has been update for the new clin only
|
||||||
assert not unsent_clin.last_sent_at
|
assert new_clin.last_sent_at
|
||||||
|
assert sent_clin.last_sent_at != new_clin.last_sent_at
|
||||||
|
session.rollback()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user