Query for applications that need to be provisioned.
Adds a method to the Applications domain class that can return a list of UUIDs for applications that are ready to be provisioned. It requires that: - the associated portfolio and state machine have a state of COMPLETED - the application not have been marked deleted - the application not have an existing cloud_id - the application does not have an existing claim on it
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from datetime import datetime, timedelta
|
||||
import pytest
|
||||
from uuid import uuid4
|
||||
|
||||
@@ -196,3 +197,20 @@ def test_update_does_not_duplicate_names_within_portfolio():
|
||||
|
||||
with pytest.raises(AlreadyExistsError):
|
||||
Applications.update(dupe_application, {"name": name})
|
||||
|
||||
|
||||
def test_get_applications_pending_creation():
|
||||
now = datetime.now()
|
||||
later = now + timedelta(minutes=30)
|
||||
|
||||
portfolio1 = PortfolioFactory.create(state="COMPLETED")
|
||||
app_ready = ApplicationFactory.create(portfolio=portfolio1)
|
||||
|
||||
app_claimed = ApplicationFactory.create(portfolio=portfolio1, claimed_until=later)
|
||||
|
||||
portfolio2 = PortfolioFactory.create(state="UNSTARTED")
|
||||
app_not_ready = ApplicationFactory.create(portfolio=portfolio2)
|
||||
|
||||
uuids = Applications.get_applications_pending_creation()
|
||||
|
||||
assert [app_ready.id] == uuids
|
||||
|
@@ -7,6 +7,7 @@ import datetime
|
||||
|
||||
from atst.forms import data
|
||||
from atst.models import *
|
||||
from atst.models.mixins.state_machines import FSMStates
|
||||
|
||||
from atst.domain.invitations import PortfolioInvitations
|
||||
from atst.domain.permission_sets import PermissionSets
|
||||
@@ -121,6 +122,7 @@ class PortfolioFactory(Base):
|
||||
owner = kwargs.pop("owner", UserFactory.create())
|
||||
members = kwargs.pop("members", [])
|
||||
with_task_orders = kwargs.pop("task_orders", [])
|
||||
state = kwargs.pop("state", None)
|
||||
|
||||
portfolio = super()._create(model_class, *args, **kwargs)
|
||||
|
||||
@@ -161,6 +163,12 @@ class PortfolioFactory(Base):
|
||||
permission_sets=perms_set,
|
||||
)
|
||||
|
||||
if state:
|
||||
state = getattr(FSMStates, state)
|
||||
fsm = PortfolioStateMachineFactory.create(state=state, portfolio=portfolio)
|
||||
# setting it in the factory is not working for some reason
|
||||
fsm.state = state
|
||||
|
||||
portfolio.applications = applications
|
||||
portfolio.task_orders = task_orders
|
||||
return portfolio
|
||||
|
Reference in New Issue
Block a user