@@ -1084,6 +1084,9 @@ def test_owned_files(client, room, user, admin):
1084
1084
# - verify that the file expiry is 15 days from now (±1s)
1085
1085
f1 = File (id = f1 .id )
1086
1086
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
+
1087
1090
# - upload another file
1088
1091
filedata , headers = _make_file_upload ('fug-2.jpeg' )
1089
1092
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):
1100
1103
# - verify the new file exp is ~15 days
1101
1104
f2 = File (id = f2 .id )
1102
1105
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
1103
1108
# - verify that the old file exp hasn't changed
1104
1109
f1 = File (id = f1 .id )
1105
1110
assert f1 .expiry == from_now .days (15 )
@@ -1117,17 +1122,55 @@ def test_owned_files(client, room, user, admin):
1117
1122
assert (f1 .expiry , f2 .expiry ) == (from_now .days (15 ), from_now .days (15 ))
1118
1123
1119
1124
# - 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
+
1120
1131
# - 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
1121
1134
1122
1135
# - 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
+
1123
1143
# - 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
+
1125
1152
# - 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
1126
1156
1127
1157
# - delete the first post
1158
+ r = sogs_delete (client , f'/room/{ room .token } /message/{ post_id } ' , user )
1159
+ assert r .status_code == 200
1160
+
1128
1161
# - 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 )
1129
1169
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 )
1131
1174
1132
1175
1133
1176
def _make_dummy_post (room , user ):
0 commit comments