domain methods for deleting apps and environments
This commit is contained in:
parent
1c0c5dd9c5
commit
b58aef2c6b
@ -67,3 +67,13 @@ class Applications(object):
|
||||
db.session.commit()
|
||||
|
||||
return application
|
||||
|
||||
@classmethod
|
||||
def delete(cls, application):
|
||||
for env in application.environments:
|
||||
Environments.delete(env)
|
||||
|
||||
application.deleted = True
|
||||
|
||||
db.session.add(application)
|
||||
db.session.commit()
|
||||
|
@ -98,3 +98,13 @@ class Environments(object):
|
||||
@classmethod
|
||||
def revoke_access(cls, environment, target_user):
|
||||
EnvironmentRoles.delete(environment.id, target_user.id)
|
||||
|
||||
@classmethod
|
||||
def delete(cls, environment, commit=False):
|
||||
environment.deleted = True
|
||||
|
||||
db.session.add(environment)
|
||||
if commit:
|
||||
db.session.commit()
|
||||
|
||||
return environment
|
||||
|
@ -3,7 +3,12 @@ import pytest
|
||||
from atst.domain.applications import Applications
|
||||
from atst.domain.exceptions import NotFoundError
|
||||
|
||||
from tests.factories import ApplicationFactory, UserFactory, PortfolioFactory
|
||||
from tests.factories import (
|
||||
ApplicationFactory,
|
||||
UserFactory,
|
||||
PortfolioFactory,
|
||||
EnvironmentFactory,
|
||||
)
|
||||
|
||||
|
||||
def test_create_application_with_multiple_environments():
|
||||
@ -62,3 +67,21 @@ def test_get_excludes_deleted():
|
||||
app = ApplicationFactory.create(deleted=True)
|
||||
with pytest.raises(NotFoundError):
|
||||
Applications.get(app.id)
|
||||
|
||||
|
||||
def test_delete_application(session):
|
||||
app = ApplicationFactory.create()
|
||||
env1 = EnvironmentFactory.create(application=app)
|
||||
env2 = EnvironmentFactory.create(application=app)
|
||||
assert not app.deleted
|
||||
assert not env1.deleted
|
||||
assert not env2.deleted
|
||||
|
||||
Applications.delete(app)
|
||||
|
||||
assert app.deleted
|
||||
assert env1.deleted
|
||||
assert env2.deleted
|
||||
|
||||
# changes are flushed
|
||||
assert not session.dirty
|
||||
|
@ -202,3 +202,17 @@ def test_get_excludes_deleted():
|
||||
)
|
||||
with pytest.raises(NotFoundError):
|
||||
Environments.get(env.id)
|
||||
|
||||
|
||||
def test_delete_environment(session):
|
||||
env = EnvironmentFactory.create(application=ApplicationFactory.create())
|
||||
assert not env.deleted
|
||||
Environments.delete(env)
|
||||
assert env.deleted
|
||||
# did not flush
|
||||
assert env in session.dirty
|
||||
|
||||
Environments.delete(env, commit=True)
|
||||
assert env.deleted
|
||||
# flushed the change
|
||||
assert not session.dirty
|
||||
|
Loading…
x
Reference in New Issue
Block a user