-
Notifications
You must be signed in to change notification settings - Fork 2
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
122 generate unique UUID #132
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
596a827
Change Physical_Type to type in locations_payload.json structure
TraciebelWairimu 3b02d8e
Merge branch 'main' of https://github.com/onaio/fhir-tooling
TraciebelWairimu 195ad6b
Merge branch 'main' of https://github.com/onaio/fhir-tooling
TraciebelWairimu 8b29af5
Merge branch 'main' of https://github.com/onaio/fhir-tooling
TraciebelWairimu cfbbcd8
Merge branch 'main' of https://github.com/onaio/fhir-tooling
TraciebelWairimu a1101c1
Generate unique uuid for locations
TraciebelWairimu eeb2039
Generate unique/repeatable uuid for build_org_affiliation and create_…
TraciebelWairimu 68c0775
Create tests to check if the generated unique_uuid is unique and repe…
TraciebelWairimu cc11b12
Remove imports that are not used
TraciebelWairimu eedffd0
Fix the test_uuid_generated_for_locations_is_unique_and_repeatable te…
TraciebelWairimu bcf7b4f
Refactor all the code in the create_user_resources function, destruct…
TraciebelWairimu cdc036d
Refactor test_main.py imports
TraciebelWairimu a967761
Refactor the code, destructure user and remove references by index
TraciebelWairimu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import json | ||
import unittest | ||
from jsonschema import validate | ||
from main import read_csv, build_payload, build_org_affiliation, extract_matches | ||
from main import read_csv, build_payload, build_org_affiliation, extract_matches, create_user_resources | ||
|
||
|
||
class TestMain(unittest.TestCase): | ||
|
@@ -187,6 +187,76 @@ def test_build_org_affiliation(self): | |
self.assertEqual(payload_obj["resourceType"], "Bundle") | ||
self.assertEqual(len(payload_obj["entry"]), 2) | ||
|
||
def test_uuid_generated_in_creating_user_resources_is_unique_and_repeatable(self): | ||
users = [['Jane', 'Doe', 'Janey', '[email protected]', '', 'Practitioner', 'TRUE', | ||
'a715b562-27f2-432a-b1ba-e57db35e0f93', 'test', 'demo', 'pa$$word'], | ||
['John', 'Doe', 'Janey', '[email protected]', '', 'Practitioner', 'TRUE', | ||
'a715b562-27f2-432a-b1ba-e57db35e0f93', 'test', 'demo', 'pa$$word'], | ||
['Janice', 'Doe', 'Jenn', '[email protected]', '99d54e3c-c26f-4500-a7f9-3f4cb788673f', 'Supervisor', | ||
'TRUE', 'a715b562-27f2-432a-b1ba-e57db35e0f93', 'test', 'demo', 'pa$$word']] | ||
|
||
users_uuids = {} | ||
for user_id, user in enumerate(users): | ||
payload = create_user_resources(user[4], user) | ||
payload_obj = json.loads(payload) | ||
practitioner_uuid = payload_obj["entry"][0]["resource"]["id"] | ||
group_uuid = payload_obj["entry"][1]["resource"]["id"] | ||
practitioner_role_uuid = payload_obj["entry"][2]["resource"]["id"] | ||
users_uuids[user_id] = [practitioner_uuid, group_uuid, practitioner_role_uuid] | ||
|
||
# practitioner_uuid | ||
self.assertEqual(users_uuids[0][0], users_uuids[1][0]) | ||
self.assertNotEqual(users_uuids[1][0], users_uuids[2][0]) | ||
|
||
# group_uuid | ||
self.assertEqual(users_uuids[0][1], users_uuids[1][1]) | ||
self.assertNotEqual(users_uuids[1][1], users_uuids[2][1]) | ||
|
||
# practitioner_role_uuid | ||
self.assertEqual(users_uuids[0][2], users_uuids[1][2]) | ||
self.assertNotEqual(users_uuids[1][2], users_uuids[2][2]) | ||
|
||
def test_uuid_generated_for_locations_is_unique_and_repeatable(self): | ||
resources = [ | ||
['City1', 'active', 'create', '', 'test location-1', '18fcbc2e-4240-4a84-a270-7a444523d7b6', 'jurisdiction', | ||
'jurisdiction'], | ||
['Building1', 'active', 'create', '', 'test location-1', '18fcbc2e-4240-4a84-a270-7a444523d7b6', 'building', | ||
'building'], | ||
['City1', 'active', 'create', '', 'test location-1', '18fcbc2e-4240-4a84-a270-7a444523d7b6', 'jurisdiction', | ||
'jurisdiction']] | ||
|
||
payload = build_payload("locations", resources, "json_payloads/locations_payload.json") | ||
payload_obj = json.loads(payload) | ||
location1 = payload_obj["entry"][0]["resource"]["id"] | ||
location2 = payload_obj["entry"][1]["resource"]["id"] | ||
location3 = payload_obj["entry"][2]["resource"]["id"] | ||
print(location1, location2, location3) | ||
|
||
self.assertNotEqual(location1, location2) | ||
self.assertEqual(location1, location3) | ||
|
||
def test_uuid_generated_in_build_org_affiliation_is_unique_and_repeatable(self): | ||
resource_list = [['HealthyU', 'a9137781-eb94-4d5f-8d39-471a92aec9f2', 'World', '138396'], | ||
['HealthyU', 'a9137781-eb94-4d5f-8d39-471a92aec9f2', 'Kenya', '54876'], | ||
['HealthyU', 'a9137781-eb94-4d5f-8d39-471a92aec9f2', 'Nairobi', '105167'], | ||
['One Org', '8342dd77-aecd-48ab-826b-75c7c33039ed', 'World', '138396']] | ||
|
||
resources = extract_matches(resource_list) | ||
payload = build_org_affiliation(resources, resource_list) | ||
payload_obj = json.loads(payload) | ||
organization_affiliation1 = payload_obj["entry"][0]["resource"]["id"] | ||
organization_affiliation2 = payload_obj["entry"][1]["resource"]["id"] | ||
|
||
self.assertNotEqual(organization_affiliation1, organization_affiliation2) | ||
|
||
payload2 = build_org_affiliation(resources, resource_list) | ||
payload2_obj = json.loads(payload2) | ||
organization_affiliation3 = payload2_obj["entry"][0]["resource"]["id"] | ||
organization_affiliation4 = payload2_obj["entry"][1]["resource"]["id"] | ||
|
||
self.assertEqual(organization_affiliation1, organization_affiliation3) | ||
self.assertEqual(organization_affiliation2, organization_affiliation4) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please refactor all the code in this function by destructuring user and removing references by index.
eg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done