Skip to content

Commit 5bcac45

Browse files
committed
Start of an integration test harness
1 parent 9602fa4 commit 5bcac45

File tree

8 files changed

+61
-1
lines changed

8 files changed

+61
-1
lines changed

.github/workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: [3.10.15, 3.11.10, 3.12.6]
11+
python-version: [3.12.6]
1212
steps:
1313
- uses: actions/checkout@v4
1414
- name: Set up Python ${{ matrix.python-version }}
@@ -21,3 +21,5 @@ jobs:
2121
run: ./run-pylint.sh
2222
- name: Tests
2323
run: ./run-tests.sh
24+
- name: Integration Tests
25+
run: ./run-integration-tests.sh

attachment_downloader/version_info.py

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ class Version:
1313
"""
1414
Version information.
1515
"""
16+
17+
@staticmethod
18+
def commit_hash_short():
19+
"""
20+
Returns the short commit hash.
21+
"""
22+
with subprocess.Popen(["git", "rev-parse", "--short", "HEAD"],
23+
stdout=subprocess.PIPE,
24+
stderr=None) as process:
25+
return process.communicate()[0].decode('ascii').strip()
26+
1627
@staticmethod
1728
def generate():
1829
"""

requirements_tests.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests==2.32.3

run-integration-tests.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
./venv/bin/pytest -s tests_integration

setup.sh

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ python3 -m pip install --user virtualenv
44
python3 -m venv venv
55
./venv/bin/pip install --upgrade pip
66
./venv/bin/pip install -r requirements.txt
7+
./venv/bin/pip install -r requirements_tests.txt

tests_integration/__init__.py

Whitespace-only changes.

tests_integration/attachment_downloader/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import tempfile
3+
4+
import requests
5+
6+
from attachment_downloader.version_info import Version
7+
8+
9+
def send_email_with_attachment(api_key, domain, sender, recipient, subject, text, attachment_path):
10+
url = f"https://api.eu.mailgun.net/v3/{domain}/messages"
11+
12+
with open(attachment_path, 'rb') as attachment_file:
13+
response = requests.post(
14+
url,
15+
auth=("api", api_key),
16+
files=[("attachment", (attachment_path, attachment_file.read()))],
17+
data={
18+
"from": sender,
19+
"to": recipient,
20+
"subject": subject,
21+
"text": text,
22+
}
23+
)
24+
return response.status_code == 200
25+
26+
class TestSendAndDownloadAttachment:
27+
def test_send_and_download_attachment(self):
28+
mailgun_domain = os.getenv('MAILGUN_DOMAIN')
29+
mailgun_api_key = os.getenv('MAILGUN_API_KEY')
30+
recipient = os.getenv('AD_INT_TEST_RECIPIENT')
31+
version_info = Version.commit_hash_short()
32+
33+
with tempfile.NamedTemporaryFile(mode='w+t',prefix=version_info,suffix='.txt') as temp_attachment:
34+
temp_attachment.write(f"This is an example attachment from attachment-downloader {version_info}")
35+
temp_attachment.flush()
36+
37+
send_email_with_attachment(mailgun_api_key,
38+
mailgun_domain,
39+
f'attachment-downloader@{mailgun_domain}',
40+
recipient,
41+
f"Integration Test - {version_info}",
42+
'This email is part of an automated integration test.',
43+
temp_attachment.name)

0 commit comments

Comments
 (0)