mailfixture 0.4.0__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mailfixture-0.4.0 → mailfixture-0.5.0}/PKG-INFO +1 -1
- {mailfixture-0.4.0 → mailfixture-0.5.0}/pyproject.toml +1 -1
- {mailfixture-0.4.0 → mailfixture-0.5.0}/src/mailfixture/__init__.py +56 -1
- {mailfixture-0.4.0 → mailfixture-0.5.0}/tests/test_client.py +22 -2
- {mailfixture-0.4.0 → mailfixture-0.5.0}/.gitignore +0 -0
- {mailfixture-0.4.0 → mailfixture-0.5.0}/LICENSE +0 -0
- {mailfixture-0.4.0 → mailfixture-0.5.0}/README.md +0 -0
- {mailfixture-0.4.0 → mailfixture-0.5.0}/src/mailfixture/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mailfixture
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Email fixtures for your test suite — programmatic inboxes, long-polling, first-class OTP and link extraction.
|
|
5
5
|
Project-URL: Homepage, https://mailfixture.com
|
|
6
6
|
Project-URL: Documentation, https://mailfixture.com/docs
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "mailfixture"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.5.0"
|
|
8
8
|
description = "Email fixtures for your test suite — programmatic inboxes, long-polling, first-class OTP and link extraction."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -46,6 +46,8 @@ __all__ = [
|
|
|
46
46
|
"SpfAuth",
|
|
47
47
|
"DkimAuth",
|
|
48
48
|
"DmarcAuth",
|
|
49
|
+
"Spam",
|
|
50
|
+
"SpamRule",
|
|
49
51
|
"FollowResult",
|
|
50
52
|
"Attachment",
|
|
51
53
|
"Domain",
|
|
@@ -60,7 +62,7 @@ __all__ = [
|
|
|
60
62
|
"MailFixtureTimeout",
|
|
61
63
|
]
|
|
62
64
|
|
|
63
|
-
__version__ = "0.
|
|
65
|
+
__version__ = "0.5.0"
|
|
64
66
|
|
|
65
67
|
DEFAULT_BASE_URL = "https://api.mailfixture.com"
|
|
66
68
|
#: Server-side ceiling for one long-poll request; the client chains
|
|
@@ -217,6 +219,45 @@ class Auth:
|
|
|
217
219
|
)
|
|
218
220
|
|
|
219
221
|
|
|
222
|
+
@dataclass
|
|
223
|
+
class SpamRule:
|
|
224
|
+
"""One SpamAssassin rule that fired, with its point contribution (which
|
|
225
|
+
may be negative) and description, when the daemon supplied one."""
|
|
226
|
+
|
|
227
|
+
name: str
|
|
228
|
+
score: float
|
|
229
|
+
description: Optional[str]
|
|
230
|
+
|
|
231
|
+
@classmethod
|
|
232
|
+
def _from_json(cls, data: Dict[str, Any]) -> "SpamRule":
|
|
233
|
+
return cls(
|
|
234
|
+
name=data.get("name", ""),
|
|
235
|
+
score=data.get("score", 0.0),
|
|
236
|
+
description=data.get("description"),
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
@dataclass
|
|
241
|
+
class Spam:
|
|
242
|
+
"""SpamAssassin content-analysis result for a message. `verdict` is
|
|
243
|
+
spamd's own decision ("spam" | "ham"), not a threshold recomputation.
|
|
244
|
+
Assert on `verdict` (or score < threshold), not an exact score."""
|
|
245
|
+
|
|
246
|
+
score: float
|
|
247
|
+
threshold: float
|
|
248
|
+
verdict: str
|
|
249
|
+
rules: List[SpamRule]
|
|
250
|
+
|
|
251
|
+
@classmethod
|
|
252
|
+
def _from_json(cls, data: Dict[str, Any]) -> "Spam":
|
|
253
|
+
return cls(
|
|
254
|
+
score=data.get("score", 0.0),
|
|
255
|
+
threshold=data.get("threshold", 0.0),
|
|
256
|
+
verdict=data.get("verdict", "ham"),
|
|
257
|
+
rules=[SpamRule._from_json(r) for r in data.get("rules") or []],
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
|
|
220
261
|
@dataclass
|
|
221
262
|
class FollowResult:
|
|
222
263
|
"""Outcome of a server-side link follow: the final response after
|
|
@@ -308,6 +349,14 @@ class Message:
|
|
|
308
349
|
raw = self.extracted.get("auth")
|
|
309
350
|
return Auth._from_json(raw) if isinstance(raw, dict) else None
|
|
310
351
|
|
|
352
|
+
@property
|
|
353
|
+
def spam(self) -> Optional[Spam]:
|
|
354
|
+
"""SpamAssassin score. None = not scored (scoring disabled, the
|
|
355
|
+
daemon was unreachable, or the message was over the size cap) —
|
|
356
|
+
never a clean pass."""
|
|
357
|
+
raw = self.extracted.get("spam")
|
|
358
|
+
return Spam._from_json(raw) if isinstance(raw, dict) else None
|
|
359
|
+
|
|
311
360
|
@classmethod
|
|
312
361
|
def _from_json(cls, data: Dict[str, Any]) -> "Message":
|
|
313
362
|
return cls(
|
|
@@ -650,15 +699,21 @@ class PhoneNumber:
|
|
|
650
699
|
#: active | pending — a pending number becomes active within ~a minute.
|
|
651
700
|
status: str
|
|
652
701
|
created_at: datetime
|
|
702
|
+
#: Scheduled auto-release: set when a plan downgrade left the account
|
|
703
|
+
#: over its number cap. Upgrading (or releasing other numbers) before
|
|
704
|
+
#: this date keeps the number. None = not scheduled.
|
|
705
|
+
release_after: Optional[datetime] = None
|
|
653
706
|
_client: "MailFixture" = field(repr=False, compare=False, default=None) # type: ignore[assignment]
|
|
654
707
|
|
|
655
708
|
@classmethod
|
|
656
709
|
def _from_json(cls, data: Dict[str, Any], client: "MailFixture") -> "PhoneNumber":
|
|
710
|
+
release_after = data.get("release_after")
|
|
657
711
|
return cls(
|
|
658
712
|
id=data["id"],
|
|
659
713
|
phone_number=data["phone_number"],
|
|
660
714
|
status=data["status"],
|
|
661
715
|
created_at=_parse_dt(data["created_at"]),
|
|
716
|
+
release_after=_parse_dt(release_after) if release_after else None,
|
|
662
717
|
_client=client,
|
|
663
718
|
)
|
|
664
719
|
|
|
@@ -56,6 +56,15 @@ MESSAGE_DETAIL = {
|
|
|
56
56
|
"dkim": [{"result": "pass", "domain": "acme.test", "selector": "s1"}],
|
|
57
57
|
"dmarc": {"result": "pass", "domain": "acme.test", "policy": "reject"},
|
|
58
58
|
},
|
|
59
|
+
"spam": {
|
|
60
|
+
"score": 6.1,
|
|
61
|
+
"threshold": 5.0,
|
|
62
|
+
"verdict": "spam",
|
|
63
|
+
"rules": [
|
|
64
|
+
{"name": "MISSING_HEADERS", "score": 1.2, "description": "Missing To: header"},
|
|
65
|
+
{"name": "NO_DESC", "score": -0.1, "description": None},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
59
68
|
},
|
|
60
69
|
"attachments": [
|
|
61
70
|
{"filename": "report.pdf", "content_type": "application/pdf", "size": 123, "inline": False}
|
|
@@ -209,7 +218,8 @@ class Stub(BaseHTTPRequestHandler):
|
|
|
209
218
|
else:
|
|
210
219
|
self._json(200, {"messages": [SMS_SUMMARY]})
|
|
211
220
|
elif parsed.path == "/v1/phone-numbers":
|
|
212
|
-
|
|
221
|
+
scheduled = dict(PHONE_NUMBER, release_after="2026-07-14T00:00:00Z")
|
|
222
|
+
self._json(200, {"phone_numbers": [scheduled]})
|
|
213
223
|
elif parsed.path == f"/v1/sms/{SMS_ID}":
|
|
214
224
|
self._json(200, SMS_DETAIL)
|
|
215
225
|
elif parsed.path == f"/v1/sms/{SMS_ID}/otp":
|
|
@@ -295,10 +305,16 @@ class ClientTest(unittest.TestCase):
|
|
|
295
305
|
self.assertEqual(message.auth.dkim[0].selector, "s1")
|
|
296
306
|
self.assertIsNone(message.auth.dkim[0].error)
|
|
297
307
|
self.assertEqual(message.auth.dmarc.policy, "reject")
|
|
298
|
-
|
|
308
|
+
self.assertEqual(message.spam.verdict, "spam")
|
|
309
|
+
self.assertEqual(message.spam.score, 6.1)
|
|
310
|
+
self.assertEqual(message.spam.rules[0].name, "MISSING_HEADERS")
|
|
311
|
+
self.assertEqual(message.spam.rules[0].description, "Missing To: header")
|
|
312
|
+
self.assertIsNone(message.spam.rules[1].description)
|
|
313
|
+
# Absent auth/spam keys (pre-feature message) read None, not a failure.
|
|
299
314
|
no_auth = dict(MESSAGE_DETAIL)
|
|
300
315
|
no_auth["extracted"] = {"otp": {"best": None, "candidates": []}, "links": []}
|
|
301
316
|
self.assertIsNone(Message._from_json(no_auth).auth)
|
|
317
|
+
self.assertIsNone(Message._from_json(no_auth).spam)
|
|
302
318
|
poll_path = next(p for m, p, _ in self.state["requests"] if "/messages?" in p)
|
|
303
319
|
self.assertIn("match=subject%3AAcme", poll_path)
|
|
304
320
|
self.assertIn("wait=5", poll_path)
|
|
@@ -371,6 +387,7 @@ class ClientTest(unittest.TestCase):
|
|
|
371
387
|
number = self.client.create_phone_number()
|
|
372
388
|
self.assertEqual(number.phone_number, "+15551234567")
|
|
373
389
|
self.assertEqual(number.status, "active")
|
|
390
|
+
self.assertIsNone(number.release_after) # absent key = not scheduled
|
|
374
391
|
self.assertEqual(self.state["auth_header"], "Bearer mfx_test")
|
|
375
392
|
method, path, _ = self.state["requests"][0]
|
|
376
393
|
self.assertEqual((method, path), ("POST", "/v1/phone-numbers"))
|
|
@@ -379,6 +396,9 @@ class ClientTest(unittest.TestCase):
|
|
|
379
396
|
numbers = self.client.list_phone_numbers()
|
|
380
397
|
self.assertEqual(len(numbers), 1)
|
|
381
398
|
self.assertEqual(numbers[0].phone_number, "+15551234567")
|
|
399
|
+
self.assertEqual(
|
|
400
|
+
numbers[0].release_after.isoformat(), "2026-07-14T00:00:00+00:00"
|
|
401
|
+
)
|
|
382
402
|
numbers[0].release()
|
|
383
403
|
method, path, _ = self.state["requests"][-1]
|
|
384
404
|
self.assertEqual((method, path), ("DELETE", f"/v1/phone-numbers/{PN_ID}"))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|