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

Removed localstack dependency from toolchain #33

Merged
merged 2 commits into from
Oct 16, 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
23 changes: 0 additions & 23 deletions .github/workflows/prbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,6 @@ jobs:
with:
extra_args: --only-verified

- name: Restore Localstack Image Cache if it exists
id: cache-docker-localstack
uses: actions/cache@v4
with:
path: ci/cache/docker/localstack
key: cache-docker-localstack-3.8

- name: Update Localstack Image Cache if cache miss
if: steps.cache-docker-localstack.outputs.cache-hit != 'true'
run: docker pull public.ecr.aws/localstack/localstack:3.8 && mkdir -p ci/cache/docker/localstack && docker image save public.ecr.aws/localstack/localstack:3.8 --output ./ci/cache/docker/localstack/localstack-3.8.tar

- name: Use Localstack Image Cache if cache hit
if: steps.cache-docker-localstack.outputs.cache-hit == 'true'
run: docker image load --input ./ci/cache/docker/localstack/localstack-3.8.tar

- name: Set up compose stack
run: |
docker compose -f compose.yml up -d

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand All @@ -68,7 +49,3 @@ jobs:
- name: Run test suite
run: |
make test

- name: Tear down compose stack
run: |
docker compose -f compose.yml down
12 changes: 0 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ deep: scan
baseline:
@detect-secrets scan --exclude-files '^(yarn.lock|.yarn/|.local/|openapi/)' > .secrets.baseline

up:
@docker compose up -d

down:
@docker compose down

stop:
@docker compose down

ps:
@docker compose ps

pytest:
@py.test --no-cov tests/

Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ _This arrangement is sometime also known as deferring feature flag toggle at run
git clone https://github.com/umccr/libumccr.git
cd libumccr
conda activate libumccr
make up
make ps
make install all
make check
make test
Expand Down
10 changes: 0 additions & 10 deletions compose.yml

This file was deleted.

7 changes: 0 additions & 7 deletions init-aws.sh

This file was deleted.

36 changes: 2 additions & 34 deletions tests/aws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import logging
import uuid
from unittest import TestCase

from mockito import when, unstub

from libumccr import aws
from libumccr.aws import libsqs, libeb
from mockito import unstub

logger = logging.getLogger()
logger.setLevel(logging.INFO)
Expand All @@ -14,35 +10,7 @@
class AWSTestCase(TestCase):

def setUp(self) -> None:
super().setUp()

mock_sqs = aws.client(
'sqs',
endpoint_url='http://localhost:4566',
region_name='us-east-1',
aws_access_key_id=str(uuid.uuid4()),
aws_secret_access_key=str(uuid.uuid4()),
aws_session_token=f"{uuid.uuid4()}_{uuid.uuid4()}"
)
when(aws).sqs_client(...).thenReturn(mock_sqs)
when(libsqs).sqs_client(...).thenReturn(mock_sqs)

mock_eb = aws.client(
'events',
endpoint_url='http://localhost:4566',
region_name='us-east-1',
aws_access_key_id=str(uuid.uuid4()),
aws_secret_access_key=str(uuid.uuid4()),
aws_session_token=f"{uuid.uuid4()}_{uuid.uuid4()}"
)
when(aws).eb_client(...).thenReturn(mock_eb)
when(libeb).eb_client(...).thenReturn(mock_eb)
super(AWSTestCase, self).setUp()

def tearDown(self) -> None:
unstub()

def verify_local(self):
queue_urls = libsqs.sqs_client().list_queues()['QueueUrls']
logger.info(f"SQS_QUEUE_URLS={queue_urls}")
self.assertIn('4566', queue_urls[0])
logger.info(f"-" * 32)
81 changes: 69 additions & 12 deletions tests/aws/test_libeb.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
from datetime import datetime

import boto3
from botocore.stub import Stubber
from libumccr import aws
from mockito import when

from libumccr.aws import libeb
from tests.aws import AWSTestCase, logger


class LibEBUnitTests(AWSTestCase):

def setUp(self):
super(LibEBUnitTests, self).setUp()
mock_eb_client = boto3.client('events', region_name='us-east-1')
self.stubber = Stubber(mock_eb_client)
self.stubber.activate()
when(aws).eb_client(...).thenReturn(mock_eb_client)
when(libeb).eb_client(...).thenReturn(mock_eb_client)

