Skip to content

Commit 8f2bf90

Browse files
committed
feat: Fixed integration tests
1 parent cf15f71 commit 8f2bf90

35 files changed

+1208
-480
lines changed

tests/conftest.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# tests/conftest.py
22
import os
33
import pytest
4+
import re
45
from vcr import VCR
56
from dotenv import load_dotenv
67

@@ -10,6 +11,62 @@
1011
# Get test API key from environment variables
1112
TEST_API_KEY = os.environ.get("MAILERSEND_API_KEY", "test-api-key")
1213

14+
15+
def sanitize_response_body(response):
16+
"""Sanitize response body to remove sensitive data like accessToken."""
17+
try:
18+
# Get the response body - handle different VCR formats
19+
body = None
20+
if response.get('body'):
21+
if isinstance(response['body'], dict):
22+
body = response['body'].get('string')
23+
else:
24+
body = response['body']
25+
26+
if not body:
27+
return response
28+
29+
# Convert bytes to string if needed
30+
if isinstance(body, bytes):
31+
body = body.decode('utf-8')
32+
33+
# Only process if it looks like JSON (contains accessToken)
34+
if 'accessToken' in body or 'mlsn.' in body:
35+
# Replace accessToken values
36+
body = re.sub(
37+
r'"accessToken":"mlsn\.[a-f0-9]+"',
38+
'"accessToken":"***FILTERED***"',
39+
body
40+
)
41+
42+
# Replace any other mlsn tokens
43+
body = re.sub(
44+
r'"mlsn\.[a-f0-9]{60,}"',
45+
'"***FILTERED***"',
46+
body
47+
)
48+
49+
# Replace preview tokens
50+
body = re.sub(
51+
r'"preview":"mlsn\.[a-f0-9]+"',
52+
'"preview":"***FILTERED***"',
53+
body
54+
)
55+
56+
# Update the response body (convert back to bytes for VCR)
57+
if isinstance(response['body'], dict):
58+
response['body']['string'] = body.encode('utf-8')
59+
else:
60+
response['body'] = body.encode('utf-8')
61+
62+
except Exception as e:
63+
print(f"[VCR FILTER] Error sanitizing response: {e}")
64+
# Don't fail tests if filtering fails
65+
pass
66+
67+
return response
68+
69+
1370
# Configure VCR globally
1471
vcr = VCR(
1572
cassette_library_dir="tests/fixtures/cassettes",
@@ -18,6 +75,7 @@
1875
filter_headers=["authorization"],
1976
filter_post_data_parameters=["api_key", "token", "accessToken"],
2077
serializer="yaml",
78+
before_record_response=sanitize_response_body,
2179
)
2280

2381
# Create a pytest fixture for the API key

tests/fixtures/cassettes/activity_get_basic.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ interactions:
1313
User-Agent:
1414
- mailersend-python/2.0.0 (Python/3.13.5; OS/Darwin 24.5.0; Impl/CPython)
1515
method: GET
16-
uri: https://api.mailersend.com/v1/activity/65qngkdovk8lwr12?page=1&limit=25&date_from=1753757734&date_to=1753844134
16+
uri: https://api.mailersend.com/v1/activity/65qngkdovk8lwr12?page=1&limit=25&date_from=1754040747&date_to=1754044347
1717
response:
1818
body:
19-
string: '{"message":"The date to must be a date before or equal to 2025-07-29
20-
14:56:42.","errors":{"date_to":["The date to must be a date before or equal
21-
to 2025-07-29 14:56:42."]}}'
19+
string: '{"data":[],"links":{"first":"https:\/\/api.mailersend.com\/v1\/activity\/65qngkdovk8lwr12?page=1","last":null,"prev":null,"next":null},"meta":{"current_page":1,"from":null,"path":"https:\/\/api.mailersend.com\/v1\/activity\/65qngkdovk8lwr12","per_page":25,"to":null}}'
2220
headers:
2321
CF-RAY:
24-
- 966d76e9fb0034c2-VIE
22+
- 9684abf1ba41076b-BEG
2523
Cache-Control:
2624
- no-cache, private
2725
Connection:
2826
- keep-alive
27+
Content-Encoding:
28+
- gzip
2929
Content-Type:
3030
- application/json
3131
Date:
32-
- Tue, 29 Jul 2025 14:56:42 GMT
32+
- Fri, 01 Aug 2025 10:32:27 GMT
3333
Server:
3434
- cloudflare
3535
Transfer-Encoding:
@@ -41,8 +41,8 @@ interactions:
4141
x-apiquota-remaining:
4242
- '-1'
4343
x-apiquota-reset:
44-
- '2025-07-30T00:00:00Z'
44+
- '2025-08-02T00:00:00Z'
4545
status:
46-
code: 422
47-
message: Unprocessable Entity
46+
code: 200
47+
message: OK
4848
version: 1

