Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better helpers #219

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_'+str(user.id))

return None
except Exception as exc:
return [
Expand Down
30 changes: 23 additions & 7 deletions core/test_helpers.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down