summaryrefslogtreecommitdiff
path: root/ishtar_common/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r--ishtar_common/tests.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index e535eda4b..90af3ac93 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -2913,6 +2913,54 @@ class PersonQATest(TestCase):
)
+class StorageTest(TestCase):
+ def setUp(self) -> None:
+ self.st1 = models.SourceType.objects.create(label="Report", code="REP")
+
+ def test_filesystemstorage(self) -> None:
+ # bug when link to non-existing files
+ image_path = os.path.join(
+ settings.ROOT_PATH, "..", "ishtar_common", "tests", "test.png"
+ )
+ doc = models.Document.objects.create(
+ source_type=self.st1,
+ title="Operation report",
+ image=SimpleUploadedFile(
+ name="test.png",
+ content=open(image_path, "rb").read(),
+ content_type="image/png",
+ ),
+ )
+ p = doc.image.path.split(os.sep)
+ # current save path
+ base_path = os.sep.join(p[:-1])
+ # clean all files in order to have no random string on save
+ for f in os.listdir(base_path):
+ if f.startswith("test"):
+ os.remove(os.path.join(base_path, f))
+ doc = models.Document.objects.get(pk=doc.pk)
+ doc.image.save(
+ "test.png",
+ SimpleUploadedFile(
+ name="test.png",
+ content=open(image_path, "rb").read(),
+ content_type="image/png",
+ ),
+ )
+ doc = models.Document.objects.get(pk=doc.pk)
+ os.remove(doc.image.path)
+ os.symlink("/tmp/ZZZZZZZZZZZZZZZ", doc.image.path) # bad link
+ doc.image.save(
+ "test.png",
+ SimpleUploadedFile(
+ name="test.png",
+ content=open(image_path, "rb").read(),
+ content_type="image/png",
+ ),
+ )
+ doc.save()
+
+
class DocumentTest(TestCase):
def setUp(self):
Operation = apps.get_model("archaeological_operations", "Operation")