Skip to content

Commit

Permalink
test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
petrkalos committed Jun 19, 2024
1 parent d3f98da commit 00cc80a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 18 deletions.
7 changes: 2 additions & 5 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 Down
35 changes: 33 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,34 @@ 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
created
parameters {
key
value
}
}
}
""",
}
response = client.query(query=query)
return response
22 changes: 20 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,27 @@
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 = 'a test description'
env_uri = session_env1.environmentUri
update_environment(client1, env_uri, {'description': test_description})
env = get_environment(client1, env_uri)
assert_that(env.description).is_equal_to(test_description)


def test_modify_env_unauthorized(client2, session_env1):
test_description = 'unauthorized'
env_uri = session_env1.environmentUri
assert_that(update_environment).raises(GqlError).when_called_with(
client2, env_uri, {'description': test_description}
).contains(
'UnauthorizedOperation',
env_uri,
)
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 Down Expand Up @@ -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 All @@ -183,5 +184,4 @@ def test_archive_organization_organization_with_unauthorized_team(client3, org1)
org1.organizationUri,
)


# TODO: list_organization_environments as part of environment tests
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)

0 comments on commit 00cc80a

Please sign in to comment.