Minor fixes in picture publishing process.
[wolnelektury.git] / apps / picture / tests / picture_import.py
index 9e965f9..1e17289 100644 (file)
@@ -1,22 +1,43 @@
 # -*- coding: utf-8 -*-
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
 from __future__ import with_statement
 
-from django.core.files.base import ContentFile, File
-from catalogue.test_utils import *
-from catalogue import models
-from librarian import WLURI
+from os import path
 from picture.models import Picture
+from catalogue.test_utils import WLTestCase
 
-from nose.tools import raises
-import tempfile
-from os import unlink, path, makedirs
 
+class PictureTest(WLTestCase):
 
-class PictureTest(TestCase):
-    
     def test_import(self):
         picture = Picture.from_xml_file(path.join(path.dirname(__file__), "files/kandinsky-composition-viii.xml"))
 
-        motifs = set([tag.name for tag in picture.tags if tag.category == 'theme'])
-        assert motifs == set([u'nieporządek']), 'theme tags are wrong. %s' % motifs
-    
+        themes = set()
+        for area in picture.areas.all():
+            themes.update([(tag.category, tag.name)
+                for tag in area.tags if tag.category in (u'theme', u'thing')])
+        assert themes == set([(u'theme', u'nieporządek'), (u'thing', u'Kosmos')]), \
+            'Bad themes on Picture areas: %s' % themes
+
+        pic_themes = set([tag.name for tag in picture.tags if tag.category in ('theme', 'thing')])
+        assert not pic_themes, 'Unwanted themes set on Pictures: %s' % pic_themes
+
+        picture.delete()
+
+    def test_import_with_explicit_image(self):
+        picture = Picture.from_xml_file(path.join(path.dirname(__file__), "files/kandinsky-composition-viii.xml"),
+                                        path.join(path.dirname(__file__), "files/kandinsky-composition-viii.png"))
+
+        picture.delete()
+
+
+    def test_import_2(self):
+        picture = Picture.from_xml_file(path.join(path.dirname(__file__), "files/kandinsky-composition-viii.xml"),
+                                        path.join(path.dirname(__file__), "files/kandinsky-composition-viii.png"),
+                                        overwrite=True)
+        cats = set([t.category for t in picture.tags])
+        assert 'epoch' in cats
+        assert 'kind' in cats
+