project -> application everywhere

This commit is contained in:
dandds
2019-01-10 16:38:00 -05:00
parent 9ad3c45200
commit 3fc323d785
67 changed files with 644 additions and 609 deletions

View 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

View File

@@ -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:

View File

@@ -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"]

View File

@@ -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

View File

@@ -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"]

View File

@@ -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):

View File

@@ -12,7 +12,7 @@ from atst.models.request_revision import RequestRevision
from atst.models.request_review import RequestReview
from atst.models.request_status_event import RequestStatusEvent, RequestStatus
from atst.models.pe_number import PENumber
from atst.models.project import Project
from atst.models.application import Application
from atst.models.legacy_task_order import LegacyTaskOrder, Source, FundingType
from atst.models.task_order import TaskOrder
from atst.models.user import User
@@ -260,14 +260,15 @@ class WorkspaceFactory(Base):
@classmethod
def _create(cls, model_class, *args, **kwargs):
with_projects = kwargs.pop("projects", [])
with_applications = kwargs.pop("applications", [])
owner = kwargs.pop("owner", UserFactory.create())
members = kwargs.pop("members", [])
workspace = super()._create(model_class, *args, **kwargs)
projects = [
ProjectFactory.create(workspace=workspace, **p) for p in with_projects
applications = [
ApplicationFactory.create(workspace=workspace, **p)
for p in with_applications
]
workspace.request.creator = owner
@@ -288,29 +289,30 @@ class WorkspaceFactory(Base):
status=WorkspaceRoleStatus.ACTIVE,
)
workspace.projects = projects
workspace.applications = applications
return workspace
class ProjectFactory(Base):
class ApplicationFactory(Base):
class Meta:
model = Project
model = Application
workspace = factory.SubFactory(WorkspaceFactory)
name = factory.Faker("name")
description = "A test project"
description = "A test application"
@classmethod
def _create(cls, model_class, *args, **kwargs):
with_environments = kwargs.pop("environments", [])
project = super()._create(model_class, *args, **kwargs)
application = super()._create(model_class, *args, **kwargs)
environments = [
EnvironmentFactory.create(project=project, **e) for e in with_environments
EnvironmentFactory.create(application=application, **e)
for e in with_environments
]
project.environments = environments
return project
application.environments = environments
return application
class EnvironmentFactory(Base):

View File

@@ -72,7 +72,7 @@ class TestDetailsOfUseForm:
request_form = self._make_form(data)
assert request_form.validate()
def test_sessions_required_for_large_projects(self):
def test_sessions_required_for_large_applications(self):
data = {**self.form_data, **self.migration_data}
data["estimated_monthly_spend"] = "9999999"
del data["number_user_sessions"]

View File

