Skip to content

Commit 8008f3c

Browse files
committed
Finish off test_owned_files test case implementations
1 parent dc4a2f0 commit 8008f3c

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

tests/test_room_routes.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,9 @@ def test_owned_files(client, room, user, admin):
10841084
# - verify that the file expiry is 15 days from now (±1s)
10851085
f1 = File(id=f1.id)
10861086
assert f1.expiry == from_now.days(15)
1087+
# - verify that the file is correctly associated with the post
1088+
assert f1.post_id == post_id
1089+
10871090
# - upload another file
10881091
filedata, headers = _make_file_upload('fug-2.jpeg')
10891092
r = sogs_post_raw(client, f'/room/{room.token}/file', filedata, user, extra_headers=headers)
@@ -1100,6 +1103,8 @@ def test_owned_files(client, room, user, admin):
11001103
# - verify the new file exp is ~15 days
11011104
f2 = File(id=f2.id)
11021105
assert f2.expiry == from_now.days(15)
1106+
# - verify that the second file is correctly associated with the post
1107+
assert f2.post_id == post_id
11031108
# - verify that the old file exp hasn't changed
11041109
f1 = File(id=f1.id)
11051110
assert f1.expiry == from_now.days(15)
@@ -1117,17 +1122,55 @@ def test_owned_files(client, room, user, admin):
11171122
assert (f1.expiry, f2.expiry) == (from_now.days(15), from_now.days(15))
11181123

11191124
# - make another post that references one of the first post's file
1125+
filedata, headers = _make_file_upload('another.png')
1126+
r = sogs_post_raw(client, f'/room/{room.token}/file', filedata, user, extra_headers=headers)
1127+
assert r.status_code == 201
1128+
d, s = (utils.encode_base64(x) for x in (b"more post data", pad64("fsdf")))
1129+
post_info = {'data': d, 'signature': s, 'files': [f1.id, r.json['id']]}
1130+
11201131
# - make sure the first post associated message hasn't changed (i.e. no stealing owned uploads)
1132+
f1a = File(id=f1.id)
1133+
assert f1a.expiry == f1.expiry and f1a.post_id == post_id
11211134

11221135
# - upload a file and set it as the room image
1136+
filedata, headers = _make_file_upload('room-image.png')
1137+
r = sogs_post_raw(client, f'/room/{room.token}/file', filedata, user, extra_headers=headers)
1138+
room_img = r.json['id']
1139+
assert r.status_code == 201
1140+
r = sogs_put(client, f'/room/{room.token}', {'image': room_img}, admin)
1141+
assert r.status_code == 200
1142+
11231143
# - verify that the uploaded file expiry and message are both NULL
1124-
# - make a post referencing the pinned ID
1144+
f_room = File(id=room_img)
1145+
assert f_room.post_id is None
1146+
assert f_room.expiry is None
1147+
1148+
# - make a post referencing the room image ID
1149+
d, s = (utils.encode_base64(x) for x in (b"post xyz", pad64("z")))
1150+
post_info = {'data': d, 'signature': s, 'files': [room_img]}
1151+
11251152
# - verify that the pinned image expiry and message are still both NULL
1153+
f_room = File(id=f_room.id)
1154+
assert f_room.post_id is None
1155+
assert f_room.expiry is None
11261156

11271157
# - delete the first post
1158+
r = sogs_delete(client, f'/room/{room.token}/message/{post_id}', user)
1159+
assert r.status_code == 200
1160+
11281161
# - verify that both attachments are now expired
1162+
f1 = File(id=f1.id)
1163+
f2 = File(id=f2.id)
1164+
assert (f1.expiry, f2.expiry) == (0.0, 0.0)
1165+
1166+
from sogs.cleanup import cleanup
1167+
1168+
assert cleanup() == (2, 0, 0, 0, 0)
11291169

1130-
pass
1170+
with pytest.raises(sogs.model.exc.NoSuchFile):
1171+
f1 = File(id=f1.id)
1172+
with pytest.raises(sogs.model.exc.NoSuchFile):
1173+
f2 = File(id=f2.id)
11311174

11321175

11331176
def _make_dummy_post(room, user):

0 commit comments

Comments
 (0)