Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update gql apis + update_environment tests #1348

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions tests_new/integration_tests/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions tests_new/integration_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import logging
import os
import sys
Expand Down Expand Up @@ -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()
36 changes: 34 additions & 2 deletions tests_new/integration_tests/core/environment/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
26 changes: 24 additions & 2 deletions tests_new/integration_tests/core/environment/test_environment.py
Original file line number Diff line number Diff line change
@@ -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}
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests_new/integration_tests/core/organizations/queries.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# 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': {
'input': {
'label': name,
'SamlGroupName': group,
'description': 'Created for integration testing',
'tags': [],
'tags': tags,
}
},
'query': """mutation CreateOrg($input: NewOrganizationInput) {
Expand Down
29 changes: 15 additions & 14 deletions tests_new/integration_tests/core/organizations/test_organization.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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):
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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)

Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions tests_new/integration_tests/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class GqlError(RuntimeError):
def __init__(self, msg):
super().__init__(msg)
Loading