-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 121-multiple-location-types
- Loading branch information
Showing
2 changed files
with
179 additions
and
24 deletions.
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,144 @@ 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() |