summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-04-02 16:38:18 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-17 13:21:27 +0200
commit4129fb1a79f4082466940c3d0b0ced7767697664 (patch)
treec67ac8afe2228a572272dcebe8853d5d82bad9af
parentaba701cfb26a9432cd306ba832a5357b0705ae01 (diff)
downloadIshtar-4129fb1a79f4082466940c3d0b0ced7767697664.tar.bz2
Ishtar-4129fb1a79f4082466940c3d0b0ced7767697664.zip
Tests: fix default conversion to str
-rw-r--r--archaeological_context_records/models.py2
-rw-r--r--archaeological_context_records/tests.py6
-rw-r--r--archaeological_files/models.py5
-rw-r--r--archaeological_finds/models_finds.py2
-rw-r--r--archaeological_finds/models_treatments.py8
-rw-r--r--archaeological_operations/tests.py12
-rw-r--r--archaeological_warehouse/models.py2
-rw-r--r--ishtar_common/models.py2
8 files changed, 25 insertions, 14 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 35899668c..128342b57 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -520,7 +520,7 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem,
return pgettext("short", "Context record")
def __str__(self):
- return self.short_label
+ return self.short_label or ""
def get_values(self, prefix='', no_values=False, no_base_finds=True):
values = super(ContextRecord, self).get_values(prefix=prefix,
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index aa98d83a8..764750cf6 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -293,6 +293,7 @@ class ContextRecordTest(ContextRecordInit, TestCase):
cr.location = "I am heeere"
cr.save()
cr = models.ContextRecord.objects.get(pk=cr.pk)
+ self.assertIsNotNone(cr.search_vector)
for key in ('label', 'heeer'):
self.assertIn(key, cr.search_vector)
cr.operation.code_patriarche = "PATRIARCHE"
@@ -300,12 +301,14 @@ class ContextRecordTest(ContextRecordInit, TestCase):
cr = models.ContextRecord.objects.get(pk=cr.pk)
profile = get_current_profile()
+ self.assertIsNotNone(cr.cached_label)
self.assertIn(profile.operation_prefix.lower() + "patriarch",
cr.search_vector)
def test_upstream_cache_update(self):
cr = self.create_context_record()[0]
cr_pk = cr.pk
+ self.assertIsNotNone(cr.cached_label)
# OP2010 - 1 | A | 1 | CR 1
ope_id, parcel_sec, parcel_nb, cr_label = cr.cached_label.split(' | ')
self.assertEqual(ope_id, 'OP2010-1')
@@ -317,6 +320,7 @@ class ContextRecordTest(ContextRecordInit, TestCase):
cr.label = new_lbl
cr.save()
cr = models.ContextRecord.objects.get(pk=cr_pk)
+ self.assertIsNotNone(cr.cached_label)
ope_id, parcel_sec, parcel_nb, cr_label = cr.cached_label.split(' | ')
self.assertEqual(cr_label, new_lbl)
@@ -326,6 +330,7 @@ class ContextRecordTest(ContextRecordInit, TestCase):
parcel.parcel_number = new_nb
parcel.save()
cr = models.ContextRecord.objects.get(pk=cr_pk)
+ self.assertIsNotNone(cr.cached_label)
ope_id, parcel_sec, parcel_nb, cr_label = cr.cached_label.split(' | ')
self.assertEqual(parcel_sec, new_sec)
self.assertEqual(parcel_nb, new_nb)
@@ -333,6 +338,7 @@ class ContextRecordTest(ContextRecordInit, TestCase):
cr.operation.year = 2017
cr.operation.save()
cr = models.ContextRecord.objects.get(pk=cr_pk)
+ self.assertIsNotNone(cr.cached_label)
ope_id, parcel_sec, parcel_nb, cr_label = cr.cached_label.split(' | ')
self.assertEqual(ope_id, 'OP2017-1')
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index 42951bdee..30393c80c 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -526,10 +526,7 @@ class File(ClosedItem, DocumentItem, BaseHistorizedItem, OwnPerms, ValueGetter,
return Parcel.render_parcels(list(self.parcels.all()))
def __str__(self):
- if self.cached_label:
- return self.cached_label
- self.save()
- return self.cached_label
+ return self.cached_label or ""
@property
def short_label(self):
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 011e10df1..7bd33018f 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -2344,4 +2344,4 @@ class Property(LightHistorizedItem):
verbose_name_plural = _(u"Properties")
def __str__(self):
- return self.person + settings.JOINT + self.find
+ return str(self.person) + settings.JOINT + str(self.find)
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py
index 572f002f2..996e03370 100644
--- a/archaeological_finds/models_treatments.py
+++ b/archaeological_finds/models_treatments.py
@@ -219,11 +219,7 @@ class Treatment(DashboardFormItem, ValueGetter, DocumentItem,
ordering = ("-year", "-index", "-start_date")
def __str__(self):
- if self.cached_label:
- return self.cached_label
- self.skip_history_when_saving = True
- self.save()
- return self.cached_label
+ return self.cached_label or ""
@property
def short_class_name(self):
@@ -994,7 +990,7 @@ class TreatmentFile(DashboardFormItem, ClosedItem, DocumentItem,
ordering = ('cached_label',)
def __str__(self):
- return self.cached_label
+ return self.cached_label or ""
@property
def short_class_name(self):
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 3da81a3bb..8eb2f361a 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -528,6 +528,7 @@ class ImportOperationTest(ImportTest, TestCase):
'4200-59350-YY55')
# cached_label update
ope2 = models.Operation.objects.get(code_patriarche='4201')
+ self.assertIsNotNone(ope2.cached_label)
self.assertIn('LILLE', ope2.cached_label.upper())
# delete associated parcel with the import deletion
parcel_count = models.Parcel.objects.count()
@@ -1178,6 +1179,7 @@ class OperationTest(TestCase, OperationInitTest):
def test_cache_update(self):
self.create_towns()
operation = self.operations[0]
+ self.assertIsNotNone(operation.cached_label)
town, ope_id = operation.cached_label.split(' | ')
self.assertIn(town, (u'Intercommunal', u"Multi-town"))
self.assertEqual(ope_id, 'OP2010-1')
@@ -1186,6 +1188,7 @@ class OperationTest(TestCase, OperationInitTest):
operation.save()
operation.towns.add(self.towns[0])
operation = models.Operation.objects.get(pk=operation.pk)
+ self.assertIsNotNone(operation.cached_label)
town, ope_id = operation.cached_label.split(' | ')
self.assertEqual(ope_id, 'OP2011-1')
self.assertEqual(town, self.towns[0].name)
@@ -1204,6 +1207,7 @@ class OperationTest(TestCase, OperationInitTest):
profile.save()
operation.code_patriarche = u"42HUIAAA5"
operation.save()
+ self.assertIsNotNone(operation.search_vector)
for key in (
'old', 'dirty', 'daisy', "'2010'", "zardoz", "huiaaa5",
"{}42huiaaa5".format(profile.operation_prefix.lower()),
@@ -1256,6 +1260,7 @@ class OperationTest(TestCase, OperationInitTest):
# verify the relevance of the update
cr = ContextRecord.objects.get(pk=cr.pk)
+ self.assertIsNotNone(cr.cached_label)
ope_id, parcel_sec, parcel_nb, cr_label = cr.cached_label.split(' | ')
profile = get_current_profile()
@@ -1266,6 +1271,7 @@ class OperationTest(TestCase, OperationInitTest):
op_code, idx = base_find.cache_short_id.split(' | ')
self.assertEqual(op_code, 'OP2011-1')
self.assertEqual(idx, '00001')
+ self.assertIsNotNone(base_find.cache_complete_id)
op_code, mat_code, lbl, idx = base_find.cache_complete_id.split(' | ')
self.assertEqual(op_code, 'OP2011-1')
self.assertEqual(mat_code, 'ADA')
@@ -1273,6 +1279,7 @@ class OperationTest(TestCase, OperationInitTest):
self.assertEqual(idx, '00001')
find = Find.objects.get(pk=find.pk)
+ self.assertIsNotNone(find.cached_label)
op_code_idx, lbl = find.cached_label.split(' | ')
self.assertEqual(op_code_idx, 'OP2011-1-00001')
self.assertEqual(lbl, 'Find me')
@@ -1281,17 +1288,21 @@ class OperationTest(TestCase, OperationInitTest):
operation.code_patriarche = '666'
operation.save()
cr = ContextRecord.objects.get(pk=cr.pk)
+ self.assertIsNotNone(cr.cached_label)
ope_id, parcel_sec, parcel_nb, cr_label = cr.cached_label.split(' | ')
self.assertEqual(ope_id, '{}666'.format(profile.operation_prefix))
base_find = BaseFind.objects.get(pk=base_find.pk)
+ self.assertIsNotNone(base_find.cache_short_id)
op_code, idx = base_find.cache_short_id.split(' | ')
self.assertEqual(op_code, 'OA666')
+ self.assertIsNotNone(base_find.cache_complete_id)
op_code, mat_code, lbl, idx = base_find.cache_complete_id.split(' | ')
self.assertEqual(op_code, 'OA666')
find = Find.objects.get(pk=find.pk)
+ self.assertIsNotNone(find.cached_label)
op_code_idx, lbl = find.cached_label.split(' | ')
self.assertEqual(op_code_idx, 'OA666-00001')
@@ -1435,6 +1446,7 @@ class OperationTest(TestCase, OperationInitTest):
"frog_number": 32303}
operation.save()
operation = models.Operation.objects.get(pk=operation.pk)
+ self.assertIsNotNone(operation.search_vector)
for key in ('marmott',):
self.assertIn(key, operation.search_vector)
for key in ('32303', 'red', 'Red'):
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index 756052f64..281bac296 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -559,7 +559,7 @@ class Container(DocumentItem, LightHistorizedItem, QRCodeItem, GeoItem,
)
def __str__(self):
- return self.cached_label
+ return self.cached_label or ""
def natural_key(self):
return (self.external_id, )
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index a17bcac03..4d699bfd8 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -3242,7 +3242,7 @@ class Town(Imported, models.Model):
return res
def __str__(self):
- return self.cached_label
+ return self.cached_label or ""
@property
def label_with_areas(self):