fix in publishing
[wolnelektury.git] / src / picture / tests / picture_import.py
1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 from __future__ import with_statement
6
7 from os import path
8 from picture.models import Picture
9 from catalogue.test_utils import WLTestCase
10
11
12 class PictureTest(WLTestCase):
13
14     def test_import(self):
15         picture = Picture.from_xml_file(path.join(path.dirname(__file__), "files/kandinsky-composition-viii.xml"))
16
17         themes = set()
18         for area in picture.areas.all():
19             themes.update([
20                 (tag.category, tag.name)
21                 for tag in area.tags if tag.category in (u'theme', u'thing')])
22         assert themes == {(u'theme', u'nieporządek'), (u'thing', u'Kosmos')}, \
23             'Bad themes on Picture areas: %s' % themes
24
25         pic_themes = set([tag.name for tag in picture.tags if tag.category in ('theme', 'thing')])
26         assert not pic_themes, 'Unwanted themes set on Pictures: %s' % pic_themes
27
28         picture.delete()
29
30     def test_import_with_explicit_image(self):
31         picture = Picture.from_xml_file(path.join(path.dirname(__file__), "files/kandinsky-composition-viii.xml"),
32                                         path.join(path.dirname(__file__), "files/kandinsky-composition-viii.png"))
33
34         picture.delete()
35
36     def test_import_2(self):
37         picture = Picture.from_xml_file(path.join(path.dirname(__file__), "files/kandinsky-composition-viii.xml"),
38                                         path.join(path.dirname(__file__), "files/kandinsky-composition-viii.png"),
39                                         overwrite=True)
40         cats = set([t.category for t in picture.tags])
41         assert 'epoch' in cats
42         assert 'kind' in cats