Filter out deleted envs in dispatch_create_environment

This commit is contained in:
richard-dds 2019-09-19 14:24:39 -04:00
parent d6742e5169
commit 6c7667b7fc
2 changed files with 13 additions and 3 deletions

View File

@ -104,6 +104,7 @@ class Environments(object):
.join(CLIN)
.filter(CLIN.start_date <= now)
.filter(CLIN.end_date > now)
.filter(Environment.deleted == False)
.filter(
or_(
Environment.claimed_until == None,

View File

@ -102,8 +102,10 @@ def test_create_environment_baseline(csp, session):
def test_dispatch_create_environment(session, monkeypatch):
# Given that I have a portfolio with an active CLIN and two environments,
# one of which is deleted
portfolio = PortfolioFactory.create(
applications=[{"environments": [{}]}],
applications=[{"environments": [{}, {}]}],
task_orders=[
{
"create_clins": [
@ -115,13 +117,20 @@ def test_dispatch_create_environment(session, monkeypatch):
}
],
)
[e1, e2] = portfolio.applications[0].environments
e2.deleted = True
session.add(e2)
session.commit()
mock = Mock()
monkeypatch.setattr("atst.jobs.create_environment", mock)
environment = portfolio.applications[0].environments[0]
# When dispatch_create_environment is called
dispatch_create_environment.run()
mock.delay.assert_called_once_with(environment_id=environment.id)
# It should cause the create_environment task to be called once with the
# non-deleted environment
mock.delay.assert_called_once_with(environment_id=e1.id)
def test_dispatch_create_atat_admin_user(session, monkeypatch):