diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-18 13:43:09 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-18 13:43:09 +0200 |
commit | baa4f718cf64d8da4185910e7bc5e600705f9d24 (patch) | |
tree | 08b97ab6e2d2624fd049c3f2453e5174644da7a7 /archaeological_operations/tests.py | |
parent | b64b199715c3f424762d54f848749ead11434096 (diff) | |
download | Ishtar-baa4f718cf64d8da4185910e7bc5e600705f9d24.tar.bz2 Ishtar-baa4f718cf64d8da4185910e7bc5e600705f9d24.zip |
Json fields: test display of json fields on the sheet
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 9d99ed67d..ab0876aef 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -23,6 +23,7 @@ import StringIO import zipfile from django.conf import settings +from django.contrib.contenttypes.models import ContentType from django.core.files.uploadedfile import SimpleUploadedFile from django.core.urlresolvers import reverse from django.db.models import Q @@ -37,7 +38,7 @@ from archaeological_operations import views from ishtar_common.models import OrganizationType, Organization, ItemKey, \ ImporterType, IshtarUser, TargetKey, ImporterModel, IshtarSiteProfile, \ Town, ImporterColumn, Person, Author, SourceType, AuthorType, \ - DocumentTemplate, PersonType, TargetKeyGroup + DocumentTemplate, PersonType, TargetKeyGroup, JsonDataField, JsonDataSection from archaeological_files.models import File, FileType from archaeological_context_records.models import Unit @@ -1030,6 +1031,53 @@ class OperationTest(TestCase, OperationInitTest): z = zipfile.ZipFile(f) self.assertIsNone(z.testzip()) + def test_json(self): + operation = self.operations[0] + operation.data = {"groundhog": {"number": 53444, + "awake_state": u"réveillée", + "with_feather": "Oui"}, + "frog_number": 32303} + operation.save() + + content_type = ContentType.objects.get_for_model(operation) + groundhog_section = JsonDataSection.objects.create( + name="Marmotte", content_type=content_type) + JsonDataField.objects.create(name=u"État d'éveil", + key='groundhog__awake_state', + content_type=content_type, + section=groundhog_section) + JsonDataField.objects.create(name=u"Avec plume", + key='groundhog__with_feather', + content_type=content_type, + section=groundhog_section) + JsonDataField.objects.create(name=u"Zzzzzzzz", + key='groundhog__zzz', + content_type=content_type, + section=groundhog_section) + JsonDataField.objects.create(name=u"Grenouille", + key='frog_number', + content_type=content_type) + + c = Client() + c.login(username=self.username, password=self.password) + response = c.get(reverse('show-operation', kwargs={'pk': operation.pk})) + self.assertEqual(response.status_code, 200) + self.assertIn('class="sheet"', response.content) + self.assertIn(u"Marmotte".encode('utf-8'), response.content) + self.assertIn(u"État d'éveil".encode('utf-8'), response.content) + self.assertIn(u"réveillée".encode('utf-8'), response.content) + self.assertIn(u"Grenouille".encode('utf-8'), response.content) + self.assertIn(u"32303".encode('utf-8'), response.content) + self.assertNotIn(u"53444".encode('utf-8'), response.content) + self.assertNotIn(u"Zzzzzzzz".encode('utf-8'), response.content) + + operation.data = {} + operation.save() + response = c.get(reverse('show-operation', kwargs={'pk': operation.pk})) + self.assertEqual(response.status_code, 200) + self.assertIn('class="sheet"', response.content) + self.assertNotIn(u"Marmotte".encode('utf-8'), response.content) + class OperationSearchTest(TestCase, OperationInitTest): fixtures = FILE_FIXTURES |