From 066ade7f529c4b067e088d694d2b64f2d05cd666 Mon Sep 17 00:00:00 2001 From: Montana Date: Wed, 26 Sep 2018 11:10:25 -0400 Subject: [PATCH] Add more tests for workspaces routes --- tests/routes/test_workspaces.py | 100 ++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/tests/routes/test_workspaces.py b/tests/routes/test_workspaces.py index 3523d207..66086e98 100644 --- a/tests/routes/test_workspaces.py +++ b/tests/routes/test_workspaces.py @@ -73,6 +73,59 @@ def test_update_workspace_name(client, user_session): assert workspace.name == "a cool new name" +def test_view_edit_project(client, user_session): + owner = UserFactory.create() + workspace = WorkspaceFactory.create() + Workspaces._create_workspace_role(owner, workspace, "admin") + project = Projects.create( + owner, + workspace, + "Snazzy Project", + "A new project for me and my friends", + {"env1", "env2"}, + ) + user_session(owner) + response = client.get( + "/workspaces/{}/projects/{}/edit".format(workspace.id, project.id) + ) + assert response.status_code == 200 + + +def test_create_member(client, user_session): + owner = UserFactory.create() + user = UserFactory.create() + workspace = WorkspaceFactory.create() + Workspaces._create_workspace_role(owner, workspace, "admin") + user_session(owner) + response = client.post( + url_for("workspaces.create_member", workspace_id=workspace.id), + data={ + "dod_id": user.dod_id, + "first_name": "Wilbur", + "last_name": "Zuckerman", + "email": "some_pig@zuckermans.com", + "workspace_role": "developer", + }, + follow_redirects=True, + ) + + assert response.status_code == 200 + assert user.has_workspaces + + +def test_permissions_for_view_member(client, user_session): + user = UserFactory.create() + workspace = WorkspaceFactory.create() + Workspaces._create_workspace_role(user, workspace, "developer") + member = WorkspaceUsers.add(user, workspace.id, "developer") + user_session(user) + response = client.post( + url_for("workspaces.view_member", workspace_id=workspace.id, member_id=user.id), + follow_redirects=True, + ) + assert response.status_code == 404 + + def test_update_member_workspace_role(client, user_session): owner = UserFactory.create() workspace = WorkspaceFactory.create() @@ -91,6 +144,24 @@ def test_update_member_workspace_role(client, user_session): assert member.role == "security_auditor" +def test_update_member_workspace_role_with_no_data(client, user_session): + owner = UserFactory.create() + workspace = WorkspaceFactory.create() + Workspaces._create_workspace_role(owner, workspace, "admin") + user = UserFactory.create() + member = WorkspaceUsers.add(user, workspace.id, "developer") + user_session(owner) + response = client.post( + url_for( + "workspaces.update_member", workspace_id=workspace.id, member_id=user.id + ), + data={}, + follow_redirects=True, + ) + assert response.status_code == 200 + assert member.role == "developer" + + def test_update_member_environment_role(client, user_session): owner = UserFactory.create() workspace = WorkspaceFactory.create() @@ -124,3 +195,32 @@ def test_update_member_environment_role(client, user_session): assert response.status_code == 200 assert EnvironmentRoles.get(user.id, env1_id).role == "security_auditor" assert EnvironmentRoles.get(user.id, env2_id).role == "devops" + + +def test_update_member_environment_role_with_no_data(client, user_session): + owner = UserFactory.create() + workspace = WorkspaceFactory.create() + Workspaces._create_workspace_role(owner, workspace, "admin") + + user = UserFactory.create() + member = WorkspaceUsers.add(user, workspace.id, "developer") + project = Projects.create( + owner, + workspace, + "Snazzy Project", + "A new project for me and my friends", + {"env1"}, + ) + env1_id = project.environments[0].id + for env in project.environments: + Environments.add_member(env, user, "developer") + user_session(owner) + response = client.post( + url_for( + "workspaces.update_member", workspace_id=workspace.id, member_id=user.id + ), + data={"env_" + str(env1_id): None, "env_" + str(env1_id): ""}, + follow_redirects=True, + ) + assert response.status_code == 200 + assert EnvironmentRoles.get(user.id, env1_id).role == "developer"