38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import os
|
|||
|
|
import sys
|
||
|
|
import unittest
|
||
|
|
from types import SimpleNamespace
|
||
|
|
|
||
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
||
|
|
|
||
|
|
from app import image_paths
|
||
|
|
from app.config import make_slug
|
||
|
|
|
||
|
|
|
||
|
|
class ImagePathTests(unittest.TestCase):
|
||
|
|
def test_task_image_path_uses_batch_slug_task_and_item(self):
|
||
|
|
root = os.path.abspath(os.path.join("tmp", "images"))
|
||
|
|
task = SimpleNamespace(id=42, batch_id=7, item_id="51100639510", alias="alias-a")
|
||
|
|
account = SimpleNamespace(slug="main_shop")
|
||
|
|
|
||
|
|
path = image_paths.task_image_path(root, task, account, "new")
|
||
|
|
|
||
|
|
self.assertEqual(
|
||
|
|
os.path.join(root, "7", "main_shop", "42_51100639510_new.jpg"),
|
||
|
|
path,
|
||
|
|
)
|
||
|
|
|
||
|
|
def test_task_image_path_falls_back_to_account_alias_slug(self):
|
||
|
|
root = os.path.abspath(os.path.join("tmp", "images"))
|
||
|
|
task = {"id": 5, "batch_id": 3, "item_id": "ITEM/1", "alias": "alias-a"}
|
||
|
|
|
||
|
|
path = image_paths.task_image_path(root, task, None, "old")
|
||
|
|
|
||
|
|
self.assertEqual(
|
||
|
|
os.path.join(root, "3", make_slug("alias-a"), "5_ITEM_1_old.jpg"),
|
||
|
|
path,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
unittest.main()
|