Skip to content

Commit d962b3b

Browse files
committed
test(all): old utility endpoint now tested
1 parent 46f58df commit d962b3b

File tree

5 files changed

+41
-48
lines changed

5 files changed

+41
-48
lines changed

QA/py/tests/test_admin.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from tests.test_import import do_import_uvp6
1111

1212
PROJECT_DIGEST_URL = "/admin/images/{project_id}/digest?max_digests=100"
13-
DIGEST_URL = "/admin/images/digest"
1413
NIGHTLY_URL = "/admin/nightly"
1514

1615

@@ -36,10 +35,6 @@ def test_admin_images(fastapi):
3635
assert rsp.status_code == status.HTTP_200_OK
3736
assert rsp.json() == "Digest for 0 images done."
3837

39-
rsp = fastapi.get(DIGEST_URL, headers=ADMIN_AUTH)
40-
assert rsp.status_code == status.HTTP_200_OK
41-
assert rsp.json() == "Digest for 0 images done."
42-
4338

4439
def do_nightly(fastapi):
4540
rsp = fastapi.get(NIGHTLY_URL, headers=ADMIN_AUTH)

QA/py/tests/test_admin_images.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from starlette import status
2+
3+
from tests.credentials import ADMIN_AUTH, USER_AUTH
4+
from tests.test_admin import PROJECT_DIGEST_URL
5+
from tests.test_import import do_import_uvp6
6+
7+
CLEANUP_URL = "/admin/images/cleanup1?project_id={project_id}"
8+
9+
10+
def test_admin_images_cleanup(fastapi):
11+
# Prepare a project with some images
12+
prj_id = do_import_uvp6(fastapi, "Test Project Admin Images Cleanup1")
13+
14+
url = PROJECT_DIGEST_URL.format(project_id=prj_id)
15+
rsp = fastapi.get(url, headers=ADMIN_AUTH)
16+
assert rsp.status_code == status.HTTP_200_OK
17+
assert isinstance(rsp.json(), str)
18+
assert "Digest for" in rsp.json()
19+
20+
url = CLEANUP_URL.format(project_id=prj_id)
21+
22+
# Simple user cannot access the admin cleanup endpoint
23+
rsp = fastapi.get(url, headers=USER_AUTH)
24+
assert rsp.status_code == status.HTTP_403_FORBIDDEN
25+
26+
# Admin can
27+
rsp = fastapi.get(url, headers=ADMIN_AUTH)
28+
assert rsp.status_code == status.HTTP_200_OK
29+
assert isinstance(rsp.json(), str)
30+
assert rsp.json().startswith("Dupl remover for")

QA/py/tests/test_collections.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ def test_collection_lifecycle(fastapi, who):
177177

178178
# update the project_ids
179179
url = COLLECTION_UPDATE_URL.format(collection_id=coll_id)
180-
the_coll = {"project_ids": [6, prj_id]}
180+
the_coll = {"project_ids": [-1, prj_id]}
181181
rsp = fastapi.patch(url, headers=who, json=the_coll)
182-
assert rsp.status_code == status.HTTP_200_OK
182+
assert rsp.status_code == status.HTTP_404_NOT_FOUND
183183
# reset to previous for compatibility with other tests
184184
url = COLLECTION_UPDATE_URL.format(collection_id=coll_id)
185185
the_coll = {"project_ids": [prj_id]}
@@ -202,7 +202,7 @@ def test_collection_lifecycle(fastapi, who):
202202
assert rsp.status_code == status.HTTP_200_OK
203203
assert rsp.json() == []
204204

205-
# Delete the collection
205+
# Delete the collection. Note: It will cascade errors if a problem prevents it
206206
url = COLLECTION_DELETE_URL.format(collection_id=coll_id)
207207
rsp = fastapi.delete(url, headers=who)
208208
if who == CREATOR_AUTH:

py/API_operations/admin/ImageManager.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ def _md5_on_record(self, img_file: ImageFile, imgid: int, orig_file_name: str):
127127
logger.exception(e)
128128
img_file.state = ImageFileStateEnum.ERROR.value
129129

