Fix transform_abstracy + tests.
[librarian.git] / tests / test_picture.py
1 # -*- coding: utf-8 -*-
2 #
3 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 #
6 from __future__ import unicode_literals
7
8 from librarian import picture, dcparser
9 from tests.utils import get_all_fixtures, get_fixture
10 from os import path
11
12
13 def test_wlpictureuri():
14     uri = picture.WLPictureURI('http://wolnelektury.pl/katalog/obraz/angelus-novus')
15
16
17 def check_load(xml_file):
18     pi = dcparser.parse(xml_file, picture.PictureInfo)
19     assert pi is not None
20     assert isinstance(pi, picture.PictureInfo)
21     
22
23 def test_load():
24     for fixture in get_all_fixtures('picture', '*.xml'):
25         yield check_load, fixture
26
27
28 def test_wlpicture():
29     wlp = picture.WLPicture.from_file(open(get_fixture('picture', 'angelus-novus.xml')))
30     pi = wlp.picture_info
31
32     #    from nose.tools import set_trace; set_trace()
33     assert pi.type[0] == u"Image"
34     assert pi.mime_type == u'image/jpeg' == wlp.mime_type
35     assert wlp.slug == 'angelus-novus'
36
37     assert path.exists(wlp.image_path)
38     
39     f = wlp.image_file()
40     f.close()
41
42
43 def test_picture_parts():
44     wlp = picture.WLPicture.from_file(open(get_fixture('picture', 'angelus-novus.xml')))
45     parts = list(wlp.partiter())
46     expect_parts = 4
47     assert len(parts) == expect_parts, "there should be %d parts of the picture" % expect_parts
48     motifs = set()
49     names = set()
50
51     for p in parts:
52         for m in p['themes']:
53             motifs.add(m)
54     for p in parts:
55         if p['object']:
56             names.add(p['object'])
57
58     assert motifs == {u'anioł historii', u'spojrzenie'}, "missing motifs, got: %s" % motifs
59     assert names == {u'obraz cały', u'skrzydło'}, 'missing objects, got: %s' % names