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