Skip to content

Commit

Permalink
Start of an integration test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesridgway committed Sep 28, 2024
1 parent 9602fa4 commit 24d532a
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.10.15, 3.11.10, 3.12.6]
python-version: [3.12.6]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -21,3 +21,9 @@ jobs:
run: ./run-pylint.sh
- name: Tests
run: ./run-tests.sh
- name: Integration Tests
env:
MAILGUN_DOMAIN: ${{ secrets.MAILGUN_DOMAIN }}
MAILGUN_API_KEY: ${{ secrets.MAILGUN_API_KEY }}
AD_INT_TEST_RECIPIENT: ${{ secrets.AD_INT_TEST_RECIPIENT }}
run: ./run-integration-tests.sh
11 changes: 11 additions & 0 deletions attachment_downloader/version_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ class Version:
"""
Version information.
"""

@staticmethod
def commit_hash_short():
"""
Returns the short commit hash.
"""
with subprocess.Popen(["git", "rev-parse", "--short", "HEAD"],
stdout=subprocess.PIPE,
stderr=None) as process:
return process.communicate()[0].decode('ascii').strip()

@staticmethod
def generate():
"""
Expand Down
1 change: 1 addition & 0 deletions requirements_tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.32.3
2 changes: 2 additions & 0 deletions run-integration-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
./venv/bin/pytest -s tests_integration
1 change: 1 addition & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ python3 -m pip install --user virtualenv
python3 -m venv venv
./venv/bin/pip install --upgrade pip
./venv/bin/pip install -r requirements.txt
./venv/bin/pip install -r requirements_tests.txt
Empty file added tests_integration/__init__.py
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import tempfile

import requests

from attachment_downloader.version_info import Version


def send_email_with_attachment(api_key, domain, sender, recipient, subject, text, attachment_path):
url = f"https://api.eu.mailgun.net/v3/{domain}/messages"

with open(attachment_path, 'rb') as attachment_file:
response = requests.post(
url,
auth=("api", api_key),
files=[("attachment", (attachment_path, attachment_file.read()))],
data={
"from": sender,
"to": recipient,
"subject": subject,
"text": text,
}
)
return response.status_code == 200

class TestSendAndDownloadAttachment:
def test_send_and_download_attachment(self):
mailgun_domain = os.getenv('MAILGUN_DOMAIN')
mailgun_api_key = os.getenv('MAILGUN_API_KEY')
recipient = os.getenv('AD_INT_TEST_RECIPIENT')
version_info = Version.commit_hash_short()

with tempfile.NamedTemporaryFile(mode='w+t',prefix=version_info,suffix='.txt') as temp_attachment:
temp_attachment.write(f"This is an example attachment from attachment-downloader {version_info}")
temp_attachment.flush()

send_email_with_attachment(mailgun_api_key,
mailgun_domain,
f'attachment-downloader@{mailgun_domain}',
recipient,
f"Integration Test - {version_info}",
'This email is part of an automated integration test.',
temp_attachment.name)

0 comments on commit 24d532a

Please sign in to comment.