1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
6 from librarian import picture, dcparser
7 from tests.utils import get_all_fixtures, get_fixture
10 class PictureTests(unittest.TestCase):
11 def test_wlpictureuri(self):
12 uri = picture.WLPictureURI('http://wolnelektury.pl/katalog/obraz/angelus-novus')
14 def check_load(self, xml_file):
15 pi = dcparser.parse(xml_file, picture.PictureInfo)
16 self.assertIsNotNone(pi)
17 self.assertIsInstance(pi, picture.PictureInfo)
20 for fixture in get_all_fixtures('picture', '*.xml'):
21 with self.subTest(fixture=fixture):
22 self.check_load(fixture)
24 def test_wlpicture(self):
25 with open(get_fixture('picture', 'angelus-novus.xml')) as f:
26 wlp = picture.WLPicture.from_file(f)
29 self.assertEqual(pi.type[0], "Image")
30 self.assertEqual(pi.mime_type, 'image/jpeg')
31 self.assertEqual(wlp.mime_type, 'image/jpeg')
32 self.assertEqual(wlp.slug, 'angelus-novus')
33 self.assertTrue(path.exists(wlp.image_path))
39 def test_picture_parts(self):
40 with open(get_fixture('picture', 'angelus-novus.xml')) as f:
41 wlp = picture.WLPicture.from_file(f)
42 parts = list(wlp.partiter())
44 self.assertEqual(len(parts), expect_parts, "there should be %d parts of the picture" % expect_parts)
53 names.add(p['object'])
55 self.assertEqual(motifs, {'anioł historii', 'spojrzenie'}, "missing motifs, got: %s" % motifs)
56 self.assertEqual(names, {'obraz cały', 'skrzydło'}, 'missing objects, got: %s' % names)