- parent relation will not include applications or environments marked as deleted - domain classes will exclude deleted objects from selections - changed some test factories to use domain_word for resource names, because they were using person names and it bugged me
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
import pytest
|
|
|
|
from atst.domain.applications import Applications
|
|
from atst.domain.exceptions import NotFoundError
|
|
|
|
from tests.factories import ApplicationFactory, UserFactory, PortfolioFactory
|
|
|
|
|
|
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)
|