be more robust
[wolnelektury.git] / apps / api / tests.py
index 12c7126..fe8e70f 100644 (file)
@@ -1,23 +1,26 @@
 # -*- coding: utf-8 -*-
 
 # -*- coding: utf-8 -*-
 
-from datetime import datetime
+from os import path
 
 
+from django.core.files.uploadedfile import SimpleUploadedFile
 from django.test import TestCase
 from django.test import TestCase
+from django.test.utils import override_settings
 from django.utils import simplejson as json
 from django.utils import simplejson as json
-from django.conf import settings
 
 
-from api.helpers import timestamp
 from catalogue.models import Book, Tag
 from catalogue.models import Book, Tag
+from picture.forms import PictureImportForm
+from picture.models import Picture
+import picture.tests
 
 
 
 
+@override_settings(
+    API_WAIT=-1, 
+    CACHES = {'api': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'},
+              'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'},
+              'permanent': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}
+)
 class ApiTest(TestCase):
 class ApiTest(TestCase):
-
-    def setUp(self):
-        self.old_api_wait = settings.API_WAIT
-        settings.API_WAIT = -1
-
-    def tearDown(self):
-        settings.API_WAIT = self.old_api_wait
+    pass
 
 
 class ChangesTest(ApiTest):
 
 
 class ChangesTest(ApiTest):
@@ -122,6 +125,9 @@ class TagTests(TestCase):
 
     def setUp(self):
         self.tag = Tag.objects.create(category='author', slug='joe', name='Joe')
 
     def setUp(self):
         self.tag = Tag.objects.create(category='author', slug='joe', name='Joe')
+        self.book = Book.objects.create(title='A Book', slug='a-book')
+        self.book.tags = [self.tag]
+        self.book.save()
 
     def test_tag_list(self):
         tags = json.loads(self.client.get('/api/authors/').content)
 
     def test_tag_list(self):
         tags = json.loads(self.client.get('/api/authors/').content)
@@ -132,3 +138,22 @@ class TagTests(TestCase):
         tag = json.loads(self.client.get('/api/authors/joe/').content)
         self.assertEqual(tag['name'], self.tag.name,
                         'Wrong tag details.')
         tag = json.loads(self.client.get('/api/authors/joe/').content)
         self.assertEqual(tag['name'], self.tag.name,
                         'Wrong tag details.')
+
+
+class PictureTests(ApiTest):
+    def test_publish(self):
+        slug = "kandinsky-composition-viii"
+        xml = SimpleUploadedFile('composition8.xml', open(path.join(picture.tests.__path__[0], "files", slug + ".xml")).read())
+        img = SimpleUploadedFile('kompozycja-8.png', open(path.join(picture.tests.__path__[0], "files", slug + ".png")).read())
+
+        import_form = PictureImportForm({}, {
+            'picture_xml_file': xml,
+            'picture_image_file': img
+            })
+
+        assert import_form.is_valid()
+        if import_form.is_valid():
+            import_form.save()
+
+        pic = Picture.objects.get(slug=slug)
+