diff --git a/tests_new/integration_tests/client.py b/tests_new/integration_tests/client.py index 5813bd6c2..9006fc264 100644 --- a/tests_new/integration_tests/client.py +++ b/tests_new/integration_tests/client.py @@ -3,12 +3,9 @@ import os from munch import DefaultMunch -ENVNAME = os.getenv('ENVNAME', 'dev') - +from integration_tests.errors import GqlError -class GqlError(RuntimeError): - def __init__(self, msg): - super().__init__(msg) +ENVNAME = os.getenv('ENVNAME', 'dev') class Client: @@ -30,7 +27,7 @@ def query(self, query: str): def _get_jwt_token(self): cognito_client = boto3.client('cognito-idp', region_name=os.getenv('AWS_REGION', 'eu-west-1')) kwargs = { - 'ClientId': os.getenv('COGNITO_CLIENT', False), + 'ClientId': os.environ['COGNITO_CLIENT'], 'AuthFlow': 'USER_PASSWORD_AUTH', 'AuthParameters': { 'USERNAME': self.username, diff --git a/tests_new/integration_tests/conftest.py b/tests_new/integration_tests/conftest.py index c581d1cc1..60df4f843 100644 --- a/tests_new/integration_tests/conftest.py +++ b/tests_new/integration_tests/conftest.py @@ -1,3 +1,4 @@ +import datetime import logging import os import sys @@ -132,3 +133,8 @@ def client4(user4) -> Client: @pytest.fixture(scope='session') def clientTenant(userTenant) -> Client: yield Client(userTenant.username, userTenant.password) + + +@pytest.fixture(scope='session') +def session_id() -> str: + return datetime.datetime.utcnow().isoformat() diff --git a/tests_new/integration_tests/core/environment/queries.py b/tests_new/integration_tests/core/environment/queries.py index 0e5bc41df..36dd0060c 100644 --- a/tests_new/integration_tests/core/environment/queries.py +++ b/tests_new/integration_tests/core/environment/queries.py @@ -13,7 +13,7 @@ def create_environment(client, name, group, organizationUri, awsAccountId, regio } }, 'query': """ - mutation CreateEnvironment($input: NewEnvironmentInput) { + mutation CreateEnvironment($input: NewEnvironmentInput!) { createEnvironment(input: $input) { environmentUri label @@ -38,7 +38,7 @@ def get_environment(client, environmentUri): 'operationName': 'GetEnvironment', 'variables': {'environmentUri': environmentUri}, 'query': """ - query GetEnvironment($environmentUri: String) { + query GetEnvironment($environmentUri: String!) { getEnvironment(environmentUri: $environmentUri) { environmentUri created @@ -116,3 +116,35 @@ def delete_environment(client, environmentUri, deleteFromAWS=True): } response = client.query(query=query) return response + + +def update_environment(client, environmentUri, input: dict): + query = { + 'operationName': 'UpdateEnvironment', + 'variables': { + 'environmentUri': environmentUri, + 'input': input, + }, + 'query': """ + mutation UpdateEnvironment( + $environmentUri: String! + $input: ModifyEnvironmentInput! + ) { + updateEnvironment(environmentUri: $environmentUri, input: $input) { + environmentUri + label + userRoleInEnvironment + SamlGroupName + AwsAccountId + description + created + parameters { + key + value + } + } + } + """, + } + response = client.query(query=query) + return response.data.updateEnvironment diff --git a/tests_new/integration_tests/core/environment/test_environment.py b/tests_new/integration_tests/core/environment/test_environment.py index 56c8abbb0..648c22eef 100644 --- a/tests_new/integration_tests/core/environment/test_environment.py +++ b/tests_new/integration_tests/core/environment/test_environment.py @@ -1,9 +1,31 @@ +from datetime import datetime + from assertpy import assert_that +from integration_tests.core.environment.queries import update_environment, get_environment +from integration_tests.errors import GqlError + def test_create_env(session_env1): assert_that(session_env1.stack.status).is_equal_to('CREATE_COMPLETE') -def test_create_env2(session_env2): - assert_that(session_env2.stack.status).is_equal_to('CREATE_COMPLETE') +def test_modify_env(client1, session_env1): + test_description = f'a test description {datetime.utcnow().isoformat()}' + env_uri = session_env1.environmentUri + updated_env = update_environment(client1, env_uri, {'description': test_description}) + assert_that(updated_env).contains_entry({'environmentUri': env_uri}, {'description': test_description}) + env = get_environment(client1, env_uri) + assert_that(env).contains_entry({'environmentUri': env_uri}, {'description': test_description}) + + +def test_modify_env_unauthorized(client1, client2, session_env1): + test_description = f'unauthorized {datetime.utcnow().isoformat()}' + env_uri = session_env1.environmentUri + assert_that(update_environment).raises(GqlError).when_called_with( + client2, env_uri, {'description': test_description} + ).contains('UnauthorizedOperation', env_uri) + env = get_environment(client1, env_uri) + assert_that(env).contains_entry({'environmentUri': env_uri}).does_not_contain_entry( + {'description': test_description} + ) diff --git a/tests_new/integration_tests/core/organizations/global_conftest.py b/tests_new/integration_tests/core/organizations/global_conftest.py index d4a3f7c31..1177a8121 100644 --- a/tests_new/integration_tests/core/organizations/global_conftest.py +++ b/tests_new/integration_tests/core/organizations/global_conftest.py @@ -3,21 +3,21 @@ @pytest.fixture(scope='session') -def org1(client1, group1): +def org1(client1, group1, session_id): """ Session org owned by group1 """ - org = create_organization(client1, 'organization1', group1) + org = create_organization(client1, 'organization1', group1, tags=[session_id]) yield org archive_organization(client1, org.organizationUri) @pytest.fixture(scope='session') -def org2(client1, group1, group2): +def org2(client1, group1, group2, session_id): """ Session org owned by group1 and invite group2 """ - org = create_organization(client1, 'organization2', group1) + org = create_organization(client1, 'organization2', group1, tags=[session_id]) invite_team_to_organization(client=client1, organizationUri=org.organizationUri, group=group2) yield org archive_organization(client1, org.organizationUri) diff --git a/tests_new/integration_tests/core/organizations/queries.py b/tests_new/integration_tests/core/organizations/queries.py index 498f55683..107d88439 100644 --- a/tests_new/integration_tests/core/organizations/queries.py +++ b/tests_new/integration_tests/core/organizations/queries.py @@ -1,5 +1,5 @@ # TODO: This file will be replaced by using the SDK directly -def create_organization(client, name, group): +def create_organization(client, name, group, tags=[]): query = { 'operationName': 'CreateOrg', 'variables': { @@ -7,7 +7,7 @@ def create_organization(client, name, group): 'label': name, 'SamlGroupName': group, 'description': 'Created for integration testing', - 'tags': [], + 'tags': tags, } }, 'query': """mutation CreateOrg($input: NewOrganizationInput) { diff --git a/tests_new/integration_tests/core/organizations/test_organization.py b/tests_new/integration_tests/core/organizations/test_organization.py index d9c72bd1c..c602d39c8 100644 --- a/tests_new/integration_tests/core/organizations/test_organization.py +++ b/tests_new/integration_tests/core/organizations/test_organization.py @@ -1,6 +1,6 @@ from assertpy import assert_that -from .queries import ( +from integration_tests.core.organizations.queries import ( archive_organization, create_organization, get_organization, @@ -9,6 +9,7 @@ remove_team_from_organization, update_organization, ) +from integration_tests.errors import GqlError def test_create_organization_with_team_with_permissions(org1): @@ -23,7 +24,7 @@ def test_create_organization_with_team_with_permissions(org1): def test_create_organization_with_unauthorized_team(client_noTenantPermissions, group4): # Given a user with no tenant permissions to MANAGE ORGANIZATIONS # When it creates an organization - assert_that(create_organization).raises(RuntimeError).when_called_with( + assert_that(create_organization).raises(GqlError).when_called_with( client_noTenantPermissions, 'organization2', group4, @@ -55,7 +56,7 @@ def test_get_organization_organization_with_invited_team(client2, org2): def test_get_organization_with_unauthorized_team(client3, org1): - assert_that(get_organization).raises(RuntimeError).when_called_with( + assert_that(get_organization).raises(GqlError).when_called_with( client=client3, organizationUri=org1.organizationUri, ).contains( @@ -65,26 +66,26 @@ def test_get_organization_with_unauthorized_team(client3, org1): ) -def test_list_organizations_with_admin_team(client1, org1, org2): +def test_list_organizations_with_admin_team(client1, org1, org2, session_id): # Given 2 organizations # When the admin user of both of them - response = list_organizations(client1) + response = list_organizations(client1, term=session_id) # Then assert_that(response.count).is_equal_to(2) -def test_list_organizations_with_invited_team(client2, org1, org2): +def test_list_organizations_with_invited_team(client2, org1, org2, session_id): # Given 2 organizations # When an invited user to one organization only - response = list_organizations(client2) + response = list_organizations(client2, term=session_id) # Then assert_that(response.count).is_equal_to(1) -def test_list_organizations_with_unauthorized_team(client3, org1, org2): +def test_list_organizations_with_unauthorized_team(client3, org1, org2, session_id): # Given 2 organizations # When a non-invited user - response = list_organizations(client3) + response = list_organizations(client3, term=session_id) # Then assert_that(response.count).is_equal_to(0) @@ -101,7 +102,7 @@ def test_update_organization_organization_with_admin_team(client1, org1): def test_update_organization_organization_with_unauthorized_team(client3, org1): - assert_that(update_organization).raises(RuntimeError).when_called_with( + assert_that(update_organization).raises(GqlError).when_called_with( client=client3, organizationUri=org1.organizationUri, ).contains( @@ -121,7 +122,7 @@ def test_invite_group_to_organization_with_admin_team(org2): def test_invite_group_to_organization_with_unauthorized_team(client3, org1, group2): - assert_that(invite_team_to_organization).raises(RuntimeError).when_called_with( + assert_that(invite_team_to_organization).raises(GqlError).when_called_with( client=client3, organizationUri=org1.organizationUri, group=group2, @@ -142,7 +143,7 @@ def test_remove_group_from_organization_with_admin_team(client1, org2, group2): def test_remove_group_from_organization_with_unauthorized_team(client3, org2, group2): - assert_that(remove_team_from_organization).raises(RuntimeError).when_called_with( + assert_that(remove_team_from_organization).raises(GqlError).when_called_with( client=client3, organizationUri=org2.organizationUri, group=group2, @@ -163,7 +164,7 @@ def test_archive_organization_organization_with_admin_team(client1, group1): def test_archive_organization_organization_with_invited_team(client2, org2): - assert_that(archive_organization).raises(RuntimeError).when_called_with( + assert_that(archive_organization).raises(GqlError).when_called_with( client=client2, organizationUri=org2.organizationUri, ).contains( @@ -174,7 +175,7 @@ def test_archive_organization_organization_with_invited_team(client2, org2): def test_archive_organization_organization_with_unauthorized_team(client3, org1): - assert_that(archive_organization).raises(RuntimeError).when_called_with( + assert_that(archive_organization).raises(GqlError).when_called_with( client=client3, organizationUri=org1.organizationUri, ).contains( diff --git a/tests_new/integration_tests/errors.py b/tests_new/integration_tests/errors.py new file mode 100644 index 000000000..74626209b --- /dev/null +++ b/tests_new/integration_tests/errors.py @@ -0,0 +1,3 @@ +class GqlError(RuntimeError): + def __init__(self, msg): + super().__init__(msg)