9fb5a4a0d8a6b0b93f351dc104a6616091b9501c
[redakcja.git] / src / catalogue / tests / test_xml_updater.py
1 # -*- coding: utf-8 -*-
2 #
3 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 #
6 """XmlUpdater tests."""
7
8 from catalogue.test_utils import get_fixture
9 from django.test import TestCase
10 from django.contrib.auth.models import User
11 from catalogue.models import Book
12 from catalogue.management import XmlUpdater
13 from librarian import DCNS
14
15
16 class XmlUpdaterTests(TestCase):
17     class SimpleUpdater(XmlUpdater):
18         @XmlUpdater.fixes_elements('.//' + DCNS('title'))
19         def fix_title(element, **kwargs):
20             element.text = element.text + " fixed"
21             return True
22
23     def setUp(self):
24         self.user = User.objects.create(username='tester')
25         text = get_fixture('chunk1.xml')
26         Book.create(self.user, text, slug='test-book')
27         self.title = "Do M***"
28
29     def test_xml_updater(self):
30         self.SimpleUpdater().run(self.user)
31         self.assertEqual(
32             Book.objects.get(slug='test-book').wldocument(
33                 publishable=False).book_info.title,
34             self.title + " fixed"
35             )