def testGetAllImages(self): clinics = [] stations = [] patients = [] images = [] nclinics = 3 nstations = 4 npatients = 5 nimages = 1 for i in xrange(1, nclinics + 1): x = CreateClinic(host, port, token, "Ensenada", "{}/05/2016".format(i), "{}/06/2016".format(i)) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) self.assertTrue("id" in ret[1]) clinics.append(int(ret[1]["id"])) for j in xrange(1, nstations + 1): x = CreateStation(host, port, token, "Dental{}".format(j)) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) stations.append(int(ret[1]["id"])) for k in range(1, npatients + 1): data = {} data["paternal_last"] = "abcd1234{}".format(k) data["maternal_last"] = "yyyyyy" data["first"] = "zzzzzzz" data["middle"] = "" data["suffix"] = "Jr." data["prefix"] = "" data["dob"] = "04/01/1962" data["gender"] = "Female" data["street1"] = "1234 First Ave" data["street2"] = "" data["city"] = "Ensenada" data["colonia"] = "" data["state"] = u"Baja California" data["phone1"] = "1-111-111-1111" data["phone2"] = "" data["email"] = "*****@*****.**" data["emergencyfullname"] = "Maria Sanchez" data["emergencyphone"] = "1-222-222-2222" data["emergencyemail"] = "*****@*****.**" x = CreatePatient(host, port, token, data) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) patients.append(int(ret[1]["id"])) for i in clinics: for j in stations: for k in patients: for l in xrange(0, nimages): x = CreateImage(host, port, token) x.setPatient(k) x.setClinic(i) x.setStation(j) x.setType("Headshot") x.setData("ABCDEFG{}".format(l)) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) images.append(int(ret[1]["id"])) # query by invalid search terms x = GetImage(host, port, token) x.setClinic(9999) x.setStation(stations[0]) x.setPatient(patients[0]) x.setType("Headshot") ret = x.send(timeout=30) self.assertEqual(ret[0], 404) x = GetImage(host, port, token) x.setClinic(clinics[0]) x.setStation(9999) x.setPatient(patients[0]) x.setType("Headshot") ret = x.send(timeout=30) self.assertEqual(ret[0], 404) x = GetImage(host, port, token) x.setClinic(clinics[0]) x.setStation(stations[0]) x.setPatient(9999) x.setType("Headshot") ret = x.send(timeout=30) self.assertEqual(ret[0], 404) x = GetImage(host, port, token) x.setClinic(clinics[0]) x.setStation(stations[0]) x.setPatient(patients[0]) x.setType("yadda") ret = x.send(timeout=30) self.assertEqual(ret[0], 400) x = GetImage(host, port, token) x.setClinic(clinics[0]) x.setStation(stations[0]) x.setPatient(patients[0]) x.setSort("yadda") ret = x.send(timeout=30) self.assertEqual(ret[0], 400) x = GetImage(host, port, token) x.setClinic(clinics[0]) x.setStation(stations[0]) x.setPatient(patients[0]) x.setSort("False") ret = x.send(timeout=30) self.assertEqual(ret[0], 400) x = GetImage(host, port, token) x.setClinic(clinics[0]) x.setStation(stations[0]) x.setPatient(patients[0]) x.setSort("True") ret = x.send(timeout=30) self.assertEqual(ret[0], 400) x = GetImage(host, port, token) x.setClinic(clinics[0]) x.setStation(stations[0]) x.setPatient(patients[0]) x.setSort("false") ret = x.send(timeout=30) self.assertEqual(ret[0], 200) x = GetImage(host, port, token) x.setClinic(clinics[0]) x.setStation(stations[0]) x.setPatient(patients[0]) x.setSort("true") ret = x.send(timeout=30) self.assertEqual(ret[0], 200) sort = "true" for c in clinics: for s in stations: for p in patients: if sort == "true": sort = "false" else: sort = "true" # query by type x = GetImage(host, port, token) x.setPatient(p) x.setSort(sort) x.setType("Headshot") ret = x.send(timeout=30) self.assertEqual(ret[0], 200) # query by clinic x = GetImage(host, port, token) x.setClinic(c) x.setSort(sort) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) self.assertTrue(len(ret[1]) == len(images) / nclinics) # query by clinic and type x = GetImage(host, port, token) x.setSort(sort) x.setClinic(c) x.setType("Headshot") ret = x.send(timeout=30) self.assertEqual(ret[0], 200) self.assertTrue(len(ret[1]) == len(images) / nclinics) # query by station x = GetImage(host, port, token) x.setSort(sort) x.setStation(s) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) self.assertTrue(len(ret[1]) == (len(images) / nstations)) # query by station and type x = GetImage(host, port, token) x.setStation(s) x.setType("Headshot") ret = x.send(timeout=30) self.assertEqual(ret[0], 200) # query by clinic and station x = GetImage(host, port, token) x.setSort(sort) x.setClinic(c) x.setStation(s) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) self.assertTrue( len(ret[1]) == len(images) / (nclinics * nstations)) # query by clinic, station and type x = GetImage(host, port, token) x.setSort(sort) x.setClinic(c) x.setStation(s) x.setType("Headshot") ret = x.send(timeout=30) self.assertEqual(ret[0], 200) # query by clinic and patient x = GetImage(host, port, token) x.setSort(sort) x.setClinic(c) x.setPatient(p) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) self.assertTrue( len(ret[1]) == len(images) / (nclinics * npatients)) # query by clinic, patient and type x = GetImage(host, port, token) x.setSort(sort) x.setClinic(c) x.setPatient(p) x.setType("Headshot") ret = x.send(timeout=30) self.assertEqual(ret[0], 200) # query by clinic, station, and patient x = GetImage(host, port, token) x.setSort(sort) x.setClinic(c) x.setStation(s) x.setPatient(p) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) self.assertTrue( len(ret[1]) == len(images) / (nclinics * nstations * npatients)) # query by clinic, station, patient and type x = GetImage(host, port, token) x.setSort(sort) x.setClinic(c) x.setStation(s) x.setPatient(p) x.setType("Headshot") ret = x.send(timeout=30) self.assertEqual(ret[0], 200) for x in images: y = DeleteImage(host, port, token, x) ret = y.send(timeout=30) self.assertEqual(ret[0], 200) for x in patients: y = DeletePatient(host, port, token, x) ret = y.send(timeout=30) self.assertEqual(ret[0], 200) for x in stations: y = DeleteStation(host, port, token, x) ret = y.send(timeout=30) self.assertEqual(ret[0], 200) for x in clinics: y = DeleteClinic(host, port, token, x) ret = y.send(timeout=30) self.assertEqual(ret[0], 200)
def testDeleteImage(self): x = CreateClinic(host, port, token, "Ensenada", "02/05/2016", "02/06/2016") ret = x.send(timeout=30) self.assertEqual(ret[0], 200) self.assertTrue("id" in ret[1]) clinicid = int(ret[1]["id"]) x = CreateStation(host, port, token, "ENT") ret = x.send(timeout=30) self.assertEqual(ret[0], 200) stationid = int(ret[1]["id"]) data = {} data["paternal_last"] = "abcd1234" data["maternal_last"] = "yyyyyy" data["first"] = "zzzzzzz" data["middle"] = "" data["suffix"] = "Jr." data["prefix"] = "" data["dob"] = "04/01/1962" data["gender"] = "Female" data["street1"] = "1234 First Ave" data["street2"] = "" data["city"] = "Ensenada" data["colonia"] = "" data["state"] = u"Baja California" data["phone1"] = "1-111-111-1111" data["phone2"] = "" data["email"] = "*****@*****.**" data["emergencyfullname"] = "Maria Sanchez" data["emergencyphone"] = "1-222-222-2222" data["emergencyemail"] = "*****@*****.**" x = CreatePatient(host, port, token, data) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) patientid = int(ret[1]["id"]) x = CreateImage(host, port, token) x.setPatient(patientid) x.setClinic(clinicid) x.setStation(stationid) x.setType("Headshot") x.setData("ABCDEFG") # doesn't matter if it is actual image data ret = x.send(timeout=30) self.assertEqual(ret[0], 200) id = int(ret[1]["id"]) x = GetImage(host, port, token) x.setId(id) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) self.assertTrue("clinic" in ret[1]) clinicId = int(ret[1]["clinic"]) self.assertTrue(clinicId == clinicid) self.assertTrue("station" in ret[1]) stationId = int(ret[1]["station"]) self.assertTrue(stationId == stationid) self.assertTrue("patient" in ret[1]) patientId = int(ret[1]["patient"]) self.assertTrue(patientId == patientid) self.assertTrue("type" in ret[1]) self.assertTrue(ret[1]["type"] == "Headshot") self.assertTrue("data" in ret[1]) self.assertTrue(ret[1]["data"] == "ABCDEFG") x = DeleteImage(host, port, token, id) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) x = GetImage(host, port, token) x.setId(id) ret = x.send(timeout=30) self.assertEqual(ret[0], 404) # not found x = DeleteImage(host, port, token, id) ret = x.send(timeout=30) self.assertEqual(ret[0], 404) x = DeleteImage(host, port, token, "") ret = x.send(timeout=30) self.assertEqual(ret[0], 400) x = DeleteImage(host, port, token, 9999) ret = x.send(timeout=30) self.assertEqual(ret[0], 404) x = DeleteImage(host, port, token, None) ret = x.send(timeout=30) self.assertEqual(ret[0], 404) x = DeletePatient(host, port, token, patientid) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) x = DeleteStation(host, port, token, stationid) ret = x.send(timeout=30) self.assertEqual(ret[0], 200) x = DeleteClinic(host, port, token, clinicid) ret = x.send(timeout=30) self.assertEqual(ret[0], 200)