@@ -1,6 +1,6 @@
from atst.domain.environments import Environments
from atst.domain.workspaces import Workspaces
from atst.domain.projects import Projects
from atst.domain.applications import Applications
from tests.factories import RequestFactory, UserFactory
@@ -9,10 +9,14 @@ def test_add_user_to_environment():
developer = UserFactory.from_atat_role("developer")
workspace = Workspaces.create_from_request(RequestFactory.create(creator=owner))
project = Projects.create(
owner, workspace, "my test project", "It's mine.", ["dev", "staging", "prod"]
application = Applications.create(
owner,
workspace,
"my test application",
"It's mine.",
["dev", "staging", "prod"],
)
dev_environment = project.environments[0]
dev_environment = application.environments[0]
dev_environment = Environments.add_member(dev_environment, developer, "developer")
assert developer in dev_environment.users

View File

@@ -2,7 +2,7 @@ import datetime
from atst.domain.environments import Environments
from atst.domain.workspaces import Workspaces
from atst.domain.projects import Projects
from atst.domain.applications import Applications
from atst.models.workspace_role import Status
from atst.models.role import Role
from atst.models.invitation import Status as InvitationStatus
@@ -15,7 +15,7 @@ from tests.factories import (
WorkspaceRoleFactory,
EnvironmentFactory,
EnvironmentRoleFactory,
ProjectFactory,
ApplicationFactory,
WorkspaceFactory,
)
from atst.domain.workspace_roles import WorkspaceRoles
@@ -90,8 +90,10 @@ def test_has_no_env_role_history(session):
owner = UserFactory.create()
user = UserFactory.create()
workspace = Workspaces.create_from_request(RequestFactory.create(creator=owner))
project = ProjectFactory.create(workspace=workspace)
environment = EnvironmentFactory.create(project=project, name="new environment!")
application = ApplicationFactory.create(workspace=workspace)
environment = EnvironmentFactory.create(
application=application, name="new environment!"
)
env_role = EnvironmentRoleFactory.create(
user=user, environment=environment, role="developer"
@@ -110,8 +112,10 @@ def test_has_env_role_history(session):
user = UserFactory.create()
workspace = Workspaces.create_from_request(RequestFactory.create(creator=owner))
workspace_role = WorkspaceRoleFactory.create(workspace=workspace, user=user)
project = ProjectFactory.create(workspace=workspace)
environment = EnvironmentFactory.create(project=project, name="new environment!")
application = ApplicationFactory.create(workspace=workspace)
environment = EnvironmentFactory.create(
application=application, name="new environment!"
)
env_role = EnvironmentRoleFactory.create(
user=user, environment=environment, role="developer"
@@ -168,10 +172,16 @@ def test_has_environment_roles():
workspace = Workspaces.create_from_request(RequestFactory.create(creator=owner))
workspace_role = Workspaces.create_member(owner, workspace, developer_data)
project = Projects.create(
owner, workspace, "my test project", "It's mine.", ["dev", "staging", "prod"]
application = Applications.create(
owner,
workspace,
"my test application",
"It's mine.",
["dev", "staging", "prod"],
)
Environments.add_member(
application.environments[0], workspace_role.user, "developer"
)
Environments.add_member(project.environments[0], workspace_role.user, "developer")
assert workspace_role.has_environment_roles
@@ -260,9 +270,9 @@ def test_can_resend_invitation_if_expired():
def test_can_list_all_environments():
workspace = WorkspaceFactory.create(
projects=[
applications=[
{
"name": "project1",
"name": "application1",
"environments": [
{"name": "dev"},
{"name": "staging"},
@@ -270,7 +280,7 @@ def test_can_list_all_environments():
],
},
{
"name": "project2",
"name": "application2",
"environments": [
{"name": "dev"},
{"name": "staging"},
@@ -278,7 +288,7 @@ def test_can_list_all_environments():
],
},
{
"name": "project3",
"name": "application3",
"environments": [
{"name": "dev"},
{"name": "staging"},

View File

@@ -61,7 +61,7 @@ def test_non_owner_user_with_no_workspaces_redirected_to_requests(client, user_s
assert "/requests" in response.location
def test_non_owner_user_with_one_workspace_redirected_to_workspace_projects(
def test_non_owner_user_with_one_workspace_redirected_to_workspace_applications(
client, user_session
):
user = UserFactory.create()
@@ -71,7 +71,7 @@ def test_non_owner_user_with_one_workspace_redirected_to_workspace_projects(
user_session(user)
response = client.get("/home", follow_redirects=False)
assert "/workspaces/{}/projects".format(workspace.id) in response.location
assert "/workspaces/{}/applications".format(workspace.id) in response.location
def test_non_owner_user_with_mulitple_workspaces_redirected_to_workspaces(

View File

@@ -6,10 +6,10 @@ from tests.factories import (
WorkspaceRoleFactory,
EnvironmentRoleFactory,
EnvironmentFactory,
ProjectFactory,
ApplicationFactory,
)
from atst.domain.projects import Projects
from atst.domain.applications import Applications
from atst.domain.workspaces import Workspaces
from atst.domain.roles import Roles
from atst.models.workspace_role import Status as WorkspaceRoleStatus
@@ -18,7 +18,7 @@ from atst.models.workspace_role import Status as WorkspaceRoleStatus
def test_user_with_permission_has_budget_report_link(client, user_session):
workspace = WorkspaceFactory.create()
user_session(workspace.owner)
response = client.get("/workspaces/{}/projects".format(workspace.id))
response = client.get("/workspaces/{}/applications".format(workspace.id))
assert (
'href="/workspaces/{}/reports"'.format(workspace.id).encode() in response.data
)
@@ -31,7 +31,7 @@ def test_user_without_permission_has_no_budget_report_link(client, user_session)
user, workspace, "developer", status=WorkspaceRoleStatus.ACTIVE
)
user_session(user)
response = client.get("/workspaces/{}/projects".format(workspace.id))
response = client.get("/workspaces/{}/applications".format(workspace.id))
assert (
'href="/workspaces/{}/reports"'.format(workspace.id).encode()
not in response.data
@@ -50,20 +50,20 @@ def test_user_with_permission_has_activity_log_link(client, user_session):
)
user_session(workspace.owner)
response = client.get("/workspaces/{}/projects".format(workspace.id))
response = client.get("/workspaces/{}/applications".format(workspace.id))
assert (
'href="/workspaces/{}/activity"'.format(workspace.id).encode() in response.data
)
# logs out previous user before creating a new session
user_session(admin)
response = client.get("/workspaces/{}/projects".format(workspace.id))
response = client.get("/workspaces/{}/applications".format(workspace.id))
assert (
'href="/workspaces/{}/activity"'.format(workspace.id).encode() in response.data
)
user_session(ccpo)
response = client.get("/workspaces/{}/projects".format(workspace.id))
response = client.get("/workspaces/{}/applications".format(workspace.id))
assert (
'href="/workspaces/{}/activity"'.format(workspace.id).encode() in response.data
)
@@ -80,116 +80,119 @@ def test_user_without_permission_has_no_activity_log_link(client, user_session):
)
user_session(developer)
response = client.get("/workspaces/{}/projects".format(workspace.id))
response = client.get("/workspaces/{}/applications".format(workspace.id))
assert (
'href="/workspaces/{}/activity"'.format(workspace.id).encode()
not in response.data
)
def test_user_with_permission_has_add_project_link(client, user_session):
def test_user_with_permission_has_add_application_link(client, user_session):
workspace = WorkspaceFactory.create()
user_session(workspace.owner)
response = client.get("/workspaces/{}/projects".format(workspace.id))
response = client.get("/workspaces/{}/applications".format(workspace.id))
assert (
'href="/workspaces/{}/projects/new"'.format(workspace.id).encode()
'href="/workspaces/{}/applications/new"'.format(workspace.id).encode()
in response.data
)
def test_user_without_permission_has_no_add_project_link(client, user_session):
def test_user_without_permission_has_no_add_application_link(client, user_session):
user = UserFactory.create()
workspace = WorkspaceFactory.create()
Workspaces._create_workspace_role(user, workspace, "developer")
user_session(user)
response = client.get("/workspaces/{}/projects".format(workspace.id))
response = client.get("/workspaces/{}/applications".format(workspace.id))
assert (
'href="/workspaces/{}/projects/new"'.format(workspace.id).encode()
'href="/workspaces/{}/applications/new"'.format(workspace.id).encode()
not in response.data
)
def test_view_edit_project(client, user_session):
def test_view_edit_application(client, user_session):
workspace = WorkspaceFactory.create()
project = Projects.create(
application = Applications.create(
workspace.owner,
workspace,
"Snazzy Project",
"A new project for me and my friends",
"Snazzy Application",
"A new application for me and my friends",
{"env1", "env2"},
)
user_session(workspace.owner)
response = client.get(
"/workspaces/{}/projects/{}/edit".format(workspace.id, project.id)
"/workspaces/{}/applications/{}/edit".format(workspace.id, application.id)
)
assert response.status_code == 200
def test_user_with_permission_can_update_project(client, user_session):
def test_user_with_permission_can_update_application(client, user_session):
owner = UserFactory.create()
workspace = WorkspaceFactory.create(
owner=owner,
projects=[
applications=[
{
"name": "Awesome Project",
"name": "Awesome Application",
"description": "It's really awesome!",
"environments": [{"name": "dev"}, {"name": "prod"}],
}
],
)
project = workspace.projects[0]
application = workspace.applications[0]
user_session(owner)
response = client.post(
url_for(
"workspaces.update_project",
"workspaces.update_application",
workspace_id=workspace.id,
project_id=project.id,
application_id=application.id,
),
data={"name": "Really Cool Project", "description": "A very cool project."},
data={
"name": "Really Cool Application",
"description": "A very cool application.",
},
follow_redirects=True,
)
assert response.status_code == 200
assert project.name == "Really Cool Project"
assert project.description == "A very cool project."
assert application.name == "Really Cool Application"
assert application.description == "A very cool application."
def test_user_without_permission_cannot_update_project(client, user_session):
def test_user_without_permission_cannot_update_application(client, user_session):
dev = UserFactory.create()
owner = UserFactory.create()
workspace = WorkspaceFactory.create(
owner=owner,
members=[{"user": dev, "role_name": "developer"}],
projects=[
applications=[
{
"name": "Great Project",
"name": "Great Application",
"description": "Cool stuff happening here!",
"environments": [{"name": "dev"}, {"name": "prod"}],
}
],
)
project = workspace.projects[0]
application = workspace.applications[0]
user_session(dev)
response = client.post(
url_for(
"workspaces.update_project",
"workspaces.update_application",
workspace_id=workspace.id,
project_id=project.id,
application_id=application.id,
),
data={"name": "New Name", "description": "A new description."},
follow_redirects=True,
)
assert response.status_code == 404
assert project.name == "Great Project"
assert project.description == "Cool stuff happening here!"
assert application.name == "Great Application"
assert application.description == "Cool stuff happening here!"
def create_environment(user):
workspace = WorkspaceFactory.create()
workspace_role = WorkspaceRoleFactory.create(workspace=workspace, user=user)
project = ProjectFactory.create(workspace=workspace)
return EnvironmentFactory.create(project=project, name="new environment!")
application = ApplicationFactory.create(workspace=workspace)
return EnvironmentFactory.create(application=application, name="new environment!")
def test_environment_access_with_env_role(client, user_session):

View File

@@ -99,7 +99,7 @@ def test_user_who_has_not_accepted_workspace_invite_cannot_view(client, user_ses
# user tries to view workspace before accepting invitation
user_session(user)
response = client.get("/workspaces/{}/projects".format(workspace.id))
response = client.get("/workspaces/{}/applications".format(workspace.id))
assert response.status_code == 404

View File

@@ -8,7 +8,7 @@ from tests.factories import (
)
from atst.domain.workspaces import Workspaces
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.domain.environment_roles import EnvironmentRoles
from atst.queue import queue
@@ -144,16 +144,16 @@ def test_update_member_environment_role(client, user_session):
workspace = WorkspaceFactory.create()
user = UserFactory.create()
member = WorkspaceRoles.add(user, workspace.id, "developer")
project = Projects.create(
application = Applications.create(
workspace.owner,
workspace,
"Snazzy Project",
"A new project for me and my friends",
"Snazzy Application",
"A new application for me and my friends",
{"env1", "env2"},
)
env1_id = project.environments[0].id
env2_id = project.environments[1].id
for env in project.environments:
env1_id = application.environments[0].id
env2_id = application.environments[1].id
for env in application.environments:
Environments.add_member(env, user, "developer")
user_session(workspace.owner)
response = client.post(
@@ -178,15 +178,15 @@ def test_update_member_environment_role_with_no_data(client, user_session):
workspace = WorkspaceFactory.create()
user = UserFactory.create()
member = WorkspaceRoles.add(user, workspace.id, "developer")
project = Projects.create(
application = Applications.create(
workspace.owner,
workspace,
"Snazzy Project",
"A new project for me and my friends",
"Snazzy Application",
"A new application for me and my friends",
{"env1"},
)
env1_id = project.environments[0].id
for env in project.environments:
env1_id = application.environments[0].id
for env in application.environments:
Environments.add_member(env, user, "developer")
user_session(workspace.owner)
response = client.post(
@@ -207,11 +207,11 @@ def test_revoke_active_member_access(client, user_session):
member = WorkspaceRoleFactory.create(
workspace=workspace, user=user, status=WorkspaceRoleStatus.ACTIVE
)
Projects.create(
Applications.create(
workspace.owner,
workspace,
"Snazzy Project",
"A new project for me and my friends",
"Snazzy Application",
"A new application for me and my friends",
{"env1"},
)
user_session(workspace.owner)