1e17289c3cf223c04ffa8ab9e9c687c5a3120c5b
[wolnelektury.git] / apps / 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([(tag.category, tag.name)
20                 for tag in area.tags if tag.category in (u'theme', u'thing')])
21         assert themes == set([(u'theme', u'nieporządek'), (u'thing', u'Kosmos')]), \
22             'Bad themes on Picture areas: %s' % themes
23
24         pic_themes = set([tag.name for tag in picture.tags if tag.category in ('theme', 'thing')])
25         assert not pic_themes, 'Unwanted themes set on Pictures: %s' % pic_themes
26
27         picture.delete()
28
29     def test_import_with_explicit_image(self):
30         picture = Picture.from_xml_file(path.join(path.dirname(__file__), "files/kandinsky-composition-viii.xml"),
31                                         path.join(path.dirname(__file__), "files/kandinsky-composition-viii.png"))
32
33         picture.delete()
34
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
43