Move "envs pending creation" query to Environments domain
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import pytest
|
||||
import pendulum
|
||||
|
||||
from atst.domain.environments import Environments
|
||||
from atst.domain.environment_roles import EnvironmentRoles
|
||||
@@ -7,11 +8,12 @@ from atst.models.environment_role import CSPRole
|
||||
|
||||
from tests.factories import (
|
||||
ApplicationFactory,
|
||||
UserFactory,
|
||||
PortfolioFactory,
|
||||
EnvironmentFactory,
|
||||
EnvironmentRoleFactory,
|
||||
ApplicationRoleFactory,
|
||||
TaskOrderFactory,
|
||||
CLINFactory,
|
||||
)
|
||||
|
||||
|
||||
@@ -132,3 +134,42 @@ def test_update_environment():
|
||||
assert environment.name is not "name 2"
|
||||
Environments.update(environment, name="name 2")
|
||||
assert environment.name == "name 2"
|
||||
|
||||
|
||||
class TestGetEnvironmentsPendingCreate:
|
||||
NOW = pendulum.now()
|
||||
YESTERDAY = NOW.subtract(days=1)
|
||||
TOMORROW = NOW.add(days=1)
|
||||
|
||||
def create_portfolio_with_clins(self, start_and_end_dates):
|
||||
return PortfolioFactory.create(
|
||||
applications=[
|
||||
{
|
||||
"name": "Mos Eisley",
|
||||
"description": "Where Han shot first",
|
||||
"environments": [{"name": "thebar"}],
|
||||
}
|
||||
],
|
||||
task_orders=[
|
||||
TaskOrderFactory.create(
|
||||
clins=[
|
||||
CLINFactory.create(start_date=start_date, end_date=end_date)
|
||||
for (start_date, end_date) in start_and_end_dates
|
||||
]
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
def test_with_expired_clins(self, session):
|
||||
self.create_portfolio_with_clins([(self.YESTERDAY, self.YESTERDAY)])
|
||||
assert len(Environments.get_environments_pending_creation(self.NOW)) == 0
|
||||
|
||||
def test_with_active_clins(self, session):
|
||||
portfolio = self.create_portfolio_with_clins([(self.YESTERDAY, self.TOMORROW)])
|
||||
Environments.get_environments_pending_creation(self.NOW) == [
|
||||
portfolio.applications[0].environments[0].id
|
||||
]
|
||||
|
||||
def test_with_future_clins(self, session):
|
||||
self.create_portfolio_with_clins([(self.TOMORROW, self.TOMORROW)])
|
||||
assert len(Environments.get_environments_pending_creation(self.NOW)) == 0
|
||||
|
@@ -5,6 +5,8 @@ from atst.jobs import RecordEnvironmentFailure, RecordEnvironmentRoleFailure
|
||||
from tests.factories import EnvironmentFactory, EnvironmentRoleFactory, UserFactory
|
||||
from uuid import uuid4
|
||||
from unittest.mock import Mock
|
||||
|
||||
from atst.models import Environment
|
||||
from tests.factories import (
|
||||
UserFactory,
|
||||
PortfolioFactory,
|
||||
@@ -59,6 +61,7 @@ def test_environment_role_job_failure(celery_app, celery_worker):
|
||||
now = pendulum.now()
|
||||
yesterday = now.subtract(days=1)
|
||||
tomorrow = now.add(days=1)
|
||||
from atst.domain.environments import Environments
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="function")
|
||||
@@ -109,40 +112,3 @@ def test_create_environment_baseline(csp, session):
|
||||
updated_environment = session.query(Environment).get(environment_id)
|
||||
|
||||
assert updated_environment.baseline_info
|
||||
|
||||
|
||||
def create_portfolio_with_clins(start_and_end_dates):
|
||||
return PortfolioFactory.create(
|
||||
applications=[
|
||||
{
|
||||
"name": "Mos Eisley",
|
||||
"description": "Where Han shot first",
|
||||
"environments": [{"name": "thebar"}],
|
||||
}
|
||||
],
|
||||
task_orders=[
|
||||
TaskOrderFactory.create(
|
||||
clins=[
|
||||
CLINFactory.create(start_date=start_date, end_date=end_date)
|
||||
for (start_date, end_date) in start_and_end_dates
|
||||
]
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def test_dispatch_query_with_expired_clins(session):
|
||||
create_portfolio_with_clins([(yesterday, yesterday)])
|
||||
assert len(environments_to_create(pendulum.now())) == 0
|
||||
|
||||
|
||||
def test_dispatch_query_with_active_clins(session):
|
||||
portfolio = create_portfolio_with_clins([(yesterday, tomorrow)])
|
||||
environments_to_create(pendulum.now()) == [
|
||||
portfolio.applications[0].environments[0].id
|
||||
]
|
||||
|
||||
|
||||
def test_dispatch_query_with_future_clins(session):
|
||||
create_portfolio_with_clins([(tomorrow, tomorrow)])
|
||||
assert len(environments_to_create(pendulum.now())) == 0
|
||||
|
Reference in New Issue
Block a user