Skip to content

Commit

Permalink
Add an environment variable to disable ZIM filename check in zimit of…
Browse files Browse the repository at this point in the history
…fliner
  • Loading branch information
benoit74 committed Nov 9, 2023
1 parent 2a86d30 commit 1239c8a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
3 changes: 3 additions & 0 deletions dispatcher/backend/src/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,6 @@
REQ_TIMEOUT_NOTIFICATIONS = int(os.getenv("REQ_TIMEOUT_NOTIFICATIONS", 5))
REQ_TIMEOUT_CMS = int(os.getenv("REQ_TIMEOUT_CMS", 10))
REQ_TIMEOUT_GHCR = int(os.getenv("REQ_TIMEOUT_GHCR", 10))

# OFFLINERS
ZIMIT_DISABLE_ZIM_FILENAME_CHECK = os.getenv("ZIMIT_DISABLE_ZIM_FILENAME_CHECK", "")
6 changes: 5 additions & 1 deletion dispatcher/backend/src/common/schemas/offliners/zimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
validate_zim_filename,
)

from common.constants import ZIMIT_DISABLE_ZIM_FILENAME_CHECK

# https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts
# https://github.com/puppeteer/puppeteer/blob/
# main/packages/puppeteer-core/src/common/Device.ts
Expand Down Expand Up @@ -190,7 +192,9 @@ class Meta:
"Make sure to end with _{period}.zim",
},
data_key="zim-file",
validate=validate_zim_filename,
validate=validate_zim_filename
if not ZIMIT_DISABLE_ZIM_FILENAME_CHECK
else None,
)

tags = String(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
class TestZimit:
def test_create_zimit_schedule_ok(self, client, access_token, garbage_collector):
schedule = {
"name": "zimit_test_ok",
"category": "other",
"enabled": False,
"tags": [],
"language": {"code": "fr", "name_en": "French", "name_native": "Français"},
"config": {
"task_name": "zimit",
"warehouse_path": "/other",
"image": {"name": "openzim/zimit", "tag": "1.0.0"},
"monitor": False,
"platform": None,
"flags": {
"name": "acme",
"url": "https://www.acme.com",
"zim-file": "acme_en_all_{period}.zim",
},
"resources": {"cpu": 3, "memory": 1024, "disk": 0},
},
"periodicity": "quarterly",
}

url = "/schedules/"
response = client.post(
url, json=schedule, headers={"Authorization": access_token}
)
response_data = response.get_json()
print(response_data)
if "_id" in response_data:
garbage_collector.add_schedule_id(response_data["_id"])
assert response.status_code == 201

# below test is green only if ZIMIT_DISABLE_ZIM_FILENAME_CHECK is set
# def test_create_zimit_schedule_bad_name_ok(
# self, client, access_token, garbage_collector
# ):
# schedule = {
# "name": "zimit_test_bad_name_ok",
# "category": "other",
# "enabled": False,
# "tags": [],
# "language": {"code": "fr", "name_en": "French", "name_native": "Français"},
# "config": {
# "task_name": "zimit",
# "warehouse_path": "/other",
# "image": {"name": "openzim/zimit", "tag": "1.0.0"},
# "monitor": False,
# "platform": None,
# "flags": {
# "name": "acme",
# "url": "https://www.acme.com",
# "zim-file": "bad_name",
# },
# "resources": {"cpu": 3, "memory": 1024, "disk": 0},
# },
# "periodicity": "quarterly",
# }

# url = "/schedules/"
# response = client.post(
# url, json=schedule, headers={"Authorization": access_token}
# )
# response_data = response.get_json()
# print(response_data)
# if "_id" in response_data:
# garbage_collector.add_schedule_id(response_data["_id"])
# assert response.status_code == 201

# below test becomes red if ZIMIT_DISABLE_ZIM_FILENAME_CHECK is set
def test_create_zimit_schedule_bad_name_nok(
self, client, access_token, garbage_collector
):
schedule = {
"name": "zimit_test_bad_name_nok",
"category": "other",
"enabled": False,
"tags": [],
"language": {"code": "fr", "name_en": "French", "name_native": "Français"},
"config": {
"task_name": "zimit",
"warehouse_path": "/other",
"image": {"name": "openzim/zimit", "tag": "1.0.0"},
"monitor": False,
"platform": None,
"flags": {
"name": "acme",
"url": "https://www.acme.com",
"zim-file": "bad_name",
},
"resources": {"cpu": 3, "memory": 1024, "disk": 0},
},
"periodicity": "quarterly",
}

url = "/schedules/"
response = client.post(
url, json=schedule, headers={"Authorization": access_token}
)
response_data = response.get_json()
print(response_data)
if "_id" in response_data:
garbage_collector.add_schedule_id(response_data["_id"])
assert response.status_code == 400
assert "error_description" in response_data
assert "zim-file" in response_data["error_description"]

0 comments on commit 1239c8a

Please sign in to comment.