You forgot XML.
authorRadek Czajka <rczajka@rczajka.pl>
Wed, 23 Jan 2019 00:03:18 +0000 (01:03 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Wed, 23 Jan 2019 00:03:18 +0000 (01:03 +0100)
src/api/tests/res/responses/books.xml [new file with mode: 0644]
src/api/tests/res/responses/collections.json
src/api/tests/tests.py
src/wolnelektury/settings/test.py

diff --git a/src/api/tests/res/responses/books.xml b/src/api/tests/res/responses/books.xml
new file mode 100644 (file)
index 0000000..967f8e2
--- /dev/null
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="utf-8"?>
+<response><resource><kind></kind><full_sort_key>$child$2</full_sort_key><title>Child</title><url>https://example.com/katalog/lektura/child/</url><has_audio>False</has_audio><author></author><cover></cover><slug>child</slug><epoch></epoch><href>https://example.com/api/books/child/</href><genre>Wiersz</genre><simple_thumb></simple_thumb><cover_color>#000000</cover_color><cover_thumb></cover_thumb></resource><resource><kind></kind><full_sort_key>$grandchild$3</full_sort_key><title>Grandchild</title><url>https://example.com/katalog/lektura/grandchild/</url><has_audio>False</has_audio><author></author><cover></cover><slug>grandchild</slug><epoch></epoch><href>https://example.com/api/books/grandchild/</href><genre>Sonet</genre><simple_thumb></simple_thumb><cover_color>#000000</cover_color><cover_thumb></cover_thumb></resource><resource><kind>Liryka</kind><full_sort_key>john doe$parent$1</full_sort_key><title>Parent</title><url>https://example.com/katalog/lektura/parent/</url><has_audio>True</has_audio><author>John Doe</author><cover>cover/parent.jpg</cover><slug>parent</slug><epoch>Barok</epoch><href>https://example.com/api/books/parent/</href><genre>Sonet</genre><simple_thumb>https://example.com/media/cover_api_thumb/parent.jpg</simple_thumb><cover_color>#a6820a</cover_color><cover_thumb>https://example.com/media/cover/parent.jpg-139x193</cover_thumb></resource></response>
+
index a0852cd..db58324 100644 (file)
@@ -1,7 +1,7 @@
 [
     {
         "url": "https://example.com/katalog/lektury/a-collection/", 
 [
     {
         "url": "https://example.com/katalog/lektury/a-collection/", 
-        "href": "https://example.com/dapi/collections/a-collection/", 
+        "href": "https://example.com/api/collections/a-collection/", 
         "title": "A Collection"
     }
 ]
         "title": "A Collection"
     }
 ]
index ccee689..adaaa60 100644 (file)
@@ -39,6 +39,13 @@ class ApiTest(TestCase):
             self.fail('No JSON could be decoded: %s' % content)
         return data
 
             self.fail('No JSON could be decoded: %s' % content)
         return data
 
+    def assert_response(self, url, name):
+        content = self.client.get(url).content.rstrip()
+        filename = path.join(path.dirname(__file__), 'res', 'responses', name)
+        with open(filename) as f:
+            good_content = f.read().rstrip()
+        self.assertEqual(content, good_content, content)
+    
     def assert_json_response(self, url, name):
         data = self.load_json(url)
         filename = path.join(path.dirname(__file__), 'res', 'responses', name)
     def assert_json_response(self, url, name):
         data = self.load_json(url)
         filename = path.join(path.dirname(__file__), 'res', 'responses', name)
@@ -130,6 +137,7 @@ class BooksTests(ApiTest):
     def test_books(self):
         self.assert_json_response('/api/books/', 'books.json')
         self.assert_json_response('/api/books/?new_api=true', 'books.json')
     def test_books(self):
         self.assert_json_response('/api/books/', 'books.json')
         self.assert_json_response('/api/books/?new_api=true', 'books.json')
+        self.assert_response('/api/books/?format=xml', 'books.xml')
 
         self.assert_slugs('/api/audiobooks/', ['parent'])
         self.assert_slugs('/api/daisy/', ['parent'])
 
         self.assert_slugs('/api/audiobooks/', ['parent'])
         self.assert_slugs('/api/daisy/', ['parent'])
index 0ad0e69..25bd82c 100644 (file)
@@ -2,3 +2,4 @@ from wolnelektury.settings import *
 
 THUMBNAIL_BACKEND = 'wolnelektury.test_utils.DummyThumbnailBackend'
 CATALOGUE_GET_MP3_LENGTH = 'catalogue.test_utils.get_mp3_length'
 
 THUMBNAIL_BACKEND = 'wolnelektury.test_utils.DummyThumbnailBackend'
 CATALOGUE_GET_MP3_LENGTH = 'catalogue.test_utils.get_mp3_length'
+MEDIA_URL = '/media/'