Skip to content
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
35 changes: 35 additions & 0 deletions .github/workflows/pull_requests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PullRequest

on:
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Check out the repository
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install Poetry
run: |
pip install poetry
poetry --version
- name: Build package
run: |
poetry build
- name: Install package
run: |
poetry install
- name: Run pytest
run: |
poetry run pytest --cov=sns_extended_client test --cov-report term-missing
13 changes: 8 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Detect and tag new version
id: check-version
if: steps.check-parent-commit.outputs.sha
uses: salsify/action-detect-and-tag-new-version@b1778166f13188a9d478e2d1198f993011ba9864 # v2.0.3
uses: salsify/action-detect-and-tag-new-version@v2
with:
version-command: |
bash -o pipefail -c "poetry version | awk '{ print \$2 }'"
Expand All @@ -54,11 +54,14 @@ jobs:
run: |
poetry run pytest --cov=sns_extended_client test --cov-report term-missing
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.OIDC_ROLE_NAME }}
role-session-name: publishrolesession
aws-region: ${{ env.AWS_REGION }}
- name: Run Integration Tests
run: |
poetry run pytest test_integ
- name: Retrieve TEST PYPI TOKEN from secretsmanager
id: get-test-pypi-token
if: "! steps.check-version.outputs.tag"
Expand All @@ -71,14 +74,14 @@ jobs:
echo "token=$(aws secretsmanager get-secret-value --secret-id ${{ vars.PYPI_TOKEN_NAME }} | jq -r '.SecretString')" >> $GITHUB_OUTPUT
- name: Publish package on TestPyPI
if: "! steps.check-version.outputs.tag"
uses: pypa/gh-action-pypi-publish@f8c70e705ffc13c3b4d1221169b84f12a75d6ca8 # release/v1
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ steps.get-test-pypi-token.outputs.token }}
repository_url: https://test.pypi.org/legacy/
repository-url: https://test.pypi.org/legacy/
- name: Publish package on PyPI
if: steps.check-version.outputs.tag
uses: pypa/gh-action-pypi-publish@f8c70e705ffc13c3b4d1221169b84f12a75d6ca8 # release/v1
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ steps.get-pypi-token.outputs.token }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
.coverage
.pytest_cache
__pycache__
*.DS_Store
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "amazon-sns-extended-client"
version = "1.0.0"
version = "1.0.1"
description = "Python version of AWS SNS extended client to publish large payload message"
authors = ["Amazon Web Service - SNS"]
license = "Apache-2.0"
Expand Down
4 changes: 4 additions & 0 deletions test_integ/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("Integration Test Logger")
Empty file added test_integ/fixtures/__init__.py
Empty file.
44 changes: 44 additions & 0 deletions test_integ/fixtures/objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import boto3
import pytest
import uuid

@pytest.fixture
def default_message_size_threshold():
return 262144

@pytest.fixture
def small_message_body():
return "small message body"


@pytest.fixture
def small_message_attribute(small_message_body):
return {
'Small_Message_Attribute': {
'StringValue': small_message_body,
'DataType': 'String'
}
}

@pytest.fixture
def custom_s3_key_attribute():
return {
'S3Key': {
'StringValue': str(uuid.uuid4()),
'DataType': 'String'
}
}


@pytest.fixture
def large_message_body(small_message_body, default_message_size_threshold):
return "x" * ( default_message_size_threshold + 1 )

@pytest.fixture
def large_message_attribute(large_message_body):
return {
'Large_Message_Attribute': {
'StringValue': 'Test',
'DataType': 'String'
}
}
19 changes: 19 additions & 0 deletions test_integ/fixtures/session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import boto3
import pytest
from sns_extended_client.session import SNSExtendedClientSession

@pytest.fixture()
def region_name() -> str:
region_name = 'us-east-1'
return region_name

@pytest.fixture()
def session(region_name) -> boto3.Session:

setattr(boto3.session, "Session", SNSExtendedClientSession)
# Now take care of the reference in the boto3.__init__ module since the object is being imported there too
setattr(boto3, "Session", SNSExtendedClientSession)

# return boto3.session.Session()
print("This session is fetched")
return boto3.Session(region_name=region_name)
61 changes: 61 additions & 0 deletions test_integ/fixtures/sns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import boto3
from sns_extended_client import SNSExtendedClientSession
import pytest
import random

@pytest.fixture()
def sns_extended_client(session):
sns_client = session.client("sns",region_name='us-east-1')
sns_client.large_payload_support = f'integration-test-bucket-{random.randint(0, 10000)}'
return sns_client

@pytest.fixture()
def sqs_client(session):
return session.client("sqs")

@pytest.fixture()
def queue_name():
return f"IntegrationTestQueue{random.randint(0,10000)}"

@pytest.fixture()
def topic_name():
return f"IntegrationTestTopic{random.randint(0,10000)}"

@pytest.fixture()
def queue(sqs_client, queue_name):
queue_object = sqs_client.create_queue(QueueName=queue_name)

yield queue_object

sqs_client.purge_queue(
QueueUrl=queue_object['QueueUrl']
)

sqs_client.delete_queue(
QueueUrl=queue_object['QueueUrl']
)

@pytest.fixture()
def topic(sns_extended_client, topic_name):
topic_arn = sns_extended_client.create_topic(Name=topic_name).get("TopicArn")

yield topic_arn

sns_extended_client.delete_topic(
TopicArn=topic_arn
)

@pytest.fixture()
def sns_extended_client_with_s3(sns_extended_client):

client_sns = sns_extended_client

client_sns.s3_client.create_bucket(
Bucket=client_sns.large_payload_support
)

yield client_sns

client_sns.s3_client.delete_bucket(
Bucket=client_sns.large_payload_support,
)
Loading