|
1 |
| -from request import sogs_get, sogs_post |
| 1 | +from request import sogs_get, sogs_post, sogs_delete |
2 | 2 | from sogs import config
|
3 | 3 | from sogs.hashing import blake2b
|
4 | 4 | from sogs.utils import encode_base64
|
5 | 5 | from sogs.model.user import SystemUser
|
6 | 6 | import nacl.bindings as sodium
|
7 | 7 | from nacl.utils import random
|
8 | 8 | from util import from_now
|
| 9 | +from itertools import product |
9 | 10 |
|
10 | 11 |
|
11 | 12 | def test_dm_default_empty(client, blind_user):
|
@@ -89,3 +90,42 @@ def test_dm_send(client, blind_user, blind_user2):
|
89 | 90 | assert data.pop('posted_at') == from_now.seconds(0)
|
90 | 91 | assert data.pop('expires_at') == from_now.seconds(config.DM_EXPIRY)
|
91 | 92 | assert data == msg_expected
|
| 93 | + |
| 94 | + |
| 95 | +def test_dm_delete(client, blind_user, blind_user2): |
| 96 | + num_posts = 10 |
| 97 | + for sender, recip in product((blind_user, blind_user2), repeat=2): |
| 98 | + # make DMs |
| 99 | + for n in range(num_posts): |
| 100 | + post = make_post(f"bep-{n}".encode('ascii'), sender=sender, to=recip) |
| 101 | + r = sogs_post(client, f'/inbox/{recip.session_id}', post, sender) |
| 102 | + assert r.status_code == 201 |
| 103 | + |
| 104 | + # get DMs |
| 105 | + r = sogs_get(client, "/inbox", recip) |
| 106 | + assert r.status_code == 200 |
| 107 | + posts = r.json |
| 108 | + assert isinstance(posts, list) |
| 109 | + assert len(posts) == num_posts |
| 110 | + |
| 111 | + # delete DMs |
| 112 | + r = sogs_delete(client, "/inbox", recip) |
| 113 | + assert r.status_code == 200 |
| 114 | + assert r.json == {'deleted': num_posts} |
| 115 | + |
| 116 | + # make sure it is empty |
| 117 | + r = sogs_get(client, "/inbox", recip) |
| 118 | + assert r.status_code == 200 |
| 119 | + posts = r.json |
| 120 | + assert posts == [] |
| 121 | + |
| 122 | + # delete again when nothing is there |
| 123 | + r = sogs_delete(client, "/inbox", recip) |
| 124 | + assert r.status_code == 200 |
| 125 | + assert r.json == {'deleted': 0} |
| 126 | + |
| 127 | + # make sure it is still empty (probably redundant but good to have) |
| 128 | + r = sogs_get(client, "/inbox", recip) |
| 129 | + assert r.status_code == 200 |
| 130 | + posts = r.json |
| 131 | + assert posts == [] |
0 commit comments