tests/fixtures/cassettes/identities_create_not_available.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,22 @@ interactions:
1717
User-Agent:
1818
- mailersend-python/2.0.0 (Python/3.13.5; OS/Darwin 24.5.0; Impl/CPython)
1919
method: POST
20-
uri: https://api.mailersend.com/identities
20+
uri: https://api.mailersend.com/v1/identities
2121
response:
2222
body:
23-
string: "{\n \"message\": \"The route identities could not be found.\"\n}"
23+
string: '{"message":"The email has already been taken.","errors":{"email":["The
24+
email has already been taken."]}}'
2425
headers:
2526
CF-RAY:
26-
- 966cbf526aa4d814-BEG
27+
- 9684c6c4badff339-BEG
2728
Cache-Control:
2829
- no-cache, private
2930
Connection:
3031
- keep-alive
31-
Content-Encoding:
32-
- gzip
3332
Content-Type:
3433
- application/json
3534
Date:
36-
- Tue, 29 Jul 2025 12:51:22 GMT
35+
- Fri, 01 Aug 2025 10:50:46 GMT
3736
Server:
3837
- cloudflare
3938
Transfer-Encoding:
@@ -42,7 +41,11 @@ interactions:
4241
- DYNAMIC
4342
strict-transport-security:
4443
- max-age=31536000; includeSubDomains
44+
x-apiquota-remaining:
45+
- '-1'
46+
x-apiquota-reset:
47+
- '2025-08-02T00:00:00Z'
4548
status:
46-
code: 404
47-
message: Not Found
49+
code: 422
50+
message: Unprocessable Entity
4851
version: 1

tests/fixtures/cassettes/identities_create_success.yaml

Lines changed: 0 additions & 48 deletions
This file was deleted.

tests/fixtures/cassettes/identities_delete_by_email.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ interactions:
1515
User-Agent:
1616
- mailersend-python/2.0.0 (Python/3.13.5; OS/Darwin 24.5.0; Impl/CPython)
1717
method: DELETE
18-
uri: https://api.mailersend.com/identities/email/test@example.com
18+
uri: https://api.mailersend.com/v1/identities/email/test@example.com
1919
response:
2020
body:
21-
string: "{\n \"message\": \"The route identities/email/test@example.com could
22-
not be found.\"\n}"
21+
string: "{\n \"message\": \"Resource not found.\"\n}"
2322
headers:
2423
CF-RAY:
25-
- 966cc0bc7a075165-BEG
24+
- 9684c6ccfcd5bbed-BEG
2625
Cache-Control:
2726
- no-cache, private
2827
Connection:
@@ -32,7 +31,7 @@ interactions:
3231
Content-Type:
3332
- application/json
3433
Date:
35-
- Tue, 29 Jul 2025 12:52:20 GMT
34+
- Fri, 01 Aug 2025 10:50:47 GMT
3635
Server:
3736
- cloudflare
3837
Transfer-Encoding:
@@ -41,6 +40,10 @@ interactions:
4140
- DYNAMIC
4241
strict-transport-security:
4342
- max-age=31536000; includeSubDomains
43+
x-apiquota-remaining:
44+
- '-1'
45+
x-apiquota-reset:
46+
- '2025-08-02T00:00:00Z'
4447
status:
4548
code: 404
4649
message: Not Found

tests/fixtures/cassettes/identities_delete_by_id.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ interactions:
1515
User-Agent:
1616
- mailersend-python/2.0.0 (Python/3.13.5; OS/Darwin 24.5.0; Impl/CPython)
1717
method: DELETE
18-
uri: https://api.mailersend.com/identities/test-identity-id
18+
uri: https://api.mailersend.com/v1/identities/test-identity-id
1919
response:
2020
body:
21-
string: "{\n \"message\": \"The route identities/test-identity-id could not
22-
be found.\"\n}"
21+
string: "{\n \"message\": \"Resource not found.\"\n}"
2322
headers:
2423
CF-RAY:
25-
- 966cb3faebf2e294-BEG
24+
- 9684c6cc0ca3076b-BEG
2625
Cache-Control:
2726
- no-cache, private
2827
Connection:
@@ -32,7 +31,7 @@ interactions:
3231
Content-Type:
3332
- application/json
3433
Date:
35-
- Tue, 29 Jul 2025 12:43:38 GMT
34+
- Fri, 01 Aug 2025 10:50:47 GMT
3635
Server:
3736
- cloudflare
3837
Transfer-Encoding:

