class ehbTestClass(TestCase): ''' The ehbTestClass is a base class for all ehb-client tests. Its main purpose is to create test objects for our different request handlers to manipulate, and to tear down those objects when the tests are finished. In the rare case that the setUp of a test class fails you may be left with artifacts in the eHB. Make sure to delete any "test" organizations left over and try running the tests again. ''' def setUp(self): # Initialize Request Handlers self.er_rh = ExternalRecordRequestHandler( RequestResources.host, RequestResources.root_path, RequestResources.isSecure, RequestResources.api_key) self.es_rh = ExternalSystemRequestHandler( RequestResources.host, RequestResources.root_path, RequestResources.isSecure, RequestResources.api_key) self.s_rh = SubjectRequestHandler( RequestResources.host, RequestResources.root_path, RequestResources.isSecure, RequestResources.api_key) self.g_rh = GroupRequestHandler( RequestResources.host, RequestResources.root_path, RequestResources.isSecure, RequestResources.api_key) self.o_rh = OrganizationRequestHandler( RequestResources.host, RequestResources.root_path, RequestResources.isSecure, RequestResources.api_key) self.es_name1 = "testESNameABCD" self.es_name2 = "testESName1234" self.org_subj_id_1 = "testmrn0001" self.org_subj_id_2 = "testmrn0002" self.org_subj_id_3 = "testmrn002" self.recid1 = "testrecid0001" self.recid2 = "testrecid0002" self.recid3 = "testrecid0003" self.recid4 = "testrecid0004" self.path1 = "testpath1" self.path2 = "testpath2" self.path3 = 'testpath3' self.org_name_1 = "testOrg001" self.org_name_2 = "testOrg002" self.subj_id_label_1 = 'org_1_id' try: # Create the Organizations self.o1 = Organization(name=self.org_name_1, subject_id_label=self.subj_id_label_1) self.o2 = Organization(name=self.org_name_2, subject_id_label=self.subj_id_label_1) r = self.o_rh.create(self.o1, self.o2) # Create Subjects dob = datetime.date.today() self.s1 = Subject(first_name='FIRST_ONE', last_name="LAST_ONE", organization_id=self.o1.id, organization_subject_id=self.org_subj_id_1, dob=dob) self.s2 = Subject(first_name='FIRST_TWO', last_name="LAST_TWO", organization_id=self.o1.id, organization_subject_id=self.org_subj_id_2, dob=dob) self.s3 = Subject(first_name='FIRST_THREE', last_name="LAST_THREE", organization_id=self.o2.id, organization_subject_id=self.org_subj_id_3, dob=dob) r = self.s_rh.create(self.s1, self.s2, self.s3) # Create External Systems self.es1 = ExternalSystem(name=self.es_name1, url="http://test.com/", description='A test system') self.es2 = ExternalSystem(name=self.es_name2, url="http://testTwo.com/", description='Another test system') r = self.es_rh.create(self.es1, self.es2) # Create External record self.er1 = ExternalRecord(record_id=self.recid1, subject_id=self.s1.id, external_system_id=self.es1.id, path=self.path1, label_id=1) self.er2 = ExternalRecord(record_id=self.recid2, subject_id=self.s1.id, external_system_id=self.es1.id, path=self.path2, label_id=1) r = self.er_rh.create(self.er1, self.er2) self.er1 = r[0]['external_record'] self.er2 = r[1]['external_record'] # # Create External record link r = self.er_rh.link(self.er1, self.er2, 1) # Create test groups # Subject Group self.g1 = Group(name='testgroup1', is_locking=False, client_key='ck', description='A test group') # ExternalRecord Group self.g2 = Group(name='exrecgroup', is_locking=False, client_key='ck', description='An external record group') r = self.g_rh.create(self.g1, self.g2) # Add subject to test group r = self.g_rh.add_subjects(self.g1, [self.s1]) # Add external record to test group r = self.g_rh.add_records(self.g2, [self.er1]) except: pass def tearDown(self): try: self.es_rh.delete(name=self.es_name1) except PageNotFound: pass try: self.es_rh.delete(name=self.es_name2) except PageNotFound: pass try: self.es_rh.delete(name='testESNameCreate') except PageNotFound: pass try: o1 = self.o_rh.get(name=self.org_name_1) self.s_rh.delete(organization_id=o1.id, organization_subject_id=self.org_subj_id_1) self.s_rh.delete(organization_id=o1.id, organization_subject_id=self.org_subj_id_2) except PageNotFound: pass try: o2 = self.o_rh.get(name=self.org_name_2) self.s_rh.delete(organization_id=o2.id, organization_subject_id=self.org_subj_id_3) except PageNotFound: pass try: self.er_rh.delete(external_system_name=self.es_name1) except PageNotFound: pass try: self.er_rh.delete(external_system_name=self.es_name2) except PageNotFound: pass try: self.o_rh.delete(name=self.org_name_1) except PageNotFound: pass try: self.o_rh.delete(name=self.org_name_2) except PageNotFound: pass try: self.o_rh.delete(name='testorg1') except PageNotFound: pass try: self.o_rh.delete(name='testorg2') except PageNotFound: pass try: self.o_rh.delete(name='testorg99') except PageNotFound: pass try: self.er_rh.create(self.er1) except PageNotFound: pass try: self.g_rh.delete(name='testgroup1', client_key='ck') except PageNotFound: pass try: self.g_rh.delete(name='exrecgroup', client_key='ck') except PageNotFound: pass try: self.g_rh.delete(name='testgroup2', client_key='ck') except PageNotFound: pass try: self.g_rh.delete(name='testgroup3', client_key='ck') except PageNotFound: pass try: self.g_rh.delete(name='testgroup1xyz', client_key='ck') except PageNotFound: pass def createAndCheck(self, rh, *records): r = rh.create(*records) b = True for i in range(r.__len__()): b = b and r[i].get('success') self.assertTrue(b, 'External record create failed')