The BaseDomainClass.get can accept any number of keyword arguments and will add a filter to the query for each kwarg. This will allow the caller to scope the query as needed with kwargs.
103 lines
3.0 KiB
Python
103 lines
3.0 KiB
Python
import pytest
|
|
from uuid import uuid4
|
|
|
|
from atst.domain.applications import Applications
|
|
from atst.domain.exceptions import NotFoundError
|
|
|
|
from tests.factories import (
|
|
ApplicationFactory,
|
|
ApplicationRoleFactory,
|
|
UserFactory,
|
|
PortfolioFactory,
|
|
EnvironmentFactory,
|
|
)
|
|
|
|
|
|
def test_create_application_with_multiple_environments():
|
|
portfolio = PortfolioFactory.create()
|
|
application = Applications.create(
|
|
portfolio, "My Test Application", "Test", ["dev", "prod"]
|
|
)
|
|
|
|
assert application.portfolio == portfolio
|
|
assert application.name == "My Test Application"
|
|
assert application.description == "Test"
|
|
assert sorted(e.name for e in application.environments) == ["dev", "prod"]
|
|
|
|
|
|
def test_portfolio_owner_can_view_environments():
|
|
owner = UserFactory.create()
|
|
portfolio = PortfolioFactory.create(
|
|
owner=owner,
|
|
applications=[{"environments": [{"name": "dev"}, {"name": "prod"}]}],
|
|
)
|
|
application = Applications.get(portfolio.applications[0].id)
|
|
|
|
assert len(application.environments) == 2
|
|
|
|
|
|
def test_can_only_update_name_and_description():
|
|
owner = UserFactory.create()
|
|
portfolio = PortfolioFactory.create(
|
|
owner=owner,
|
|
applications=[
|
|
{
|
|
"name": "Application 1",
|
|
"description": "a application",
|
|
"environments": [{"name": "dev"}],
|
|
}
|
|
],
|
|
)
|
|
application = Applications.get(portfolio.applications[0].id)
|
|
env_name = application.environments[0].name
|
|
Applications.update(
|
|
application,
|
|
{
|
|
"name": "New Name",
|
|
"description": "a new application",
|
|
"environment_name": "prod",
|
|
},
|
|
)
|
|
|
|
assert application.name == "New Name"
|
|
assert application.description == "a new application"
|
|
assert len(application.environments) == 1
|
|
assert application.environments[0].name == env_name
|
|
|
|
|
|
def test_get_excludes_deleted():
|
|
app = ApplicationFactory.create(deleted=True)
|
|
with pytest.raises(NotFoundError):
|
|
Applications.get(app.id)
|
|
|
|
|
|
def test_get_application():
|
|
app = ApplicationFactory.create()
|
|
assert Applications.get(app.id) == app
|
|
assert Applications.get(app.id, portfolio_id=app.portfolio_id) == app
|
|
with pytest.raises(NotFoundError):
|
|
# make the uuid a string like you'd get from a route
|
|
rando_id = str(uuid4())
|
|
Applications.get(app.id, portfolio_id=rando_id)
|
|
|
|
|
|
def test_delete_application(session):
|
|
app = ApplicationFactory.create()
|
|
app_role = ApplicationRoleFactory.create(user=UserFactory.create(), application=app)
|
|
env1 = EnvironmentFactory.create(application=app)
|
|
env2 = EnvironmentFactory.create(application=app)
|
|
assert not app.deleted
|
|
assert not env1.deleted
|
|
assert not env2.deleted
|
|
assert not app_role.deleted
|
|
|
|
Applications.delete(app)
|
|
|
|
assert app.deleted
|
|
assert env1.deleted
|
|
assert env2.deleted
|
|
assert app_role.deleted
|
|
|
|
# changes are flushed
|
|
assert not session.dirty
|