diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-02-27 20:44:52 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-06-17 13:21:27 +0200 | 
| commit | 86c03a98d11e93880b4568776e0939113a92a707 (patch) | |
| tree | e07ad2e91e2544f7b2d61e8f3f653fdda26bfd52 /archaeological_operations/tests.py | |
| parent | 52f442699a72ff5d0341a7d15d5b966a3cc2bd60 (diff) | |
| download | Ishtar-86c03a98d11e93880b4568776e0939113a92a707.tar.bz2 Ishtar-86c03a98d11e93880b4568776e0939113a92a707.zip  | |
Migrate to python 3 - Clean old migrations and some old scripts
Diffstat (limited to 'archaeological_operations/tests.py')
| -rw-r--r-- | archaeological_operations/tests.py | 251 | 
1 files changed, 120 insertions, 131 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 190543e3f..65cc0c316 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -20,7 +20,7 @@  import json  import datetime  from subprocess import Popen, PIPE -import StringIO +from io import StringIO, BytesIO  import tempfile  import zipfile @@ -33,8 +33,8 @@ from django.db.models import Q  from django.test.client import Client  from django.contrib.auth.models import User, Permission -from django.utils.translation import ugettext_lazy as _, pgettext -import models +from django.utils.translation import ugettext_lazy as _, pgettext, pgettext_lazy +from . import models  from archaeological_operations import views @@ -651,10 +651,10 @@ class ImportStepByStepTest(ImportTest, TestCase):          self.assertEqual(response.status_code, 200)          # verify pagination for next link is OK          self.assertIn('href="/import-step-by-step/{}/3/"'.format(impt.pk), -                      response.content) +                      response.content.decode())          # creation have been evaluated          self.assertIn( -            unicode(_(u"New objects will be created.")), +            str(_(u"New objects will be created.")),              response.content.decode('utf-8')          ) @@ -684,7 +684,7 @@ class ImportStepByStepTest(ImportTest, TestCase):          response = c.get(import_url)          self.assertEqual(response.status_code, 200)          self.assertIn( -            unicode(_(u"This line have been already imported.")), +            str(_(u"This line have been already imported.")),              response.content.decode('utf-8')          ) @@ -719,7 +719,7 @@ class ImportStepByStepTest(ImportTest, TestCase):              imported_line = fle.readline()              self.assertIn("2000/01/32", imported_line)          # error detected on the source file -        error = unicode(_( +        error = str(_(              u"The following error(s) has been encountered while parsing "              u"the source file:")          ) @@ -932,7 +932,7 @@ class ParcelTest(ImportTest, TestCase):              for year in result.keys():                  for values in parcels_copy:                      if values['year'] != year and \ -                       values['year'] != unicode(year): +                       values['year'] != str(year):                          continue                      self.assertTrue(                          (values['section'], values['parcel_number']) @@ -940,7 +940,7 @@ class ParcelTest(ImportTest, TestCase):                          msg="Section - Parcel number: \"%s - %s\" is not "                          "in \"%s\"" % (                              values['section'], values['parcel_number'], -                            unicode(result[year]))) +                            str(result[year])))                      parcels.pop(parcels.index(values))                      result[year].pop(result[year].index(                          (values['section'], values['parcel_number']))) @@ -1304,7 +1304,7 @@ class OperationTest(TestCase, OperationInitTest):          response = c.get(reverse('show-operation', kwargs={'pk': operation.pk}))          self.assertEqual(response.status_code, 200)          # empty content when not allowed -        self.assertEqual(response.content, "") +        self.assertEqual(response.content, b"")          response = c.get(reverse('show-document',                                   kwargs={'pk': source.pk}))          self.assertRedirects(response, "/") @@ -1312,11 +1312,11 @@ class OperationTest(TestCase, OperationInitTest):          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="card sheet"', response.content) +        self.assertIn(b'class="card sheet"', response.content)          response = c.get(reverse('show-document',                                   kwargs={'pk': source.pk}))          self.assertEqual(response.status_code, 200) -        self.assertIn('class="card sheet"', response.content) +        self.assertIn(b'class="card sheet"', response.content)      def test_show_pdf(self):          operation = self.operations[0] @@ -1325,15 +1325,15 @@ class OperationTest(TestCase, OperationInitTest):                                   kwargs={'pk': operation.pk, 'type': 'pdf'}))          self.assertEqual(response.status_code, 200)          # empty content when not allowed -        self.assertEqual(response.content, "") +        self.assertEqual(response.content, b"")          c.login(username=self.username, password=self.password)          response = c.get(reverse('show-operation',                                   kwargs={'pk': operation.pk, 'type': 'pdf'}))          self.assertEqual(response.status_code, 200) -        f = StringIO.StringIO(response.content) +        f = BytesIO(response.content)          filetype = Popen("/usr/bin/file -b --mime -", shell=True, stdout=PIPE,                           stdin=PIPE).communicate(f.read(1024))[0].strip() -        self.assertTrue(filetype.startswith('application/pdf')) +        self.assertTrue(filetype.startswith(b'application/pdf'))      def test_show_odt(self):          operation = self.operations[0] @@ -1342,12 +1342,12 @@ class OperationTest(TestCase, OperationInitTest):                                   kwargs={'pk': operation.pk, 'type': 'odt'}))          self.assertEqual(response.status_code, 200)          # empty content when not allowed -        self.assertEqual(response.content, "") +        self.assertEqual(response.content, b"")          c.login(username=self.username, password=self.password)          response = c.get(reverse('show-operation', kwargs={'pk': operation.pk,                                                             'type': 'odt'}))          self.assertEqual(response.status_code, 200) -        f = StringIO.StringIO(response.content) +        f = BytesIO(response.content)          z = zipfile.ZipFile(f)          self.assertIsNone(z.testzip()) @@ -1398,21 +1398,22 @@ class OperationTest(TestCase, OperationInitTest):          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="card 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) +        content = response.content.decode() +        self.assertIn('class="card sheet"', content) +        self.assertIn("Marmotte", content) +        self.assertIn("État d'éveil", content) +        self.assertIn("réveillée", content) +        self.assertIn("Grenouille", content) +        self.assertIn(">32303<", content) +        self.assertNotIn(">53444<", content) +        self.assertNotIn("Zzzzzzzz", content)          operation.data = {}          operation.save()          response = c.get(reverse('show-operation', kwargs={'pk': operation.pk}))          self.assertEqual(response.status_code, 200) -        self.assertIn('class="card sheet"', response.content) -        self.assertNotIn(u"Marmotte".encode('utf-8'), response.content) +        self.assertIn(b'class="card sheet"', response.content) +        self.assertNotIn(b"Marmotte", response.content)      def test_json_search_vector_update(self):          operation = self.operations[0] @@ -1447,7 +1448,7 @@ class OperationTest(TestCase, OperationInitTest):          doc = Document.objects.get(pk=doc.pk)          self.assertEqual(c_index + 1, doc.index) -        self.assertEqual(doc.external_id, unicode(doc.index)) +        self.assertEqual(doc.external_id, str(doc.index))          doc2 = Document.objects.create(title="Image2!")          operation.documents.add(doc2) @@ -1488,7 +1489,7 @@ class CustomFormTest(TestCase, OperationInitTest):          key_in_charge = "in_charge"          response = c.post(url, data)          self.assertIn( -            key_in_charge, response.content, +            key_in_charge, response.content.decode(),              msg="filter all - 'in charge' field not found on the modification "                  "wizard")          f = CustomForm.objects.create(name="Test", form="operation-010-general", @@ -1497,7 +1498,7 @@ class CustomFormTest(TestCase, OperationInitTest):          response = c.post(url, data)          self.assertNotIn( -            key_in_charge, response.content, +            key_in_charge, response.content.decode(),              msg="filter all - 'in charge' field found on the modification "                  "wizard. It should have been filtered.") @@ -1511,11 +1512,11 @@ class CustomFormTest(TestCase, OperationInitTest):          ExcludedField.objects.create(custom_form=f_scientist, field="address")          response = c.post(url, data)          self.assertIn( -            key_in_charge, response.content, +            key_in_charge, response.content.decode(),              msg="filter user type - 'in charge' field not found on the "                  "modification wizard. It should not have been filtered.")          self.assertNotIn( -            key_address, response.content, +            key_address, response.content.decode(),              msg="filter user type - 'address' field found on the "                  "modification wizard. It should have been filtered.") @@ -1526,11 +1527,11 @@ class CustomFormTest(TestCase, OperationInitTest):          self.user.ishtaruser.person.person_types.add(tpe)          response = c.post(url, data)          self.assertIn( -            key_in_charge, response.content, +            key_in_charge, response.content.decode(),              msg="filter user - 'in charge' field not found on the modification "                  "wizard. It should not have been filtered.")          self.assertIn( -            key_address, response.content, +            key_address, response.content.decode(),              msg="filter user - 'address' field not found on the modification "                  "wizard. It should not have been filtered.") @@ -1594,14 +1595,14 @@ class CustomFormTest(TestCase, OperationInitTest):          }          response = c.post(url, data)          self.assertIn( -            "Le beau", response.content, +            b"Le beau", response.content,              msg="json field not displayed on modification wizard"          )          cls_wiz.wizard_post(c, url, step, {'pk': self.operations[1].pk})          response = c.post(url, data)          self.assertIn( -            "Le beau", response.content, +            b"Le beau", response.content,              msg="json field form: existing value should be presented in select"          ) @@ -1642,35 +1643,38 @@ class OperationSearchTest(TestCase, OperationInitTest):          c = Client()          response = c.get(reverse('get-operation'), {'year': '2010'})          # no result when no authentication -        self.assertTrue(not json.loads(response.content)) +        self.assertTrue(not json.loads(response.content.decode()))          c.login(username=self.username, password=self.password)          response = c.get(reverse('get-operation'), {'year': '2010'}) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 2) -        response = c.get(reverse('get-operation'), -                         {'operator': self.orgas[0].name}) -        result = json.loads(response.content) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         2) +        response = c.get( +            reverse('get-operation'), +            {pgettext_lazy("key for text search", u"operator"): +             self.orgas[0].name}) +        result = json.loads(response.content.decode())          self.assertEqual(result['recordsTotal'], 3)      def test_base_search_vector(self):          c = Client()          response = c.get(reverse('get-operation'), {'search_vector': 'chaTEAU'})          # no result when no authentication -        self.assertTrue(not json.loads(response.content)) +        self.assertTrue(not json.loads(response.content.decode()))          c.login(username=self.username, password=self.password)          # test vector search with accents          operation = models.Operation.objects.get(pk=self.operations[0].pk)          operation.common_name = u"Opération : Château de Fougères"          operation.save()          response = c.get(reverse('get-operation'), {'search_vector': 'chaTEAU'}) -        result = json.loads(response.content) +        result = json.loads(response.content.decode())          self.assertEqual(result['recordsTotal'], 1)          response = c.get(reverse('get-operation'), {'search_vector': 'château'}) -        result = json.loads(response.content) +        result = json.loads(response.content.decode())          self.assertEqual(result['recordsTotal'], 1)          # test search with inappropriate minus sign          response = c.get(reverse('get-operation'),                           {'search_vector': 'chaTEAU - '}) -        result = json.loads(response.content) +        result = json.loads(response.content.decode())          self.assertEqual(result['recordsTotal'], 1)      def test_complex_search_vector(self): @@ -1694,42 +1698,42 @@ class OperationSearchTest(TestCase, OperationInitTest):          self.assertEqual(result['recordsTotal'], 1)          response = c.get(reverse('get-operation'),                           {'search_vector': 'chaTEAU fougere'}) -        result = json.loads(response.content) +        result = json.loads(response.content.decode())          self.assertEqual(result['recordsTotal'], 1)          # explicit AND          response = c.get(reverse('get-operation'),                           {'search_vector': 'chaTEAU & fougere'}) -        result = json.loads(response.content) +        result = json.loads(response.content.decode())          self.assertEqual(result['recordsTotal'], 1)          # explicit OR          response = c.get(reverse('get-operation'),                           {'search_vector': 'chaTEAU | fougere'}) -        result = json.loads(response.content) +        result = json.loads(response.content.decode())          self.assertEqual(result['recordsTotal'], 3)          # query with parenthesis          # response = c.get(reverse('get-operation'),          #                  {'search_vector': '2010 & (fougere | filicophyta)'}) -        # result = json.loads(response.content) +        # result = json.loads(response.content.decode())          # self.assertEqual(result['recordsTotal'], 2)          # query with mistmatch parenthesis          response = c.get(reverse('get-operation'),                           {'search_vector': '))   2010 &) ((chaTEAU | fougere)'}) -        result = json.loads(response.content) +        result = json.loads(response.content.decode())          self.assertEqual(result['recordsTotal'], 2)          # open search          response = c.get(reverse('get-operation'), {'search_vector': 'cha*'}) -        result = json.loads(response.content) +        result = json.loads(response.content.decode())          self.assertEqual(result['recordsTotal'], 3)          # exclude          response = c.get(reverse('get-operation'),                           {'search_vector': '-fougere'}) -        result = json.loads(response.content) +        result = json.loads(response.content.decode())          self.assertEqual(result['recordsTotal'], 1)      def _test_search(self, c, term, query_string, number, name=""): @@ -1739,7 +1743,7 @@ class OperationSearchTest(TestCase, OperationInitTest):          search = {'search_vector': q}          response = c.get(reverse('get-operation'), search)          self.assertEqual(response.status_code, 200) -        result = json.loads(response.content) +        result = json.loads(response.content.decode())          if not result:              result = {"recordsTotal": 0}          self.assertEqual(result['recordsTotal'], number, @@ -1776,15 +1780,15 @@ class OperationSearchTest(TestCase, OperationInitTest):          villa = models.RemainType.objects.get(txt_idx='villa')          ope1.remains.add(villa) -        search_period_q = unicode(pgettext("key for text search", u"period")) +        search_period_q = str(pgettext("key for text search", u"period"))          self._test_search(c, search_period_q, final_neo.label, 1, "Simple") -        search_year_q = unicode(pgettext("key for text search", u"year")) +        search_year_q = str(pgettext("key for text search", u"year"))          self._test_search(c, search_year_q, "2042", 1, "Integer")          self._test_search(c, search_year_q, '2042";"2020', 2, "Many integer") -        search_town_q = unicode(pgettext("key for text search", u"town")) +        search_town_q = str(pgettext("key for text search", u"town"))          self._test_search(c, search_town_q, town.cached_label, 1,                            "String search with parenthesis and minus") @@ -1807,12 +1811,12 @@ class OperationSearchTest(TestCase, OperationInitTest):                            u'{}*'.format(neo.label[:3]), 2, "Open search")          # non hierarchic search -        search_remain_q = unicode(pgettext("key for text search", u"remain")) +        search_remain_q = str(pgettext("key for text search", u"remain"))          self._test_search(c, search_remain_q, villa.label,                            1, "Non hierarchic search")          # boolean search -        search_open_q = unicode(pgettext("key for text search", u"is-open")) +        search_open_q = str(pgettext("key for text search", u"is-open"))          self._test_search(c, search_open_q, u"Yes", 2, "Boolean")      def test_mixed_search_vector(self): @@ -1824,10 +1828,10 @@ class OperationSearchTest(TestCase, OperationInitTest):          c = Client()          c.login(username=self.username, password=self.password) -        search_year_q = unicode(pgettext("key for text search", u"year")) +        search_year_q = str(pgettext("key for text search", u"year"))          q = '"chateau fougere" {}="2042"'.format(search_year_q)          response = c.get(reverse('get-operation'), {'search_vector': q}) -        result = json.loads(response.content) +        result = json.loads(response.content.decode())          self.assertEqual(result['recordsTotal'], 1)      def create_relations(self): @@ -1847,15 +1851,18 @@ class OperationSearchTest(TestCase, OperationInitTest):          rel1, rel2 = self.create_relations()          self.operations[1].year = 2011          self.operations[1].save() +        reltype_key = pgettext_lazy("key for text search", u"relation-types")          search = { -            'search_vector': 'year=2010 relation-types="{}"'.format(rel2.name) +            'search_vector': 'year=2010 {}="{}"'.format( +                reltype_key, rel2.name)          }          response = c.get(reverse('get-operation'), search)          # no result when no authentification -        self.assertTrue(not json.loads(response.content)) +        self.assertTrue(not json.loads(response.content.decode()))          c.login(username=self.username, password=self.password)          response = c.get(reverse('get-operation'), search) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 2) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         2)      def test_search_with_problematic_characters(self):          c = Client() @@ -1894,26 +1901,28 @@ class OperationSearchTest(TestCase, OperationInitTest):          # no result when no authentication          response = c.get(reverse('get-operation'), search)          self.assertEqual(response.status_code, 200) -        self.assertTrue(not json.loads(response.content)) +        self.assertTrue(not json.loads(response.content.decode()))          c.login(username=self.username, password=self.password)          # one result for exact search          response = c.get(reverse('get-operation'), search)          self.assertEqual(response.status_code, 200) -        res = json.loads(response.content) +        res = json.loads(response.content.decode())          self.assertTrue(res['recordsTotal'] == 1)          # no result for the brother          search = {'periods': recent_neo.pk}          response = c.get(reverse('get-operation'), search)          self.assertEqual(response.status_code, 200) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 0) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         0)          # one result for the father          search = {'periods': neo.pk}          response = c.get(reverse('get-operation'), search)          self.assertEqual(response.status_code, 200) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 1) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         1)      def test_town_search(self):          c = Client() @@ -1937,19 +1946,22 @@ class OperationSearchTest(TestCase, OperationInitTest):          search = {'towns': base_town.pk}          response = c.get(reverse('get-operation'), search)          self.assertEqual(response.status_code, 200) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 1) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         1)          # parent search          search = {'towns': parent_town.pk}          response = c.get(reverse('get-operation'), search)          self.assertEqual(response.status_code, 200) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 1) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         1)          # child search          search = {'towns': child_town.pk}          response = c.get(reverse('get-operation'), search)          self.assertEqual(response.status_code, 200) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 1) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         1)  class OperationPermissionTest(TestCase, OperationInitTest): @@ -1988,22 +2000,26 @@ class OperationPermissionTest(TestCase, OperationInitTest):          # no result when no authentification          c = Client()          response = c.get(reverse('get-operation'), {'year': '2010'}) -        self.assertTrue(not json.loads(response.content)) +        self.assertTrue(not json.loads(response.content.decode()))          # possession          c = Client()          c.login(username=self.alt_username, password=self.alt_password)          response = c.get(reverse('get-operation'), {'year': '2010'})          # only one "own" operation available -        self.assertTrue(json.loads(response.content)) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 1) +        self.assertTrue(json.loads(response.content.decode())) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         1) +        operator_key = pgettext_lazy("key for text search", u"operator")          response = c.get(reverse('get-operation'), -                         {'operator': self.orgas[0].name}) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 1) +                         {operator_key: self.orgas[0].name}) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         1)          response = c.get(reverse('get-operation'), -                         {'search_vector': 'operator="{}"'.format( -                             self.orgas[0].name)}) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 1) +                         {'search_vector': '{}="{}"'.format( +                          operator_key, self.orgas[0].name)}) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         1)          # area filter          c = Client() @@ -2011,15 +2027,18 @@ class OperationPermissionTest(TestCase, OperationInitTest):          response = c.get(reverse('get-operation'),                           {'year': '2010'})          # only one "own" operation available -        self.assertTrue(json.loads(response.content)) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 1) +        self.assertTrue(json.loads(response.content.decode())) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         1)          response = c.get(reverse('get-operation'), -                         {'operator': self.orgas[0].name}) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 1) +                         {operator_key: self.orgas[0].name}) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         1)          response = c.get(reverse('get-operation'), -                         {'search_vector': 'operator="{}"'.format( -                             self.orgas[0].name)}) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 1) +                         {'search_vector': '{}="{}"'.format( +                          operator_key, self.orgas[0].name)}) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         1)      def test_own_modify(self):          operation_pk1 = self.operations[0].pk @@ -2088,7 +2107,7 @@ def create_administrativact(user, operation):      dct = {'history_modifier': user,             'act_type': act_type,             'operation': operation, -           'signature_date': datetime.date(2014, 05, 12), +           'signature_date': datetime.date(2014, 5, 12),             'index': 322}      adminact, created = models.AdministrativeAct.objects.get_or_create(**dct)      return [act_type], [adminact] @@ -2107,12 +2126,14 @@ class RegisterTest(TestCase, OperationInitTest):          c = Client()          response = c.get(reverse('get-administrativeact'), {'year': '2014'})          # no result when no authentication -        self.assertTrue(not json.loads(response.content)) +        self.assertTrue(not json.loads(response.content.decode()))          c.login(username=self.username, password=self.password)          response = c.get(reverse('get-administrativeact'), {'year': '2014'}) -        self.assertTrue(json.loads(response.content)['recordsTotal'] == 1) +        self.assertEqual( +            json.loads(response.content.decode())['recordsTotal'], 1)          response = c.get(reverse('get-administrativeact'), {'indexed': '2'}) -        self.assertTrue(json.loads(response.content)['recordsTotal'] == 1) +        self.assertEqual( +            json.loads(response.content.decode())['recordsTotal'], 1)      def test_document_generation(self):          tpl = open( @@ -2132,55 +2153,20 @@ class RegisterTest(TestCase, OperationInitTest):          data = {'pk': self.admin_acts[0].pk, 'document_template': doc.pk}          response = c.post(reverse('operation-administrativeact-document'), data)          # no result when no authentication -        self.assertEqual(response.content, "") +        self.assertEqual(response.content, b"")          c.login(username=self.username, password=self.password)          response = c.post(reverse('operation-administrativeact-document'), data)          try: -            f = StringIO.StringIO(response.content) +            f = BytesIO(response.content)              z = zipfile.ZipFile(f)              self.assertIsNone(z.testzip())              content = z.open('content.xml') -            self.assertIn('2014-05-12', content.read()) +            self.assertIn(b'2014-05-12', content.read())          finally:              content.close()              z.close()              f.close() -    def test_document_migration(self): -        fe = FileInit() -        fe.create_file() - -        from archaeological_files.tests import create_administrativact as ca_fle -        ca_fle(self.user, fe.item) - -        tpl = open( -            settings.ROOT_PATH + -            '../ishtar_common/tests/old.odt', -            'rb') -        template = SimpleUploadedFile(tpl.name, tpl.read()) -        doc = DocumentTemplate.objects.create( -            name="Old", -            associated_object_name=DocumentTemplate.CLASSNAMES[0][0], -            available=True, -            template=template -        ) -        self.act_types[0].associated_template.add(doc) - -        doc.convert_from_v1() -        with open(doc.template.path) as f: -            try: -                z = zipfile.ZipFile(f) -                self.assertIsNone(z.testzip()) -                c = z.open('content.xml') -                content = c.read() -                self.assertIn( -                    '{{ adminact_associated_file_in_charge_parcel_owner }}', -                    content -                ) -            finally: -                c.close() -                z.close() -  class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase):      fixtures = FILE_FIXTURES @@ -2691,18 +2677,21 @@ class SiteTest(TestCase, OperationInitTest):          search = {'search_vector': 'reference="reference-site"'}          response = c.get(reverse('get-site'), search)          # no result when no authentication -        self.assertTrue(not json.loads(response.content)) +        self.assertTrue(not json.loads(response.content.decode()))          c.login(username=self.username, password=self.password)          response = c.get(reverse('get-site'), search) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 1) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         1)          search = {'search_vector': 'reference="reference"'}          response = c.get(reverse('get-site'), search) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 0) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         0)          search = {'search_vector': 'reference="reference*"'}          response = c.get(reverse('get-site'), search) -        self.assertEqual(json.loads(response.content)['recordsTotal'], 1) +        self.assertEqual(json.loads(response.content.decode())['recordsTotal'], +                         1)  class GenerateQRCode(OperationInitTest, TestCase):  | 
