diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-27 13:21:12 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-27 13:21:12 +0100 |
commit | 45180c1f4f2e75b38b57d581f454b170ca68cfe1 (patch) | |
tree | 62b31735a99e8e60655e3bbe1bc0956294a4652c /ishtar_common/tests.py | |
parent | ab651277d8f70c9930481b1b578a762c7eedd1b3 (diff) | |
download | Ishtar-45180c1f4f2e75b38b57d581f454b170ca68cfe1.tar.bz2 Ishtar-45180c1f4f2e75b38b57d581f454b170ca68cfe1.zip |
Tools to manage media files.
* clean unused
* find missing
* rename and simplify
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r-- | ishtar_common/tests.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index cf9f599c4..f51f9736a 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -45,7 +45,8 @@ from django.test.runner import DiscoverRunner from ishtar_common import models from ishtar_common import views from ishtar_common.apps import admin_site -from ishtar_common.utils import post_save_point, update_data, move_dict_data +from ishtar_common.utils import post_save_point, update_data, move_dict_data, \ + rename_and_simplify_media_name, try_fix_file COMMON_FIXTURES = [ @@ -1657,3 +1658,41 @@ class DashboardTest(TestCase): self.assertEqual( response.status_code, 200, "Reaching dashboard for item: {} return an error.".format(url)) + + +class CleanMedia(TestCase): + + def test_rename(self): + test_names = [ + (u"éofficier2-12-02-04.93_gvK3hAr-1_2m7zZPn-1_nKhh2S2-1_"\ + u"ONmUhfD-1_ymA3gGJ-1_XzJyRx3-1_PhvRcO8-1-thumb_ZwWMKBd.jpg", + u"éofficier2-12-02-04.93-thumb.jpg"), + (u"a_ZwWMKBd.jpg", False), # no rename because too short + (u"hoplala_gvK3hAr_2m7zZPn_nKhh2S2_ZwWMKBd.jpg", + u"hoplala_gvK3hAr_2m7zZPn_nKhh2S2.jpg",), # stop before because + # another file exists + ] + base_dir = os.sep.join([settings.ROOT_PATH, u"..", u"ishtar_common", + u"tests", u"rename"]) + for name, expected in test_names: + name = os.sep.join([base_dir, name]) + new_name, modif = rename_and_simplify_media_name(name, rename=False) + if expected: + self.assertTrue(modif) + self.assertEqual(new_name, os.sep.join([base_dir, expected])) + else: + self.assertFalse(modif) + + def test_try_fix(self): + test_names = [ + (u"hoplala_gvK3hAr_2m7zZPn_nKhh2S2_ZwWMKBd_ZwWMKBd.jpg", + # non existing file + u"hoplala_gvK3hAr_2m7zZPn.jpg",), + ] + base_dir = os.sep.join([settings.ROOT_PATH, u"..", u"ishtar_common", + u"tests", u"rename"]) + for name, expected in test_names: + name = os.sep.join([base_dir, name]) + + found = try_fix_file(name, make_copy=False) + self.assertEqual(found, expected) |