Skip to content

Commit 52e66b5

Browse files
authored
Add integration test (#23)
* Add integration test * Clean up the test_session for integration tests * Add integration tests to Release workflow and Unit tests to PullRequest workflow * Bump up the version to 1.0.1
1 parent dcf21b4 commit 52e66b5

File tree

10 files changed

+663
-6
lines changed

10 files changed

+663
-6
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: PullRequest
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
id-token: write
14+
steps:
15+
- name: Check out the repository
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 2
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: "3.9"
23+
- name: Install Poetry
24+
run: |
25+
pip install poetry
26+
poetry --version
27+
- name: Build package
28+
run: |
29+
poetry build
30+
- name: Install package
31+
run: |
32+
poetry install
33+
- name: Run pytest
34+
run: |
35+
poetry run pytest --cov=sns_extended_client test --cov-report term-missing

.github/workflows/release.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Detect and tag new version
3535
id: check-version
3636
if: steps.check-parent-commit.outputs.sha
37-
uses: salsify/action-detect-and-tag-new-version@b1778166f13188a9d478e2d1198f993011ba9864 # v2.0.3
37+
uses: salsify/action-detect-and-tag-new-version@v2
3838
with:
3939
version-command: |
4040
bash -o pipefail -c "poetry version | awk '{ print \$2 }'"
@@ -54,11 +54,14 @@ jobs:
5454
run: |
5555
poetry run pytest --cov=sns_extended_client test --cov-report term-missing
5656
- name: configure aws credentials
57-
uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0
57+
uses: aws-actions/configure-aws-credentials@v4
5858
with:
5959
role-to-assume: ${{ vars.OIDC_ROLE_NAME }}
6060
role-session-name: publishrolesession
6161
aws-region: ${{ env.AWS_REGION }}
62+
- name: Run Integration Tests
63+
run: |
64+
poetry run pytest test_integ
6265
- name: Retrieve TEST PYPI TOKEN from secretsmanager
6366
id: get-test-pypi-token
6467
if: "! steps.check-version.outputs.tag"
@@ -71,14 +74,14 @@ jobs:
7174
echo "token=$(aws secretsmanager get-secret-value --secret-id ${{ vars.PYPI_TOKEN_NAME }} | jq -r '.SecretString')" >> $GITHUB_OUTPUT
7275
- name: Publish package on TestPyPI
7376
if: "! steps.check-version.outputs.tag"
74-
uses: pypa/gh-action-pypi-publish@f8c70e705ffc13c3b4d1221169b84f12a75d6ca8 # release/v1
77+
uses: pypa/gh-action-pypi-publish@release/v1
7578
with:
7679
user: __token__
7780
password: ${{ steps.get-test-pypi-token.outputs.token }}
78-
repository_url: https://test.pypi.org/legacy/
81+
repository-url: https://test.pypi.org/legacy/
7982
- name: Publish package on PyPI
8083
if: steps.check-version.outputs.tag
81-
uses: pypa/gh-action-pypi-publish@f8c70e705ffc13c3b4d1221169b84f12a75d6ca8 # release/v1
84+
uses: pypa/gh-action-pypi-publish@release/v1
8285
with:
8386
user: __token__
8487
password: ${{ steps.get-pypi-token.outputs.token }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.vscode
2+
.coverage
23
.pytest_cache
34
__pycache__
45
*.DS_Store

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "amazon-sns-extended-client"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
description = "Python version of AWS SNS extended client to publish large payload message"
55
authors = ["Amazon Web Service - SNS"]
66
license = "Apache-2.0"

test_integ/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import logging
2+
3+
logging.basicConfig(level=logging.INFO)
4+
logger = logging.getLogger("Integration Test Logger")

test_integ/fixtures/__init__.py

Whitespace-only changes.

test_integ/fixtures/objects.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import boto3
2+
import pytest
3+
import uuid
4+
5+
@pytest.fixture
6+
def default_message_size_threshold():
7+
return 262144
8+
9+
@pytest.fixture
10+
def small_message_body():
11+
return "small message body"
12+
13+
14+
@pytest.fixture
15+
def small_message_attribute(small_message_body):
16+
return {
17+
'Small_Message_Attribute': {
18+
'StringValue': small_message_body,
19+
'DataType': 'String'
20+
}
21+
}
22+
23+
@pytest.fixture
24+
def custom_s3_key_attribute():
25+
return {
26+
'S3Key': {
27+
'StringValue': str(uuid.uuid4()),
28+
'DataType': 'String'
29+
}
30+
}
31+
32+
33+
@pytest.fixture
34+
def large_message_body(small_message_body, default_message_size_threshold):
35+
return "x" * ( default_message_size_threshold + 1 )
36+
37+
@pytest.fixture
38+
def large_message_attribute(large_message_body):
39+
return {
40+
'Large_Message_Attribute': {
41+
'StringValue': 'Test',
42+
'DataType': 'String'
43+
}
44+
}

test_integ/fixtures/session.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import boto3
2+
import pytest
3+
from sns_extended_client.session import SNSExtendedClientSession
4+
5+
@pytest.fixture()
6+
def region_name() -> str:
7+
region_name = 'us-east-1'
8+
return region_name
9+
10+
@pytest.fixture()
11+
def session(region_name) -> boto3.Session:
12+
13+
setattr(boto3.session, "Session", SNSExtendedClientSession)
14+
# Now take care of the reference in the boto3.__init__ module since the object is being imported there too
15+
setattr(boto3, "Session", SNSExtendedClientSession)
16+
17+
# return boto3.session.Session()
18+
print("This session is fetched")
19+
return boto3.Session(region_name=region_name)

test_integ/fixtures/sns.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import boto3
2+
from sns_extended_client import SNSExtendedClientSession
3+
import pytest
4+
import random
5+
6+
@pytest.fixture()
7+
def sns_extended_client(session):
8+
sns_client = session.client("sns",region_name='us-east-1')
9+
sns_client.large_payload_support = f'integration-test-bucket-{random.randint(0, 10000)}'
10+
return sns_client
11+
12+
@pytest.fixture()
13+
def sqs_client(session):
14+
return session.client("sqs")
15+
16+
@pytest.fixture()
17+
def queue_name():
18+
return f"IntegrationTestQueue{random.randint(0,10000)}"
19+
20+
@pytest.fixture()
21+
def topic_name():
22+
return f"IntegrationTestTopic{random.randint(0,10000)}"
23+
24+
@pytest.fixture()
25+
def queue(sqs_client, queue_name):
26+
queue_object = sqs_client.create_queue(QueueName=queue_name)
27+
28+
yield queue_object
29+
30+
sqs_client.purge_queue(
31+
QueueUrl=queue_object['QueueUrl']
32+
)
33+
34+
sqs_client.delete_queue(
35+
QueueUrl=queue_object['QueueUrl']
36+
)
37+
38+
@pytest.fixture()
39+
def topic(sns_extended_client, topic_name):
40+
topic_arn = sns_extended_client.create_topic(Name=topic_name).get("TopicArn")
41+
42+
yield topic_arn
43+
44+
sns_extended_client.delete_topic(
45+
TopicArn=topic_arn
46+
)
47+
48+
@pytest.fixture()
49+
def sns_extended_client_with_s3(sns_extended_client):
50+
51+
client_sns = sns_extended_client
52+
53+
client_sns.s3_client.create_bucket(
54+
Bucket=client_sns.large_payload_support
55+
)
56+
57+
yield client_sns
58+
59+
client_sns.s3_client.delete_bucket(
60+
Bucket=client_sns.large_payload_support,
61+
)

0 commit comments

Comments
 (0)