Merge pull request #522 from dod-ccpo/csp-env-integration
CSP Interface: Environments
This commit is contained in:
@@ -2,7 +2,36 @@ from atst.domain.environments import Environments
|
||||
from atst.domain.environment_roles import EnvironmentRoles
|
||||
from atst.domain.workspace_roles import WorkspaceRoles
|
||||
|
||||
from tests.factories import UserFactory, WorkspaceFactory
|
||||
from tests.factories import ProjectFactory, UserFactory, WorkspaceFactory
|
||||
|
||||
|
||||
def test_create_environments():
|
||||
project = ProjectFactory.create()
|
||||
environments = Environments.create_many(project, ["Staging", "Production"])
|
||||
for env in environments:
|
||||
assert env.cloud_id is not None
|
||||
|
||||
|
||||
def test_create_environment_role_creates_cloud_id(session):
|
||||
owner = UserFactory.create()
|
||||
developer = UserFactory.from_atat_role("developer")
|
||||
|
||||
workspace = WorkspaceFactory.create(
|
||||
owner=owner,
|
||||
members=[{"user": developer, "role_name": "developer"}],
|
||||
projects=[{"name": "project1", "environments": [{"name": "project1 prod"}]}],
|
||||
)
|
||||
|
||||
env = workspace.projects[0].environments[0]
|
||||
new_role = [{"id": env.id, "role": "developer"}]
|
||||
|
||||
workspace_role = workspace.members[0]
|
||||
assert not workspace_role.user.cloud_id
|
||||
assert Environments.update_environment_roles(
|
||||
owner, workspace, workspace_role, new_role
|
||||
)
|
||||
|
||||
assert workspace_role.user.cloud_id is not None
|
||||
|
||||
|
||||
def test_update_environment_roles():
|
||||
|
@@ -1,6 +1,13 @@
|
||||
from flask import url_for
|
||||
|
||||
from tests.factories import UserFactory, WorkspaceFactory
|
||||
from tests.factories import (
|
||||
UserFactory,
|
||||
WorkspaceFactory,
|
||||
WorkspaceRoleFactory,
|
||||
EnvironmentRoleFactory,
|
||||
EnvironmentFactory,
|
||||
ProjectFactory,
|
||||
)
|
||||
from atst.domain.projects import Projects
|
||||
from atst.domain.workspaces import Workspaces
|
||||
from atst.models.workspace_role import Status as WorkspaceRoleStatus
|
||||
@@ -125,3 +132,42 @@ def test_user_without_permission_cannot_update_project(client, user_session):
|
||||
assert response.status_code == 404
|
||||
assert project.name == "Great Project"
|
||||
assert project.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!")
|
||||
|
||||
|
||||
def test_environment_access_with_env_role(client, user_session):
|
||||
user = UserFactory.create()
|
||||
environment = create_environment(user)
|
||||
env_role = EnvironmentRoleFactory.create(
|
||||
user=user, environment=environment, role="developer"
|
||||
)
|
||||
user_session(user)
|
||||
response = client.get(
|
||||
url_for(
|
||||
"workspaces.access_environment",
|
||||
workspace_id=environment.workspace.id,
|
||||
environment_id=environment.id,
|
||||
)
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert "csp-environment-access" in response.location
|
||||
|
||||
|
||||
def test_environment_access_with_no_role(client, user_session):
|
||||
user = UserFactory.create()
|
||||
environment = create_environment(user)
|
||||
user_session(user)
|
||||
response = client.get(
|
||||
url_for(
|
||||
"workspaces.access_environment",
|
||||
workspace_id=environment.workspace.id,
|
||||
environment_id=environment.id,
|
||||
)
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
Reference in New Issue
Block a user