00b03cef39b6e9f6a6611187186412238c3b988d
[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 librarian import picture, dcparser
7 from tests.utils import get_all_fixtures, get_fixture
8 from os import path
9
10
11 def test_wlpictureuri():
12     uri = picture.WLPictureURI('http://wolnelektury.pl/katalog/obraz/angelus-novus')
13
14
15 def check_load(xml_file):
16     pi = dcparser.parse(xml_file, picture.PictureInfo)
17     assert pi is not None
18     assert isinstance(pi, picture.PictureInfo)
19     
20
21 def test_load():
22     for fixture in get_all_fixtures('picture', '*.xml'):
23         yield check_load, fixture
24
25
26 def test_wlpicture():
27     wlp = picture.WLPicture.from_file(open(get_fixture('picture', 'angelus-novus.xml')))
28     pi = wlp.picture_info
29
30     #    from nose.tools import set_trace; set_trace()
31     assert pi.type[0] == u"Image"
32     assert pi.mime_type == u'image/jpeg' == wlp.mime_type
33     assert wlp.slug == 'angelus-novus'
34
35     assert path.exists(wlp.image_path)
36     
37     f = wlp.image_file('r')
38     f.close()
39
40
41 def test_picture_parts():
42     wlp = picture.WLPicture.from_file(open(get_fixture('picture', 'angelus-novus.xml')))
43     parts = list(wlp.partiter())
44     expect_parts = 4
45     assert len(parts) == expect_parts, "there should be %d parts of the picture" % expect_parts
46     motifs = set()
47     names = set()
48
49     print parts
50     for p in parts:
51         for m in p['themes']:
52             motifs.add(m)
53     for p in parts:
54         if p['object']:
55             names.add(p['object'])
56
57     assert motifs == {u'anioł historii', u'spojrzenie'}, "missing motifs, got: %s" % motifs
58     assert names == {u'obraz cały', u'skrzydło'}, 'missing objects, got: %s' % names