project -> application everywhere
This commit is contained in:
58
tests/domain/test_applications.py
Normal file
58
tests/domain/test_applications.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from atst.domain.applications import Applications
|
||||
from tests.factories import RequestFactory, UserFactory, WorkspaceFactory
|
||||
from atst.domain.workspaces import Workspaces
|
||||
|
||||
|
||||
def test_create_application_with_multiple_environments():
|
||||
request = RequestFactory.create()
|
||||
workspace = Workspaces.create_from_request(request)
|
||||
application = Applications.create(
|
||||
workspace.owner, workspace, "My Test Application", "Test", ["dev", "prod"]
|
||||
)
|
||||
|
||||
assert application.workspace == workspace
|
||||
assert application.name == "My Test Application"
|
||||
assert application.description == "Test"
|
||||
assert sorted(e.name for e in application.environments) == ["dev", "prod"]
|
||||
|
||||
|
||||
def test_workspace_owner_can_view_environments():
|
||||
owner = UserFactory.create()
|
||||
workspace = WorkspaceFactory.create(
|
||||
owner=owner,
|
||||
applications=[{"environments": [{"name": "dev"}, {"name": "prod"}]}],
|
||||
)
|
||||
application = Applications.get(owner, workspace, workspace.applications[0].id)
|
||||
|
||||
assert len(application.environments) == 2
|
||||
|
||||
|
||||
def test_can_only_update_name_and_description():
|
||||
owner = UserFactory.create()
|
||||
workspace = WorkspaceFactory.create(
|
||||
owner=owner,
|
||||
applications=[
|
||||
{
|
||||
"name": "Application 1",
|
||||
"description": "a application",
|
||||
"environments": [{"name": "dev"}],
|
||||
}
|
||||
],
|
||||
)
|
||||
application = Applications.get(owner, workspace, workspace.applications[0].id)
|
||||
env_name = application.environments[0].name
|
||||
Applications.update(
|
||||
owner,
|
||||
workspace,
|
||||
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
|
@@ -8,7 +8,7 @@ from tests.factories import (
|
||||
UserFactory,
|
||||
WorkspaceFactory,
|
||||
WorkspaceRoleFactory,
|
||||
ProjectFactory,
|
||||
ApplicationFactory,
|
||||
)
|
||||
|
||||
|
||||
@@ -81,10 +81,10 @@ def test_other_users_cannot_view_ws_audit_log():
|
||||
|
||||
def test_paginate_ws_audit_log():
|
||||
workspace = WorkspaceFactory.create()
|
||||
project = ProjectFactory.create(workspace=workspace)
|
||||
application = ApplicationFactory.create(workspace=workspace)
|
||||
for _ in range(100):
|
||||
AuditLog.log_system_event(
|
||||
resource=project, action="create", workspace=workspace
|
||||
resource=application, action="create", workspace=workspace
|
||||
)
|
||||
|
||||
events = AuditLog.get_workspace_events(
|
||||
@@ -98,8 +98,8 @@ def test_ws_audit_log_only_includes_current_ws_events():
|
||||
workspace = WorkspaceFactory.create(owner=owner)
|
||||
other_workspace = WorkspaceFactory.create(owner=owner)
|
||||
# Add some audit events
|
||||
project_1 = ProjectFactory.create(workspace=workspace)
|
||||
project_2 = ProjectFactory.create(workspace=other_workspace)
|
||||
application_1 = ApplicationFactory.create(workspace=workspace)
|
||||
application_2 = ApplicationFactory.create(workspace=other_workspace)
|
||||
|
||||
events = AuditLog.get_workspace_events(workspace.owner, workspace)
|
||||
for event in events:
|
||||
|
@@ -2,12 +2,12 @@ from atst.domain.environments import Environments
|
||||
from atst.domain.environment_roles import EnvironmentRoles
|
||||
from atst.domain.workspace_roles import WorkspaceRoles
|
||||
|
||||
from tests.factories import ProjectFactory, UserFactory, WorkspaceFactory
|
||||
from tests.factories import ApplicationFactory, UserFactory, WorkspaceFactory
|
||||
|
||||
|
||||
def test_create_environments():
|
||||
project = ProjectFactory.create()
|
||||
environments = Environments.create_many(project, ["Staging", "Production"])
|
||||
application = ApplicationFactory.create()
|
||||
environments = Environments.create_many(application, ["Staging", "Production"])
|
||||
for env in environments:
|
||||
assert env.cloud_id is not None
|
||||
|
||||
@@ -19,10 +19,12 @@ def test_create_environment_role_creates_cloud_id(session):
|
||||
workspace = WorkspaceFactory.create(
|
||||
owner=owner,
|
||||
members=[{"user": developer, "role_name": "developer"}],
|
||||
projects=[{"name": "project1", "environments": [{"name": "project1 prod"}]}],
|
||||
applications=[
|
||||
{"name": "application1", "environments": [{"name": "application1 prod"}]}
|
||||
],
|
||||
)
|
||||
|
||||
env = workspace.projects[0].environments[0]
|
||||
env = workspace.applications[0].environments[0]
|
||||
new_role = [{"id": env.id, "role": "developer"}]
|
||||
|
||||
workspace_role = workspace.members[0]
|
||||
@@ -41,26 +43,26 @@ def test_update_environment_roles():
|
||||
workspace = WorkspaceFactory.create(
|
||||
owner=owner,
|
||||
members=[{"user": developer, "role_name": "developer"}],
|
||||
projects=[
|
||||
applications=[
|
||||
{
|
||||
"name": "project1",
|
||||
"name": "application1",
|
||||
"environments": [
|
||||
{
|
||||
"name": "project1 dev",
|
||||
"name": "application1 dev",
|
||||
"members": [{"user": developer, "role_name": "devlops"}],
|
||||
},
|
||||
{
|
||||
"name": "project1 staging",
|
||||
"name": "application1 staging",
|
||||
"members": [{"user": developer, "role_name": "developer"}],
|
||||
},
|
||||
{"name": "project1 prod"},
|
||||
{"name": "application1 prod"},
|
||||
],
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
dev_env = workspace.projects[0].environments[0]
|
||||
staging_env = workspace.projects[0].environments[1]
|
||||
dev_env = workspace.applications[0].environments[0]
|
||||
staging_env = workspace.applications[0].environments[1]
|
||||
new_ids_and_roles = [
|
||||
{"id": dev_env.id, "role": "billing_admin"},
|
||||
{"id": staging_env.id, "role": "developer"},
|
||||
@@ -83,34 +85,34 @@ def test_remove_environment_role():
|
||||
workspace = WorkspaceFactory.create(
|
||||
owner=owner,
|
||||
members=[{"user": developer, "role_name": "developer"}],
|
||||
projects=[
|
||||
applications=[
|
||||
{
|
||||
"name": "project1",
|
||||
"name": "application1",
|
||||
"environments": [
|
||||
{
|
||||
"name": "project1 dev",
|
||||
"name": "application1 dev",
|
||||
"members": [{"user": developer, "role_name": "devops"}],
|
||||
},
|
||||
{
|
||||
"name": "project1 staging",
|
||||
"name": "application1 staging",
|
||||
"members": [{"user": developer, "role_name": "developer"}],
|
||||
},
|
||||
{
|
||||
"name": "project1 uat",
|
||||
"name": "application1 uat",
|
||||
"members": [
|
||||
{"user": developer, "role_name": "financial_auditor"}
|
||||
],
|
||||
},
|
||||
{"name": "project1 prod"},
|
||||
{"name": "application1 prod"},
|
||||
],
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
project = workspace.projects[0]
|
||||
now_ba = project.environments[0].id
|
||||
now_none = project.environments[1].id
|
||||
still_fa = project.environments[2].id
|
||||
application = workspace.applications[0]
|
||||
now_ba = application.environments[0].id
|
||||
now_none = application.environments[1].id
|
||||
still_fa = application.environments[2].id
|
||||
|
||||
new_environment_roles = [
|
||||
{"id": now_ba, "role": "billing_auditor"},
|
||||
@@ -135,12 +137,12 @@ def test_no_update_to_environment_roles():
|
||||
workspace = WorkspaceFactory.create(
|
||||
owner=owner,
|
||||
members=[{"user": developer, "role_name": "developer"}],
|
||||
projects=[
|
||||
applications=[
|
||||
{
|
||||
"name": "project1",
|
||||
"name": "application1",
|
||||
"environments": [
|
||||
{
|
||||
"name": "project1 dev",
|
||||
"name": "application1 dev",
|
||||
"members": [{"user": developer, "role_name": "devops"}],
|
||||
}
|
||||
],
|
||||
@@ -148,7 +150,7 @@ def test_no_update_to_environment_roles():
|
||||
],
|
||||
)
|
||||
|
||||
dev_env = workspace.projects[0].environments[0]
|
||||
dev_env = workspace.applications[0].environments[0]
|
||||
new_ids_and_roles = [{"id": dev_env.id, "role": "devops"}]
|
||||
|
||||
workspace_role = WorkspaceRoles.get(workspace.id, developer.id)
|
||||
@@ -161,34 +163,34 @@ def test_get_scoped_environments(db):
|
||||
developer = UserFactory.create()
|
||||
workspace = WorkspaceFactory.create(
|
||||
members=[{"user": developer, "role_name": "developer"}],
|
||||
projects=[
|
||||
applications=[
|
||||
{
|
||||
"name": "project1",
|
||||
"name": "application1",
|
||||
"environments": [
|
||||
{
|
||||
"name": "project1 dev",
|
||||
"name": "application1 dev",
|
||||
"members": [{"user": developer, "role_name": "developer"}],
|
||||
},
|
||||
{"name": "project1 staging"},
|
||||
{"name": "project1 prod"},
|
||||
{"name": "application1 staging"},
|
||||
{"name": "application1 prod"},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "project2",
|
||||
"name": "application2",
|
||||
"environments": [
|
||||
{"name": "project2 dev"},
|
||||
{"name": "application2 dev"},
|
||||
{
|
||||
"name": "project2 staging",
|
||||
"name": "application2 staging",
|
||||
"members": [{"user": developer, "role_name": "developer"}],
|
||||
},
|
||||
{"name": "project2 prod"},
|
||||
{"name": "application2 prod"},
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
project1_envs = Environments.for_user(developer, workspace.projects[0])
|
||||
assert [env.name for env in project1_envs] == ["project1 dev"]
|
||||
application1_envs = Environments.for_user(developer, workspace.applications[0])
|
||||
assert [env.name for env in application1_envs] == ["application1 dev"]
|
||||
|
||||
project2_envs = Environments.for_user(developer, workspace.projects[1])
|
||||
assert [env.name for env in project2_envs] == ["project2 staging"]
|
||||
application2_envs = Environments.for_user(developer, workspace.applications[1])
|
||||
assert [env.name for env in application2_envs] == ["application2 staging"]
|
||||
|
@@ -1,57 +0,0 @@
|
||||
from atst.domain.projects import Projects
|
||||
from tests.factories import RequestFactory, UserFactory, WorkspaceFactory
|
||||
from atst.domain.workspaces import Workspaces
|
||||
|
||||
|
||||
def test_create_project_with_multiple_environments():
|
||||
request = RequestFactory.create()
|
||||
workspace = Workspaces.create_from_request(request)
|
||||
project = Projects.create(
|
||||
workspace.owner, workspace, "My Test Project", "Test", ["dev", "prod"]
|
||||
)
|
||||
|
||||
assert project.workspace == workspace
|
||||
assert project.name == "My Test Project"
|
||||
assert project.description == "Test"
|
||||
assert sorted(e.name for e in project.environments) == ["dev", "prod"]
|
||||
|
||||
|
||||
def test_workspace_owner_can_view_environments():
|
||||
owner = UserFactory.create()
|
||||
workspace = WorkspaceFactory.create(
|
||||
owner=owner, projects=[{"environments": [{"name": "dev"}, {"name": "prod"}]}]
|
||||
)
|
||||
project = Projects.get(owner, workspace, workspace.projects[0].id)
|
||||
|
||||
assert len(project.environments) == 2
|
||||
|
||||
|
||||
def test_can_only_update_name_and_description():
|
||||
owner = UserFactory.create()
|
||||
workspace = WorkspaceFactory.create(
|
||||
owner=owner,
|
||||
projects=[
|
||||
{
|
||||
"name": "Project 1",
|
||||
"description": "a project",
|
||||
"environments": [{"name": "dev"}],
|
||||
}
|
||||
],
|
||||
)
|
||||
project = Projects.get(owner, workspace, workspace.projects[0].id)
|
||||
env_name = project.environments[0].name
|
||||
Projects.update(
|
||||
owner,
|
||||
workspace,
|
||||
project,
|
||||
{
|
||||
"name": "New Name",
|
||||
"description": "a new project",
|
||||
"environment_name": "prod",
|
||||
},
|
||||
)
|
||||
|
||||
assert project.name == "New Name"
|
||||
assert project.description == "a new project"
|
||||
assert len(project.environments) == 1
|
||||
assert project.environments[0].name == env_name
|
@@ -25,7 +25,7 @@ def test_monthly_totals():
|
||||
monthly = Reports.monthly_totals(workspace)
|
||||
|
||||
assert not monthly["environments"]
|
||||
assert not monthly["projects"]
|
||||
assert not monthly["applications"]
|
||||
assert not monthly["workspace"]
|
||||
|
||||
|
||||
|
@@ -4,7 +4,7 @@ from uuid import uuid4
|
||||
from atst.domain.exceptions import NotFoundError, UnauthorizedError
|
||||
from atst.domain.workspaces import Workspaces, WorkspaceError
|
||||
from atst.domain.workspace_roles import WorkspaceRoles
|
||||
from atst.domain.projects import Projects
|
||||
from atst.domain.applications import Applications
|
||||
from atst.domain.environments import Environments
|
||||
from atst.models.workspace_role import Status as WorkspaceRoleStatus
|
||||
|
||||
@@ -69,16 +69,16 @@ def test_workspaces_get_ensures_user_is_in_workspace(workspace, workspace_owner)
|
||||
Workspaces.get(outside_user, workspace.id)
|
||||
|
||||
|
||||
def test_get_for_update_projects_allows_owner(workspace, workspace_owner):
|
||||
Workspaces.get_for_update_projects(workspace_owner, workspace.id)
|
||||
def test_get_for_update_applications_allows_owner(workspace, workspace_owner):
|
||||
Workspaces.get_for_update_applications(workspace_owner, workspace.id)
|
||||
|
||||
|
||||
def test_get_for_update_projects_blocks_developer(workspace):
|
||||
def test_get_for_update_applications_blocks_developer(workspace):
|
||||
developer = UserFactory.create()
|
||||
WorkspaceRoles.add(developer, workspace.id, "developer")
|
||||
|
||||
with pytest.raises(UnauthorizedError):
|
||||
Workspaces.get_for_update_projects(developer, workspace.id)
|
||||
Workspaces.get_for_update_applications(developer, workspace.id)
|
||||
|
||||
|
||||
def test_can_create_workspace_role(workspace, workspace_owner):
|
||||
@@ -183,45 +183,45 @@ def test_random_user_cannot_view_workspace_members(workspace):
|
||||
workspace = Workspaces.get_with_members(developer, workspace.id)
|
||||
|
||||
|
||||
def test_scoped_workspace_only_returns_a_users_projects_and_environments(
|
||||
def test_scoped_workspace_only_returns_a_users_applications_and_environments(
|
||||
workspace, workspace_owner
|
||||
):
|
||||
new_project = Projects.create(
|
||||
new_application = Applications.create(
|
||||
workspace_owner,
|
||||
workspace,
|
||||
"My Project",
|
||||
"My project",
|
||||
"My Application",
|
||||
"My application",
|
||||
["dev", "staging", "prod"],
|
||||
)
|
||||
Projects.create(
|
||||
Applications.create(
|
||||
workspace_owner,
|
||||
workspace,
|
||||
"My Project 2",
|
||||
"My project 2",
|
||||
"My Application 2",
|
||||
"My application 2",
|
||||
["dev", "staging", "prod"],
|
||||
)
|
||||
developer = UserFactory.from_atat_role("developer")
|
||||
dev_environment = Environments.add_member(
|
||||
new_project.environments[0], developer, "developer"
|
||||
new_application.environments[0], developer, "developer"
|
||||
)
|
||||
|
||||
scoped_workspace = Workspaces.get(developer, workspace.id)
|
||||
|
||||
# Should only return the project and environment in which the user has an
|
||||
# Should only return the application and environment in which the user has an
|
||||
# environment role.
|
||||
assert scoped_workspace.projects == [new_project]
|
||||
assert scoped_workspace.projects[0].environments == [dev_environment]
|
||||
assert scoped_workspace.applications == [new_application]
|
||||
assert scoped_workspace.applications[0].environments == [dev_environment]
|
||||
|
||||
|
||||
def test_scoped_workspace_returns_all_projects_for_workspace_admin(
|
||||
def test_scoped_workspace_returns_all_applications_for_workspace_admin(
|
||||
workspace, workspace_owner
|
||||
):
|
||||
for _ in range(5):
|
||||
Projects.create(
|
||||
Applications.create(
|
||||
workspace_owner,
|
||||
workspace,
|
||||
"My Project",
|
||||
"My project",
|
||||
"My Application",
|
||||
"My application",
|
||||
["dev", "staging", "prod"],
|
||||
)
|
||||
|
||||
@@ -231,26 +231,26 @@ def test_scoped_workspace_returns_all_projects_for_workspace_admin(
|
||||
)
|
||||
scoped_workspace = Workspaces.get(admin, workspace.id)
|
||||
|
||||
assert len(scoped_workspace.projects) == 5
|
||||
assert len(scoped_workspace.projects[0].environments) == 3
|
||||
assert len(scoped_workspace.applications) == 5
|
||||
assert len(scoped_workspace.applications[0].environments) == 3
|
||||
|
||||
|
||||
def test_scoped_workspace_returns_all_projects_for_workspace_owner(
|
||||
def test_scoped_workspace_returns_all_applications_for_workspace_owner(
|
||||
workspace, workspace_owner
|
||||
):
|
||||
for _ in range(5):
|
||||
Projects.create(
|
||||
Applications.create(
|
||||
workspace_owner,
|
||||
workspace,
|
||||
"My Project",
|
||||
"My project",
|
||||
"My Application",
|
||||
"My application",
|
||||
["dev", "staging", "prod"],
|
||||
)
|
||||
|
||||
scoped_workspace = Workspaces.get(workspace_owner, workspace.id)
|
||||
|
||||
assert len(scoped_workspace.projects) == 5
|
||||
assert len(scoped_workspace.projects[0].environments) == 3
|
||||
assert len(scoped_workspace.applications) == 5
|
||||
assert len(scoped_workspace.applications[0].environments) == 3
|
||||
|
||||
|
||||
def test_for_user_returns_active_workspaces_for_user(workspace, workspace_owner):
|
||||
|
Reference in New Issue
Block a user