Skip to content

Commit

Permalink
Fix coverage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
noah-paige committed Dec 4, 2023
1 parent 4215ff4 commit 95db11b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 94 deletions.
108 changes: 54 additions & 54 deletions tests/modules/mlstudio/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,60 @@ def check_vpc_exists(module_mocker):


@pytest.fixture(scope='module')
def sagemaker_studio_user(client, tenant, group, env_fixture) -> SagemakerStudioUser:
def sagemaker_studio_domain(client, group, env_fixture) -> SagemakerStudioDomain:
response = client.query(
"""
mutation createMLStudioDomain($input: NewStudioDomainInput) {
createMLStudioDomain(input: $input) {
sagemakerStudioUri
environmentUri
label
vpcType
vpcId
subnetIds
}
}
""",
input={
'label': 'testcreate',
'environmentUri': env_fixture.environmentUri,
},
username='alice',
groups=[group.name],
)
yield response.data.createMLStudioDomain


@pytest.fixture(scope='module')
def sagemaker_studio_domain_with_vpc(client, group, env_fixture) -> SagemakerStudioDomain:
response = client.query(
"""
mutation createMLStudioDomain($input: NewStudioDomainInput) {
createMLStudioDomain(input: $input) {
sagemakerStudioUri
environmentUri
label
vpcType
vpcId
subnetIds
}
}
""",
input={
'label': 'testcreate',
'environmentUri': env_fixture.environmentUri,
'vpcId': 'vpc-12345',
'subnetIds': ['subnet-12345', 'subnet-67890']
},
username='alice',
groups=[group.name],
)

yield response.data.createMLStudioDomain


@pytest.fixture(scope='module')
def sagemaker_studio_user(client, tenant, group, env_fixture, sagemaker_studio_domain) -> SagemakerStudioUser:
response = client.query(
"""
mutation createSagemakerStudioUser($input:NewSagemakerStudioUserInput){
Expand Down Expand Up @@ -102,56 +155,3 @@ def multiple_sagemaker_studio_users(client, db, env_fixture, group):
response.data.createSagemakerStudioUser.environmentUri
== env_fixture.environmentUri
)


@pytest.fixture(scope='module')
def sagemaker_studio_domain(client, group, env_fixture) -> SagemakerStudioDomain:
response = client.query(
"""
mutation createMLStudioDomain($input: NewStudioDomainInput) {
createMLStudioDomain(input: $input) {
sagemakerStudioUri
environmentUri
label
vpcType
vpcId
subnetIds
}
}
""",
input={
'label': 'testcreate',
'environmentUri': env_fixture.environmentUri,
},
username='alice',
groups=[group.name],
)
yield response.data.createMLStudioDomain


@pytest.fixture(scope='module')
def sagemaker_studio_domain_with_vpc(client, group, env_fixture) -> SagemakerStudioDomain:
response = client.query(
"""
mutation createMLStudioDomain($input: NewStudioDomainInput) {
createMLStudioDomain(input: $input) {
sagemakerStudioUri
environmentUri
label
vpcType
vpcId
subnetIds
}
}
""",
input={
'label': 'testcreate',
'environmentUri': env_fixture.environmentUri,
'vpcId': 'vpc-12345',
'subnetIds': ['subnet-12345', 'subnet-67890']
},
username='alice',
groups=[group.name],
)

yield response.data.createMLStudioDomain
73 changes: 33 additions & 40 deletions tests/modules/mlstudio/test_sagemaker_studio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
from dataall.modules.mlstudio.db.mlstudio_models import SagemakerStudioUser


def test_create_sagemaker_studio_domain(sagemaker_studio_domain, env_fixture):
"""Testing that the conftest sagemaker studio domain has been created correctly"""
assert sagemaker_studio_domain.label == 'testcreate-domain'
assert sagemaker_studio_domain.vpcType == 'created'
assert sagemaker_studio_domain.vpcId is None
assert len(sagemaker_studio_domain.subnetIds) == 0
assert sagemaker_studio_domain.environmentUri == env_fixture.environmentUri


def test_create_sagemaker_studio_domain_unauthorized(client, env_fixture, group2):
response = client.query(
"""
mutation createMLStudioDomain($input: NewStudioDomainInput) {
createMLStudioDomain(input: $input) {
sagemakerStudioUri
environmentUri
label
vpcType
vpcId
subnetIds
}
}
""",
input={
'label': 'testcreate',
'environmentUri': env_fixture.environmentUri,
},
username='anonymoususer',
groups=[group2.name],
)
assert 'Unauthorized' in response.errors[0].message


def test_create_sagemaker_studio_user(sagemaker_studio_user, group, env_fixture):
"""Testing that the conftest sagemaker studio user has been created correctly"""
assert sagemaker_studio_user.label == 'testcreate'
Expand Down Expand Up @@ -68,46 +101,6 @@ def test_delete_sagemaker_studio_user(
)
assert not n

# @pytest.fixture
# def mock_check_domain_vpc(mocker):
# return mocker.patch(
# 'dataall.modules.mlstudio.services.mlstudio_service.SagemakerStudioService.check_mlstudio_domain_vpc',
# return_value=False,
# )


def test_create_sagemaker_studio_domain(sagemaker_studio_domain, env_fixture):
"""Testing that the conftest sagemaker studio domain has been created correctly"""
assert sagemaker_studio_domain.label == 'testcreate-domain'
assert sagemaker_studio_domain.vpcType == 'created'
assert sagemaker_studio_domain.vpcId is None
assert len(sagemaker_studio_domain.subnetIds) == 0
assert sagemaker_studio_domain.environmentUri == env_fixture.environmentUri


def test_create_sagemaker_studio_domain_unauthorized(client, env_fixture, group2):
response = client.query(
"""
mutation createMLStudioDomain($input: NewStudioDomainInput) {
createMLStudioDomain(input: $input) {
sagemakerStudioUri
environmentUri
label
vpcType
vpcId
subnetIds
}
}
""",
input={
'label': 'testcreate',
'environmentUri': env_fixture.environmentUri,
},
username='anonymoususer',
groups=[group2.name],
)
assert 'Unauthorized' in response.errors[0].message


def test_get_sagemaker_studio_domain(client, env_fixture, sagemaker_studio_domain):
response = client.query(
Expand Down

0 comments on commit 95db11b

Please sign in to comment.