def test_eb_client(self):
"""
python -m unittest tests.aws.test_libeb.LibEBUnitTests.test_eb_client
Expand All @@ -19,6 +32,20 @@ def test_get_event_buses(self):
"""
python -m unittest tests.aws.test_libeb.LibEBUnitTests.test_get_event_buses
"""
self.stubber.add_response('list_event_buses', {
'EventBuses': [
{
'Name': 'string',
'Arn': 'string',
'Description': 'string',
'Policy': 'string',
'CreationTime': datetime(2015, 1, 1),
'LastModifiedTime': datetime(2015, 1, 1)
},
],
'NextToken': 'string'
})

resp = libeb.get_event_buses()
logger.info(resp)
self.assertIsNotNone(resp)
Expand All @@ -27,18 +54,16 @@ def test_emit_events(self):
"""
python -m unittest tests.aws.test_libeb.LibEBUnitTests.test_emit_events
"""
# when(BaseClient)._make_api_call(...).thenReturn(
# {
# "FailedEntryCount": 123,
# "Entries": [
# {
# "EventId": "string",
# "ErrorCode": "string",
# "ErrorMessage": "string"
# },
# ]
# }
# )
self.stubber.add_response('put_events', {
'FailedEntryCount': 123,
'Entries': [
{
'EventId': 'string',
'ErrorCode': 'string',
'ErrorMessage': 'string'
},
]
})

resp = libeb.emit_events([
{
Expand All @@ -61,6 +86,17 @@ def test_emit_event(self):
"""
python -m unittest tests.aws.test_libeb.LibEBUnitTests.test_emit_event
"""
self.stubber.add_response('put_events', {
'FailedEntryCount': 123,
'Entries': [
{
'EventId': 'string',
'ErrorCode': 'string',
'ErrorMessage': 'string'
},
]
})

resp = libeb.emit_event(
{
"Time": datetime(2015, 1, 1),
Expand All @@ -82,6 +118,27 @@ def test_dispatch_events(self):
"""
python -m unittest tests.aws.test_libeb.LibEBUnitTests.test_dispatch_events
"""
self.stubber.add_response('put_events', {
'FailedEntryCount': 123,
'Entries': [
{
'EventId': 'string',
'ErrorCode': 'string',
'ErrorMessage': 'string'
},
]
})
self.stubber.add_response('put_events', {
'FailedEntryCount': 123,
'Entries': [
{
'EventId': 'string',
'ErrorCode': 'string',
'ErrorMessage': 'string'
},
]
})

mock_entries = []
for n in range(20):
mock_entries.append(
Expand Down
21 changes: 10 additions & 11 deletions tests/aws/test_libsm.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging
import sys
import uuid
from unittest import TestCase, skip
from unittest.mock import patch

import boto3
from botocore.stub import Stubber
from mockito import when

from libumccr import aws
Expand All @@ -15,16 +16,14 @@ class LibSmUnitTests(TestCase):

def setUp(self):
from libumccr.aws import libsm
mock_sm = aws.client(
'secretsmanager',
endpoint_url='http://localhost:4566',
region_name='ap-southeast-2',
aws_access_key_id=str(uuid.uuid4()),
aws_secret_access_key=str(uuid.uuid4()),
aws_session_token=f"{uuid.uuid4()}_{uuid.uuid4()}"
)
when(aws).sm_client(...).thenReturn(mock_sm)
when(libsm).sm_client(...).thenReturn(mock_sm)
mock_sm_client = boto3.client('secretsmanager', region_name='us-east-1')
stubber = Stubber(mock_sm_client)
stubber.add_response('get_secret_value', {
'SecretString': 'HealTheWorld', # pragma: allowlist secret
})
stubber.activate()
when(aws).sm_client(...).thenReturn(mock_sm_client)
when(libsm).sm_client(...).thenReturn(mock_sm_client)

def test_cache_clear(self):
"""
Expand Down
22 changes: 10 additions & 12 deletions tests/aws/test_libssm.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging
import sys
import uuid
from unittest import TestCase, skip
from unittest.mock import patch

import boto3
from botocore.stub import Stubber
from mockito import when

from libumccr import aws
Expand All @@ -15,16 +16,13 @@ class LibSsmUnitTests(TestCase):

def setUp(self):
from libumccr.aws import libssm
mock_ssm = aws.client(
'ssm',
endpoint_url='http://localhost:4566',
region_name='ap-southeast-2',
aws_access_key_id=str(uuid.uuid4()),
aws_secret_access_key=str(uuid.uuid4()),
aws_session_token=f"{uuid.uuid4()}_{uuid.uuid4()}"
)
when(aws).ssm_client(...).thenReturn(mock_ssm)
when(libssm).ssm_client(...).thenReturn(mock_ssm)
mock_ssm_client = boto3.client('ssm', region_name='us-east-1')
stubber = Stubber(mock_ssm_client)
stubber.add_response('get_parameter', {'Parameter': {'Value': 'Sello'}})
stubber.activate()
when(aws).ssm_client(...).thenReturn(mock_ssm_client)
when(libssm).ssm_client(...).thenReturn(mock_ssm_client)
super(LibSsmUnitTests, self).setUp()

def test_cache_clear(self):
"""
Expand Down Expand Up @@ -83,7 +81,7 @@ def test_get_ssm_param(self):
from libumccr.aws import libssm
value = libssm.get_ssm_param(name='my-param')
logger.info(value)
self.assertEqual(value, 'Hello')
self.assertEqual(value, 'Sello')


class LibSsmIntegrationTests(TestCase):
Expand Down