Skip to content

Commit

Permalink
get rid of technical user
Browse files Browse the repository at this point in the history
  • Loading branch information
delcroip committed Sep 30, 2024
1 parent 0c96de3 commit 62aa164
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
11 changes: 5 additions & 6 deletions api_fhir_r4/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ def update(self, instance, validated_data):
raise NotImplementedError('`update()` must be implemented.') # pragma: no cover

def get_audit_user_id(self):
request = self.context.get("request")
# Taking the audit_user_id from the query doesn't seem wise but there might be a use for it
# audit_user_id = request.query_params.get('auditUserId', None)
audit_user_id = request.user.id_for_audit if request.user else None
if audit_user_id is None:
audit_user_id = GeneralConfiguration.get_default_audit_user_id()
# the audit user is the user
if self.user:
return self.user.audit_user_id or self.user._u.id
audit_user_id = GeneralConfiguration.get_default_audit_user_id()
if isinstance(audit_user_id, int):
return audit_user_id
else:
raise ValueError("User not available from the request for audit trail")
return self.__get_technical_audit_user(audit_user_id)

@property
Expand Down
14 changes: 5 additions & 9 deletions api_fhir_r4/tests/mixin/genericFhirAPITestMixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from fhir.resources.R4B.bundle import Bundle
from api_fhir_r4.utils import DbManagerUtils


from core.test_helpers import create_test_interactive_user
class GenericFhirAPITestMixin(object):

user = None
@property
def base_url(self):
return None
Expand All @@ -28,19 +28,20 @@ def _test_json_path(self):
def _test_json_path_credentials(self):
return None

_TEST_SUPERUSER_NAME = 'admin'
_TEST_SUPERUSER_NAME = 'admin_api'
_TEST_SUPERUSER_PASS = 'adminadmin'#'Admin123'
_test_request_data = None
_test_json_path_credentials = None

def setUp(self):
self.user = create_test_interactive_user(username=self._TEST_SUPERUSER_NAME)
dir_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
if self._test_json_path and self._test_request_data is None:
json_representation = open(dir_path + self._test_json_path).read()
self._test_request_data = json.loads(json_representation)
if self._test_json_path_credentials and self._test_request_data_credentials is None:
json_representation = open(dir_path + self._test_json_path_credentials).read()
self._test_request_data_credentials = json.loads(json_representation)
self._test_request_data_credentials = json.loads(json_representation)

def apply_replace_map(self , payload):
return payload
Expand Down Expand Up @@ -70,13 +71,8 @@ def get_response_details(self, response_json):

def login(self):
user = DbManagerUtils.get_object_or_none(User, username=self._TEST_SUPERUSER_NAME)
if user is None:
user = self.__create_superuser()
self.client.force_authenticate(user=user)

def __create_superuser(self):
User.objects.create_superuser(username=self._TEST_SUPERUSER_NAME, password=self._TEST_SUPERUSER_PASS)
return DbManagerUtils.get_object_or_none(User, username=self._TEST_SUPERUSER_NAME)

def get_bundle_from_json_response(self, response):
response_json = response.json()
Expand Down

0 comments on commit 62aa164

Please sign in to comment.