tests/fixtures/cassettes/identities_get_by_email.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ interactions:
1313
User-Agent:
1414
- mailersend-python/2.0.0 (Python/3.13.5; OS/Darwin 24.5.0; Impl/CPython)
1515
method: GET
16-
uri: https://api.mailersend.com/identities/email/test@example.com
16+
uri: https://api.mailersend.com/v1/identities/email/test@example.com
1717
response:
1818
body:
19-
string: "{\n \"message\": \"The route identities/email/test@example.com could
20-
not be found.\"\n}"
19+
string: "{\n \"message\": \"Resource not found.\"\n}"
2120
headers:
2221
CF-RAY:
23-
- 966cc0b82bc2e297-BEG
22+
- 9684c6c85d461f09-BEG
2423
Cache-Control:
2524
- no-cache, private
2625
Connection:
@@ -30,7 +29,7 @@ interactions:
3029
Content-Type:
3130
- application/json
3231
Date:
33-
- Tue, 29 Jul 2025 12:52:20 GMT
32+
- Fri, 01 Aug 2025 10:50:46 GMT
3433
Server:
3534
- cloudflare
3635
Transfer-Encoding:
@@ -39,6 +38,10 @@ interactions:
3938
- DYNAMIC
4039
strict-transport-security:
4140
- max-age=31536000; includeSubDomains
41+
x-apiquota-remaining:
42+
- '-1'
43+
x-apiquota-reset:
44+
- '2025-08-02T00:00:00Z'
4245
status:
4346
code: 404
4447
message: Not Found

tests/fixtures/cassettes/identities_get_single.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ interactions:
1313
User-Agent:
1414
- mailersend-python/2.0.0 (Python/3.13.5; OS/Darwin 24.5.0; Impl/CPython)
1515
method: GET
16-
uri: https://api.mailersend.com/identities/test-identity-id
16+
uri: https://api.mailersend.com/v1/identities/test-identity-id
1717
response:
1818
body:
19-
string: "{\n \"message\": \"The route identities/test-identity-id could not
20-
be found.\"\n}"
19+
string: "{\n \"message\": \"Resource not found.\"\n}"
2120
headers:
2221
CF-RAY:
23-
- 966cb3f3fe3de296-BEG
22+
- 9684c6c70b1ce296-BEG
2423
Cache-Control:
2524
- no-cache, private
2625
Connection:
@@ -30,7 +29,7 @@ interactions:
3029
Content-Type:
3130
- application/json
3231
Date:
33-
- Tue, 29 Jul 2025 12:43:37 GMT
32+
- Fri, 01 Aug 2025 10:50:46 GMT
3433
Server:
3534
- cloudflare
3635
Transfer-Encoding:

tests/fixtures/cassettes/identities_update_by_email.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ interactions:
1515
User-Agent:
1616
- mailersend-python/2.0.0 (Python/3.13.5; OS/Darwin 24.5.0; Impl/CPython)
1717
method: PUT
18-
uri: https://api.mailersend.com/identities/email/test@example.com
18+
uri: https://api.mailersend.com/v1/identities/email/test@example.com
1919
response:
2020
body:
21-
string: "{\n \"message\": \"The route identities/email/test@example.com could
22-
not be found.\"\n}"
21+
string: "{\n \"message\": \"Resource not found.\"\n}"
2322
headers:
2423
CF-RAY:
25-
- 966cc0ba7b1fe290-BEG
24+
- 9684c6cb0b621b8b-BEG
2625
Cache-Control:
2726
- no-cache, private
2827
Connection:
@@ -32,7 +31,7 @@ interactions:
3231
Content-Type:
3332
- application/json
3433
Date:
35-
- Tue, 29 Jul 2025 12:52:20 GMT
34+
- Fri, 01 Aug 2025 10:50:47 GMT
3635
Server:
3736
- cloudflare
3837
Transfer-Encoding:
@@ -41,6 +40,10 @@ interactions:
4140
- DYNAMIC
4241
strict-transport-security:
4342
- max-age=31536000; includeSubDomains
43+
x-apiquota-remaining:
44+
- '-1'
45+
x-apiquota-reset:
46+
- '2025-08-02T00:00:00Z'
4447
status:
4548
code: 404
4649
message: Not Found

0 commit comments

Comments
 (0)