From 88ddca54c106a8a4185c8365adeea04cbf48fc08 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sat, 25 Apr 2020 23:13:05 +0200 Subject: [PATCH] return mailbox in GET /api/v2/aliases --- README.md | 11 +++++++++++ app/api/serializer.py | 5 +++++ tests/api/test_alias.py | 41 ++++++++++++++++++++++++----------------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index d0f13a5f..c0d2934f 100644 --- a/README.md +++ b/README.md @@ -852,6 +852,9 @@ If success, 200 with the list of aliases. Each alias has the following fields: - nb_block - nb_forward - nb_reply +- mailbox + - id + - email - (optional) latest_activity: - action: forward|reply|block|bounced - timestamp @@ -871,6 +874,10 @@ Here's an example: "email": "prefix1.cat@sl.local", "enabled": true, "id": 3, + "mailbox": { + "email": "a@b.c", + "id": 1 + }, "latest_activity": { "action": "forward", "contact": { @@ -891,6 +898,10 @@ Here's an example: "email": "prefix0.hey@sl.local", "enabled": true, "id": 2, + "mailbox": { + "email": "a@b.c", + "id": 1 + }, "latest_activity": { "action": "forward", "contact": { diff --git a/app/api/serializer.py b/app/api/serializer.py index f02c4dc8..104b8225 100644 --- a/app/api/serializer.py +++ b/app/api/serializer.py @@ -51,6 +51,11 @@ def serialize_alias_info_v2(alias_info: AliasInfo) -> dict: "nb_forward": alias_info.nb_forward, "nb_block": alias_info.nb_blocked, "nb_reply": alias_info.nb_reply, + # mailbox + "mailbox": { + "id": alias_info.mailbox.id, + "email": alias_info.mailbox.email + } } if alias_info.latest_email_log: email_log = alias_info.latest_email_log diff --git a/tests/api/test_alias.py b/tests/api/test_alias.py index 5ada525f..f8eab894 100644 --- a/tests/api/test_alias.py +++ b/tests/api/test_alias.py @@ -150,24 +150,28 @@ def test_get_aliases_v2(flask_client): r0 = r.json["aliases"][0] # r0 will have the following format # { - # "creation_date": "2020-04-06 17:52:47+00:00", - # "creation_timestamp": 1586195567, - # "email": "prefix1.hey@sl.local", - # "enabled": true, - # "id": 3, - # "latest_activity": { - # "action": "forward", - # "contact": { - # "email": "c1@example.com", - # "name": null, - # "reverse_alias": "\"c1 at example.com\" " + # "creation_date": "2020-04-25 21:10:01+00:00", + # "creation_timestamp": 1587849001, + # "email": "prefix1.yeah@sl.local", + # "enabled": true, + # "id": 3, + # "latest_activity": { + # "action": "forward", + # "contact": { + # "email": "c1@example.com", + # "name": null, + # "reverse_alias": "\"c1 at example.com\" " + # }, + # "timestamp": 1587849001 # }, - # "timestamp": 1586195567 - # }, - # "nb_block": 0, - # "nb_forward": 1, - # "nb_reply": 0, - # "note": null + # "mailbox": { + # "email": "a@b.c", + # "id": 1 + # }, + # "nb_block": 0, + # "nb_forward": 1, + # "nb_reply": 0, + # "note": null # } assert r0["email"].startswith("prefix1") assert r0["latest_activity"]["action"] == "forward" @@ -177,6 +181,9 @@ def test_get_aliases_v2(flask_client): assert "name" in r0["latest_activity"]["contact"] assert "reverse_alias" in r0["latest_activity"]["contact"] + assert "id" in r0["mailbox"] + assert "email" in r0["mailbox"] + def test_delete_alias(flask_client): user = User.create(