X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/f715832d8af615462b881bff83a37237bf44ca22..7fdf8249c9c016e397edc3112184e74b0f3f9778:/apps/api/tests.py diff --git a/apps/api/tests.py b/apps/api/tests.py index 2c2e51ce8..0a638dc3f 100644 --- a/apps/api/tests.py +++ b/apps/api/tests.py @@ -1,23 +1,28 @@ # -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from os import path -from datetime import datetime - +from django.core.files.uploadedfile import SimpleUploadedFile from django.test import TestCase -from django.utils import simplejson as json -from django.conf import settings +from django.test.utils import override_settings +import json -from api.helpers import timestamp 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): - - 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): @@ -30,10 +35,10 @@ class ChangesTest(ApiTest): book.save() changes = json.loads(self.client.get('/api/changes/0.json?book_fields=title&tag_fields=name').content) - self.assertEqual(changes['updated']['books'], + self.assertEqual(changes['updated']['books'], [{'id': book.id, 'title': book.title}], 'Invalid book format in changes') - self.assertEqual(changes['updated']['tags'], + self.assertEqual(changes['updated']['tags'], [{'id': tag.id, 'name': tag.name}], 'Invalid tag format in changes') @@ -135,3 +140,21 @@ class TagTests(TestCase): 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() + + Picture.objects.get(slug=slug)