Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
petrkalos committed Feb 6, 2024
1 parent 823e8b1 commit a14d1f2
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ def mock_aws_client(module_mocker):
session_helper
)

module_mocker.patch(
'dataall.base.aws.sts.SessionHelper',
session_helper
)

session_helper.get_session.return_value = session
session_helper.remote_session.return_value = session
session.client.return_value = aws_client
Expand Down
39 changes: 39 additions & 0 deletions tests/core/environments/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import uuid

from tests.core.permissions.test_permission import *


@pytest.fixture
def consumption_role(mock_aws_client, client, org_fixture, env_fixture, user, group, db):
test_arn = f'arn:aws:sts::111111111111:assumed-role/Test/{str(uuid.uuid4())[:8]}'
mock_aws_client.get_role.return_value = {'Role': {'Arn': test_arn}}
query = """
mutation addConsumptionRoleToEnvironment(
$input:AddConsumptionRoleToEnvironmentInput
){
addConsumptionRoleToEnvironment(
input:$input
){
consumptionRoleUri
consumptionRoleName
environmentUri
groupUri
IAMRoleName
IAMRoleArn
}
}
"""
response = client.query(
query,
username=user,
groups=[group.name],
environmentUri=env_fixture.environmentUri,
input={
'consumptionRoleName': str(uuid.uuid4())[:8],
'groupUri': str(uuid.uuid4())[:8],
'IAMRoleArn': test_arn,
'environmentUri': env_fixture.environmentUri
},
)
assert not response.errors
return response
61 changes: 60 additions & 1 deletion tests/core/environments/test_environment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from dataall.core.environment.api.enums import EnvironmentPermission
from dataall.core.environment.db.environment_models import Environment
from dataall.core.environment.services.environment_service import EnvironmentService
from dataall.core.permissions.db.resource_policy_repositories import ResourcePolicy
from dataall.core.permissions.permissions import REMOVE_ENVIRONMENT_CONSUMPTION_ROLE


def get_env(client, env_fixture, group):
return client.query(
Expand Down Expand Up @@ -582,7 +585,8 @@ def test_group_invitation(db, client, env_fixture, org_fixture, group2, user, gr
]


def test_archive_env(client, org_fixture, env_fixture, group, group2):
def test_archive_env(client, org_fixture, env, group, group2):
env_fixture = env(org_fixture, 'dev-delete', 'alice', 'testadmins', '111111111111', 'eu-west-1')
response = client.query(
"""
mutation deleteEnvironment($environmentUri:String!, $deleteFromAWS:Boolean!){
Expand Down Expand Up @@ -652,3 +656,58 @@ def test_create_environment(db, client, org_fixture, env_fixture, user, group):
)
session.delete(env)
session.commit()


def test_update_consumption_role(
client,
org_fixture,
env_fixture,
user,
group,
db,
consumption_role
):
query = """
mutation updateConsumptionRole(
$environmentUri:String!,
$consumptionRoleUri:String!,
$input:UpdateConsumptionRoleInput
){
updateConsumptionRole(
environmentUri:$environmentUri,
consumptionRoleUri: $consumptionRoleUri,
input:$input
){
consumptionRoleUri
consumptionRoleName
environmentUri
groupUri
IAMRoleName
IAMRoleArn
}
}
"""

consumption_role_uri = consumption_role.data.addConsumptionRoleToEnvironment.consumptionRoleUri

with db.scoped_session() as session:
ResourcePolicy.attach_resource_policy(
session=session,
resource_uri=consumption_role_uri,
group=group.name,
permissions=[REMOVE_ENVIRONMENT_CONSUMPTION_ROLE],
resource_type=Environment.__name__,
)

response = client.query(
query,
username=user,
groups=[group.name],
environmentUri=env_fixture.environmentUri,
consumptionRoleUri=consumption_role_uri,
input={'consumptionRoleName': 'testRoleName', 'groupUri': 'testGroupUri'},
)

assert not response.errors
assert response.data.updateConsumptionRole.consumptionRoleName == 'testRoleName'
assert response.data.updateConsumptionRole.groupUri == 'testGroupUri'

0 comments on commit a14d1f2

Please sign in to comment.