def __lookup_basic(self, lookup_bool, input_json_str, response): work_orders = [] work_orders = self.kv_helper.lookup("workers") alter_items = [] alter_items = utility.list_difference(self.worker_pool, work_orders) for item in alter_items: self.worker_pool.remove(item) alter_items = utility.list_difference(work_orders, self.worker_pool) for item in alter_items: self.worker_pool.append(item) input_value = json.loads(input_json_str) total_count = 0 ids = [] lookupTag = "" for worker_id in self.worker_pool: if lookup_bool: if (worker_id == input_value["params"]["lookUpTag"]): lookup_bool = False continue else: continue value = self.kv_helper.get("workers", worker_id) json_dict = json.loads(value) checkcount = 0 actualcount = 0 if value: if "workerType" in input_json_str: checkcount = checkcount + 1 if int(json_dict["workerType"]) == int( input_value["params"]["workerType"]): actualcount = actualcount + 1 if "organizationId" in input_json_str: checkcount = checkcount + 1 if json_dict["organizationId"] == input_value["params"][ "organizationId"]: actualcount = actualcount + 1 if "applicationTypeId" in input_json_str: checkcount = checkcount + 1 if json_dict["applicationTypeId"] == input_value["params"][ "applicationTypeId"]: actualcount = actualcount + 1 if (checkcount == actualcount): total_count = total_count + 1 ids.append(worker_id) lookupTag = worker_id response["result"] = {} response["result"]["totalCount"] = total_count response["result"]["lookupTag"] = lookupTag response["result"]["ids"] = ids return response
def test_list_difference(self): """Tests to verify list_difference(list_1, list_2) function """ expected = [1, 3, 5, 7, 9] list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9] list2 = [2, 4, 6, 8] self.assertEquals(expected, list_difference(list1, list2)) list1 = [1, 3, 5, 7, 9] list2 = [2, 4, 6, 8] self.assertEquals(expected, list_difference(list1, list2)) expected = [] list1 = [1, 3, 5, 7, 9] list2 = [1, 3, 5, 7, 9] self.assertEquals(expected, list_difference(list1, list2)) expected = [] list1 = [] list2 = [1, 3, 5, 7, 9] self.assertEquals(expected, list_difference(list1, list2)) expected = [] list1 = [] list2 = [] self.assertEquals(expected, list_difference(list1, list2))
def __lookup_basics(self, lookup_bool, input_json_str, response): work_orders = [] work_orders = self.kv_helper.lookup("wo-receipts") alter_items = [] alter_items = utility.list_difference(self.receipt_pool, work_orders) for item in alter_items: self.receipt_pool.remove(item) alter_items = utility.list_difference(work_orders, self.receipt_pool) for item in alter_items: self.receipt_pool.append(item) input_value = json.loads(input_json_str) total_count = 0 ids = [] lookupTag = "" for wo_id in self.receipt_pool: if lookup_bool: if (wo_id == input_value["params"]["lastLookUpTag"]): lookup_bool = False continue else: continue value = self.kv_helper.get("wo-receipts", wo_id) json_dict = json.loads(value) checkcount = 0 actualcount = 0 if value: if 'workerServiceId' in input_json_str: checkcount = checkcount + 1 if json_dict["result"]["workerServiceId"] == input_value[ "params"]["workerServiceId"]: actualcount = actualcount + 1 if 'workerId' in input_json_str: checkcount = checkcount + 1 if json_dict["result"]["workerId"] == input_value[ "params"]["workerId"]: actualcount = actualcount + 1 if 'requesterId' in input_json_str: checkcount = checkcount + 1 if json_dict["result"]["requesterId"] == input_value[ "params"]["requesterId"]: actualcount = actualcount + 1 if 'status' in input_json_str: checkcount = checkcount + 1 if json_dict["result"]["receiptStatus"] == input_value[ "params"]["receiptStatus"]: actualcount = actualcount + 1 if (checkcount == actualcount): total_count = total_count + 1 ids.append(wo_id) lookupTag = wo_id response["result"] = {} response["result"]["totalCount"] = total_count response["result"]["lookupTag"] = lookupTag response["result"]["ids"] = ids return response