From 73b07c439730fc38f0f4cd13ed7d82f2d4ad37b4 Mon Sep 17 00:00:00 2001 From: delcroip Date: Thu, 28 Sep 2023 11:29:34 +0200 Subject: [PATCH 1/3] cache-user-disctrict --- core/schema.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/schema.py b/core/schema.py index ed499f56..4b0929c3 100644 --- a/core/schema.py +++ b/core/schema.py @@ -1267,6 +1267,8 @@ def async_mutate(cls, user, **data): data['validity_from'] = TimeUtils.now() data['audit_user_id'] = user.id_for_audit update_or_create_user(data, user) + cache.delete('user_disctrict_'+user.id) + return None except Exception as exc: return [ From d758df3e1150e2438cd08cc3fa7a783a7e0ef50e Mon Sep 17 00:00:00 2001 From: delcroip Date: Thu, 28 Sep 2023 12:03:11 +0200 Subject: [PATCH 2/3] fix --- core/schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/schema.py b/core/schema.py index 4b0929c3..b3213a1a 100644 --- a/core/schema.py +++ b/core/schema.py @@ -1267,7 +1267,7 @@ def async_mutate(cls, user, **data): data['validity_from'] = TimeUtils.now() data['audit_user_id'] = user.id_for_audit update_or_create_user(data, user) - cache.delete('user_disctrict_'+user.id) + cache.delete('user_disctrict_'+str(user.id)) return None except Exception as exc: From 78d28e0e2134e0010c2595d617710c199fe5ad6e Mon Sep 17 00:00:00 2001 From: delcroip Date: Wed, 4 Oct 2023 14:25:08 +0200 Subject: [PATCH 3/3] better helper --- core/test_helpers.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/core/test_helpers.py b/core/test_helpers.py index a7e3ebd4..87bcee1d 100644 --- a/core/test_helpers.py +++ b/core/test_helpers.py @@ -1,19 +1,35 @@ from core.models import Officer, InteractiveUser, User, TechnicalUser from core.services import create_or_update_user_roles +from uuid import uuid4 - -def create_test_officer(valid=True, custom_props=None): - officer = Officer.objects.create( - **{ - "code": "TSTOFF", +def create_test_officer(valid=True, custom_props={}): + code = custom_props.pop('code', None) + uuid = custom_props.pop('uuid', None) + qs_eo = Officer.objects + eo = None + data = { + "code": code or "TSTOFF", + "uuid":uuid, "last_name": "Officer", "other_names": "Test", "validity_to": None if valid else "2019-06-01", "audit_user_id": -1, **(custom_props if custom_props else {}) } - ) - return officer + if code: + qs_eo = qs_eo.filter(code=code) + if uuid: + qs_eo = qs_eo.filter(uuid=uuid) + + if code or uuid: + eo = qs_eo.first() + if eo: + data['uuid']=eo.uuid + eo.update(data) + return eo + else: + data['uuid']=uuid4() + return Officer.objects.create(**data) def create_test_interactive_user(username='TestInteractiveTest', password="Test1234", roles=None, custom_props=None):