Skip to content

Commit

Permalink
chore(job_attachments): remove service model file (#193)
Browse files Browse the repository at this point in the history
Signed-off-by: Gahyun Suh <[email protected]>
  • Loading branch information
gahyusuh authored Mar 4, 2024
1 parent 398da18 commit 6c9142e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12,662 deletions.
23 changes: 18 additions & 5 deletions test/unit/deadline_job_attachments/aws/test_aws_clients.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

"""Tests for aws clients"""
from unittest.mock import Mock, patch
from deadline.job_attachments._aws.aws_clients import (
get_deadline_client,
get_s3_client,
get_sts_client,
)
import deadline
from deadline.job_attachments._aws.aws_config import (
S3_CONNECT_TIMEOUT_IN_SECS,
S3_READ_TIMEOUT_IN_SECS,
Expand All @@ -16,9 +18,15 @@ def test_get_deadline_client(boto_config):
"""
Test that get_deadline_client returns the correct deadline client
"""
deadline_client = get_deadline_client()
session_mock = Mock()
with patch(
f"{deadline.__package__}.job_attachments._aws.aws_clients.get_boto3_session"
) as get_session:
get_session.return_value = session_mock
session_mock.client.return_value = Mock()
get_deadline_client()

assert deadline_client.meta.service_model.service_name == "deadline"
session_mock.client.assert_called_with("deadline", endpoint_url=None)


def test_get_deadline_client_non_default_endpoint(boto_config):
Expand All @@ -27,10 +35,15 @@ def test_get_deadline_client_non_default_endpoint(boto_config):
and that the endpoint url is the given one when provided.
"""
test_endpoint = "https://test.com"
deadline_client = get_deadline_client(endpoint_url=test_endpoint)
session_mock = Mock()
with patch(
f"{deadline.__package__}.job_attachments._aws.aws_clients.get_boto3_session"
) as get_session:
get_session.return_value = session_mock
session_mock.client.return_value = Mock()
get_deadline_client(endpoint_url=test_endpoint)

assert deadline_client.meta.service_model.service_name == "deadline"
assert deadline_client.meta.endpoint_url == test_endpoint
session_mock.client.assert_called_with("deadline", endpoint_url=test_endpoint)


def test_get_s3_client(boto_config):
Expand Down
48 changes: 35 additions & 13 deletions test/unit/deadline_job_attachments/aws/test_deadline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,49 @@

"""Tests for Deadline AWS calls."""
import pytest
from unittest.mock import MagicMock, patch
from botocore.exceptions import ClientError

import deadline
from deadline.job_attachments._aws.deadline import get_queue
from deadline.job_attachments.exceptions import JobAttachmentsError
from deadline.job_attachments.models import Queue


def test_get_queue(deadline_stub, default_queue: Queue, create_get_queue_response):
deadline_stub.add_response(
"get_queue",
create_get_queue_response(default_queue),
{"farmId": default_queue.farmId, "queueId": default_queue.queueId},
)
@patch(f"{deadline.__package__}.job_attachments._aws.aws_clients.get_boto3_session")
def test_get_queue(mock_get_boto3_session, default_queue: Queue, create_get_queue_response):
# Set up the mock session and mock deadline client
mock_session = MagicMock()
mock_get_boto3_session.return_value = mock_session
mock_deadline_client = MagicMock()
mock_session.client.return_value = mock_deadline_client
# Simulate a response from get_queue
mock_deadline_client.get_queue.return_value = create_get_queue_response(default_queue)

result = get_queue(default_queue.farmId, default_queue.queueId)

with deadline_stub:
assert get_queue(default_queue.farmId, default_queue.queueId) == default_queue
mock_get_boto3_session.assert_called_once()
mock_session.client.assert_called_with("deadline", endpoint_url=None)
mock_deadline_client.get_queue.assert_called_once_with(
farmId=default_queue.farmId, queueId=default_queue.queueId
)
assert result == default_queue


def test_get_queue_fail_to_get_queue(
deadline_stub, default_queue: Queue, create_get_queue_response
):
deadline_stub.add_client_error("get_queue")
@patch(f"{deadline.__package__}.job_attachments._aws.deadline.get_deadline_client")
def test_get_queue_client_error(mock_get_deadline_client, default_queue: Queue):
# Set up the mock deadline client
mock_client = mock_get_deadline_client.return_value
# Simulate a ClientError from get_queue
mock_client.get_queue.side_effect = ClientError(
{"Error": {"Code": "SomeErrorCode", "Message": "SomeErrorMessage"}},
"GetQueue",
)

with deadline_stub, pytest.raises(JobAttachmentsError):
with pytest.raises(JobAttachmentsError) as exc_info:
get_queue(default_queue.farmId, default_queue.queueId)

# Check that the correct exception is raised
assert 'Failed to get queue "queue-01234567890123456789012345678901" from Deadline: ' in str(
exc_info.value
)
23 changes: 1 addition & 22 deletions test/unit/deadline_job_attachments/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import dataclasses
import json
import os
import pathlib
from datetime import datetime
from io import BytesIO
from typing import Any, Callable, Generator
Expand All @@ -23,11 +22,8 @@
# or otherwise use moto with it in our tests, so let's just start it here so the rest of our mocking works as expected
mock_iotdata().start()

import boto3 # noqa: E402 isort:skip
from botocore.client import BaseClient # noqa: E402 isort:skip
from botocore.stub import Stubber # noqa: E402 isort:skip

import deadline # noqa: E402 isort:skip
from deadline.job_attachments._aws import aws_clients # noqa: E402 isort:skip
from deadline.job_attachments.asset_sync import AssetSync # noqa: E402 isort:skip
from deadline.job_attachments.models import ( # noqa: E402 isort:skip
Expand All @@ -47,8 +43,6 @@ def boto_config() -> Generator[None, None, None]:
"AWS_ACCESS_KEY_ID": "ACCESSKEY",
"AWS_SECRET_ACCESS_KEY": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"AWS_DEFAULT_REGION": "us-west-2",
# Coverlay doesn't have access to the deadline models, patch it in here.
"AWS_DATA_PATH": str((pathlib.Path(__file__) / ".." / "data" / "boto_module").resolve()),
}
with patch.dict("os.environ", updated_environment):
yield
Expand Down Expand Up @@ -78,21 +72,6 @@ def create_bucket(bucket_name):
return create_bucket


@pytest.fixture(scope="function")
def deadline_stub(boto_config) -> Generator[Stubber, None, None]:
"""
Fixture that yields a stubber for a Deadline client.
"""
deadline_client = boto3.client("deadline")
stubber = Stubber(deadline_client)

with patch(
f"{deadline.__package__}.job_attachments._aws.deadline.get_deadline_client",
return_value=deadline_client,
):
yield stubber


@pytest.fixture(name="default_job_attachment_s3_settings")
def fixture_default_job_attachment_s3_settings():
"""
Expand Down Expand Up @@ -202,7 +181,7 @@ def __inner_func__(bucket, manifest_location, expected_manifest):
@pytest.fixture
def assert_canonical_manifest():
"""
Assert that a canconical manifest file in a mock s3 bucket matches what's expected.
Assert that a canonical manifest file in a mock s3 bucket matches what's expected.
"""

def __inner_func__(bucket, manifest_location: str, expected_manifest: str):
Expand Down
Loading

0 comments on commit 6c9142e

Please sign in to comment.