130-
def do_cleanup_dup_same_obj( # TODO: Not working and not tested anyway
130+
def do_cleanup_dup_same_obj(
131131
self, current_user_id: UserIDT, prj_id: ProjectIDT, max_deletes: int
132-
) -> str:
132+
) -> str: #
133133
"""
134134
Simplest duplication pattern. Inside the same object there are several identical images.
135135
"""
@@ -139,7 +139,7 @@ def do_cleanup_dup_same_obj( # TODO: Not working and not tested anyway
139139
orig_img = aliased(Image, name="orig")
140140
orig_file = aliased(ImageFile, name="orig_file")
141141
qry = self.session.query(
142-
orig_img.file_name, orig_img.imgid, Image, ImageFile
142+
orig_img.orig_file_name, orig_img.imgid, Image, ImageFile
143143
) # Select what to delete
144144
qry = (
145145
qry.join(ObjectHeader, ObjectHeader.objid == Image.objid)
@@ -166,13 +166,6 @@ def do_cleanup_dup_same_obj( # TODO: Not working and not tested anyway
166166
ImageFile.state == ImageFileStateEnum.OK.value,
167167
),
168168
)
169-
qry = qry.join(
170-
orig_file,
171-
and_(
172-
orig_file.path == orig_img.file_name,
173-
orig_file.state == ImageFileStateEnum.OK.value,
174-
),
175-
)
176169
# and the same value of course
177170
qry = qry.filter(
178171
and_(
@@ -202,7 +195,10 @@ def do_cleanup_dup_same_obj( # TODO: Not working and not tested anyway
202195
continue
203196
# Even if MD5s match, be paranoid and compare files
204197
orig_path = self.vault.image_path(orig_file_name)
205-
dup_path = self.vault.image_path(an_image.file_name)
198+
img_file_name = Image.img_from_id_and_orig(
199+
an_image.imgid, an_image.orig_file_name
200+
)
201+
dup_path = self.vault.image_path(img_file_name)
206202
assert orig_path != dup_path
207203
orig_exists = exists(orig_path)
208204
dup_exists = exists(dup_path)
@@ -232,7 +228,7 @@ def do_cleanup_dup_same_obj( # TODO: Not working and not tested anyway
232228
# Do the cleanup
233229
deleted_imgids.add(an_image.imgid)
234230
if dup_exists:
235-
remover.add_files([an_image.file_name])
231+
remover.add_files([img_file_name])
236232
self.session.delete(an_image)
237233
self.session.delete(an_image_file)
238234
# Wait for the files handled

py/main.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@
159159
from DB.Project import ProjectTaxoStat, Project
160160
from DB.ProjectPrivilege import ProjectPrivilege
161161
from DB.User import User, OrganizationIDT
162-
from helpers.Asyncio import async_bg_run, log_streamer
163162
from helpers.DynamicLogs import get_logger, get_api_logger, MONITOR_LOG_PATH
164163
from helpers.fastApiUtils import (
165164
internal_server_error_handler,
@@ -3490,33 +3489,6 @@ def digest_project_images(
34903489
return ret
34913490

34923491

3493-
@app.get(
3494-
"/admin/images/digest",
3495-
operation_id="digest_images",
3496-
tags=["WIP"],
3497-
include_in_schema=False,
3498-
response_model=str,
3499-
) # TODO: Looks like a duplicate of above
3500-
def digest_images(
3501-
max_digests: Optional[int] = Query(
3502-
default=100000, description="Number of images to scan."
3503-
),
3504-
project_id: Optional[int] = Query(
3505-
default=None, description="Internal, numeric id of the project."
3506-
),
3507-
current_user: int = Depends(get_current_user),
3508-
) -> str:
3509-
"""
3510-
Compute digests if they are not.
3511-
"""
3512-
with ImageManagerService() as sce:
3513-
with RightsThrower():
3514-
ret: str = sce.do_digests(
3515-
current_user, prj_id=project_id, max_digests=max_digests
3516-
)
3517-
return ret
3518-
3519-
35203492
@app.get(
35213493
"/admin/images/cleanup1",
35223494
operation_id="cleanup_images_1",

0 commit comments

Comments
 (0)