def __init__(self, toward): Item.__init__(self) self.toward = toward self.heuristic = float("inf") self.h_toward = -1 # Up to down is 0,down to up is 1 self.current = self.WAIT_TIME self.is_pass = False
def fixItemId(self): if len(self.__items) > 0: max = 0 for item in self.__items: if max <= item.getId(): max = item.getId() + 1 Item.setItemId(max)
def service(self) -> None: item_a: Item = Item("Hula Hoop", 65) item_b: Item = Item("Mars Bars", 100) item_c: Item = Item("Coke Zero", 150) self.item_slots['A'] = [item_a] * 2 self.item_slots['B'] = [item_b] * 2 self.item_slots['C'] = [item_c] * 2 self.machine_stack.add_to_stack(50, 50, 50, 50)
def __init__(self): self.id = 3 self.total_price = 12.99 self.delivered = True self.issued = True self.paid = False # right now, it is storing the items in a list where the item objects in the list are in a JSON string format" # because the issue with converting an object like Invoice into a string # is that the inner objects are not 'serializable' item = Item("cocacola", 12.33, 2) item2 = Item("cocacoladiet", 12.66, 5) self.items = [json.dumps(vars(item)), json.dumps(vars(item2))]
def post(self, project_key): project_key = cgi.escape(project_key) project = Project.get(project_key) print project name = cgi.escape(self.request.get('name')) print name description = cgi.escape(self.request.get('description')) print description item = Item(name= name, description= description, project= project) item.put() self.response.out.write('ok')
def get_substitutes(cat_id, nutriscore): cursor_wrapper = CursorWrapper() sql = f"SELECT * FROM PurBeurre.foods WHERE category_id={cat_id} AND nutriscore < '{nutriscore}' ORDER BY nutriscore;" with cursor_wrapper as cursor: cursor.execute(sql, commit=False) item_list = cursor.fetchall() items = [] for item in item_list: item_dict = { 'food_id': item[0], 'category_id': item[1], 'name': item[2], 'ingredients': item[3], 'additives': item[4], 'nutrients': item[6], 'nutriscore': item[5], 'labels': item[7], 'stores': item[8], 'barcode': item[9], 'url': item[10], 'favourite': is_favourite_in_db(item[0]) } food = Item(item_dict) items.append(food) return items
def scrapFromXkom(productQuery: str): url = xKomUrl + "szukaj?q=" + productQuery.replace(" ", "%20") soup = responseXkom(url) aResults = soup.find_all("a", class_="sc-1h16fat-0 sc-1yu46qn-10 dFAarG", href=True) for a in aResults: print(a["href"]) if len(aResults) < 1: print("Nie znaleziono przedmiotu!") return 0 productUrl = xKomUrl + str(aResults[0]["href"]).replace("/", "", 1) print(productUrl) soupProduct = responseXkom(productUrl) global producentCode for div in soupProduct.find_all("div", class_="sc-bwzfXH sc-13p5mv-0 cwztyD sc-htpNat gSgMmi"): t = (div.find("div", class_="sc-13p5mv-1").text, div.find("div", class_="sc-13p5mv-3").text) if t[0] == "Kod producenta": producentCode = t[1] productAvailable = False global productImage productImage = soupProduct.find("meta", property="og:image")["content"] if soupProduct.find("meta", property="og:image") is not None else "" if soupProduct.find("span", class_="sc-1hdxfw1-1 cMQxDU") is not None: productAvailable = True return Item("x-kom", str.lstrip(soupProduct.find("h2", class_="text-left").text if soupProduct.find("h2", class_="text-left") is not None else "Brak danych"), soupProduct.find("div", class_="u7xnnm-4 iVazGO").text if soupProduct.find("div", class_="u7xnnm-4 iVazGO") is not None else "Brak danych", productAvailable, productUrl, productImage)
def scrapFromMorele(productQuery: str): global producentCode url = moreleUrl + "wyszukiwarka/0/0/,,1,,,,,,,,,,/1/?q=" + producentCode soupProduct = responseMorele(url) print(producentCode) print(url) if soupProduct.find("h1", class_="prod-name") is None: return scrapFromMoreleIfRedirect(productQuery) productAvailable = True if soupProduct.find("div", class_="prod-available-items") is None: productAvailableString = "0" else: productAvailableString = soupProduct.find("div", class_="prod-available-items").text productAvailableString = productAvailableString.replace("\n", "") if len(productAvailableString) != 0: for r in (("Dostępnych", ""), ("szt.", ""), (" ", ""), ("Zostało", ""), ("tylko", ""), ("Została", "")): productAvailableString = productAvailableString.replace(*r) if productAvailableString is None or int(productAvailableString) < 1 or len(productAvailableString) <= 0: productAvailable = False else: productAvailable = False return Item("Morele.net", soupProduct.find("h1", class_="prod-name").text if soupProduct.find("h1", class_="prod-name") is not None else "Brak danych", soupProduct.find_all("div", class_="product-price")[0]["data-default"] if len( soupProduct.find_all("div", class_="product-price")) > 0 else "Brak danych", productAvailable, url, "")
def deleteItem(self, id, count, type): with open('controller/item.json', 'r') as outfile: data = json.load(outfile) for i in range(len(data)): if data[i]["_id"] == id: if int(count) > 0: diff = int(data[i]["_count"]) - int(count) if diff >= 0: item = Item(self._customerManager.getBucketListSize(), data[i]["_title"], data[i]["_price"], count) if type == "customer": self._customerManager.addToBucket(item) data[i]["_count"] = diff elif type == "": data[i]["_count"] = diff else: printWriter = PrintWriter.getInstance() printWriter.printNoItem() # else: # item = Item(self._customerManager.getBucketListSize(), data[i]["_title"], data[i]["_price"], data[i]["_count"]) # self._customerManager.addToBucket(item) # data[i]["_count"] = 0 with open('controller/item.json', 'w') as outfile: json.dump(data, outfile, indent=4) break
def btnAddActionPerformed(self): customerId = self.__txtCustomerId.get() itemId = self.__txtItemId.get() number = self.__txtNumber.get() employeeId = self.__txtEmployeeId.get() if len(customerId) > 0 and len(itemId) > 0 and len(number) > 0 and len( employeeId) > 0: try: customer = Customer(customerId, "", "", "") item = Item(itemId, "", "", "") employee = Employee(employeeId, "", "", "", "") if self.__customers.__contains__(customer) \ and self.__items.__contains__(item) and\ self.__employees.__contains__(employee): cIndex = self.__customers.index(customer) iIndex = self.__items.index(item) eIndex = self.__employees.index(employee) transaction = Transaction("", self.__customers[cIndex], self.__items[iIndex], number, self.__employees[eIndex]) transaction.fixId() self.__parent.addTransactionCallBack(transaction) messagebox.showinfo("Success", "A new transaction has been added") self.showDefaultText() else: messagebox.showerror("Error", "This information does not exist!") except Exception: messagebox.showerror("Error", "Invalid information format!") else: messagebox.showerror("Error", "Input fields cannot be left blank!")
def get_foods_as_list_of_objects(category_id): cursor_wrapper = CursorWrapper() sql = "SELECT * FROM foods WHERE category_id = {}".format(category_id) with cursor_wrapper as cursor: cursor.execute(sql, commit=False) foods_tuple = cursor.fetchall() foods = [] for item in foods_tuple: food_dict = { 'food_id': item[0], 'category_id': item[1], 'name': item[2], 'ingredients': item[3], 'additives': item[4], 'nutrients': item[6], 'nutriscore': item[5], 'labels': item[7], 'stores': item[8], 'barcode': item[9], 'url': item[10], 'favourite': is_favourite_in_db(item[0]) } food = Item(food_dict) foods.append(food) return foods
def __init__(self): with open('controller/item.json', 'r') as outfile: data = json.load(outfile) self._customerManager = CustomerManager() for jsondict in data: item = Item(len(self._itemList), jsondict["_title"], jsondict["_price"], jsondict["_count"]) self._itemList.append(item)
def getBucketCustomer(self): list = [] with open('controller/bucket.json', 'r') as outfile: data = json.load(outfile) for jsondict in data: item = Item(len(list), jsondict["_title"], jsondict["_price"], jsondict["_count"]) list.append(item) return list
def readItemTable(self): self.__items = [] sql = "SELECT * FROM items" self.__cursor.execute(sql) records = self.__cursor.fetchall() for row in records: item = Item(str(row[0]), row[1], row[2], str(row[3])) self.__items.append(item) return self.__items
def getList(self): json_dict = [] with open('controller/item.json', 'r') as outfile: data = json.load(outfile) for jsondict in data: item = Item(len(json_dict), jsondict["_title"], jsondict["_price"], jsondict["_count"]) json_dict.append(item) return json_dict
def btnAddActionPerformed(self): name = self.__txtName.get() brand = self.__txtBrand.get() price = self.__txtPrice.get() if len(name) > 0 and len(brand) > 0 and len(price) > 0: try: item = Item("", name, brand, price) if self.__items.__contains__(item): messagebox.showerror("Error", "Item information already exists!") else: item.fixId() self.__parent.addItemCallBack(item) messagebox.showinfo("Success", "A new item has been added") self.showDefaultText() except Exception: messagebox.showerror("Error", "Invalid information format!") else: messagebox.showerror("Error", "Input fields cannot be left blank!")
def searchItemById(self, itemId): self.__items = [] sql = "SELECT * FROM items WHERE id = %s" val = (itemId, ) self.__cursor.execute(sql, val) records = self.__cursor.fetchall() for row in records: item = Item(str(row[0]), row[1], row[2], str(row[3])) self.__items.append(item) return self.__items
def searchItemByPrice(self, price): self.__items = [] sql = "SELECT * FROM items WHERE price LIKE %s" val = ("%" + price + "%", ) self.__cursor.execute(sql, val) records = self.__cursor.fetchall() for row in records: item = Item(str(row[0]), row[1], row[2], str(row[3])) self.__items.append(item) return self.__items
def scrapFromMoreleIfRedirect(productQuery: str): url = moreleUrl + "wyszukiwarka/0/0/,,,,,,,,,,,,/1/?q=" + productQuery.replace(" ", "+") soup = responseMorele(url) print(url) aResults = soup.find_all("a", class_="productLink", href=True) for a in aResults: print(a["href"]) if len(aResults) < 1: print("Nie znaleziono przedmiotu! [Redirect]") showdialog("Nie znaleziono przedmiotu! [Redirect]") return Item("Morele.net", "Brak danych", "0 zł", False, "", "") productUrl = moreleUrl + str(aResults[0]["href"]).replace("/", "", 1) print(productUrl) soupProduct = responseMorele(productUrl) productAvailable = True if soupProduct.find("div", class_="prod-available-items") is None: productAvailableString = "0" else: productAvailableString = soupProduct.find("div", class_="prod-available-items").text if len(productAvailableString) > 4: for r in (("Dostępnych", ""), ("szt.", ""), (" ", ""), ("Zostało", ""), ("tylko", ""), ("Została", "")): productAvailableString = productAvailableString.replace(*r) if productAvailableString is None or int(productAvailableString) < 1: productAvailable = False else: productAvailable = False return Item("Morele.net", soupProduct.find("h1", class_="prod-name").text if soupProduct.find("h1", class_="prod-name") is not None else "Brak danych", soupProduct.find_all("div", class_="product-price")[0]["data-default"] if soupProduct.find_all("div", class_="product-price")[0]["data-default"] is not None else "Brak danych", productAvailable, productUrl, "")
def update(self, item_id): item_dict = dbread.get_item(item_id) self.item = Item(item_dict) self.name.text = self.item.food_name self.ingredients.text = self.item.ingredients self.additives.text = self.item.additives self.nutriscore.text = self.item.nutriscore self.nutrients.text = self.item.nutrients self.labels.text = self.item.labels self.stores.text = self.item.stores self.barcode.text = str(self.item.barcode) self.url.text = "lien vers Open Food Facts" self.favourite_btn.text = "supprimer des favoris" if self.item.favourite else "ajouter aux favoris"
def btnEditActionPerformed(self): name = self.__txtName.get() brand = self.__txtBrand.get() price = self.__txtPrice.get() if len(name) > 0 and len(brand) > 0 and len(price) > 0: try: item = Item(str(self.__item.getId()), name, brand, price) self.__parent.editItemCallBack(item) self.__editItemWindow.destroy() messagebox.showinfo("Success", "Item information has been edited") except Exception: messagebox.showerror("Error", "Invalid information format!") else: messagebox.showerror("Error", "Input fields cannot be left blank!")
def __init__(self, item_id=None): super().__init__() if item_id: item_dict = dbread.get_item(item_id) item_dict['favourite'] = dbread.is_favourite_in_db( item_dict['food_id']) self.item = Item(item_dict) self.name.text = self.item.food_name self.ingredients.text = self.item.ingredients self.additives.text = self.item.additives self.nutriscore.text = self.item.nutriscore self.nutrients.text = self.item.nutrients self.labels.text = self.item.labels self.stores.text = self.item.stores self.barcode.text = str(self.item.barcode) self.url.text = "lien vers Open Food Facts" self.favourite_btn.text = "supprimer des favoris" if self.item.favourite else "ajouter aux favoris"
def get(self, project_key): project_key = cgi.escape(project_key) project = Project.get(project_key) print project items = Item.all() items.filter('project =', project) items.run() json = jsonize() items_list = [] for item in items: items_list.append(json.to_dict(item)) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(items_list)
def post(self, project_key): project_key = cgi.escape(project_key) project = Project.get(project_key) ItemKey = cgi.escape(self.request.get('ItemKey')) items = Item.all() Items.filter('project =', project) Items.filter('__key__= ', ItemKey) Items.run() item = Items.fetch(1) if item: item[0].delete() self.response.out.write('ok') else: self.response.out.write('fail')
def readTransactionTable(self): self.__transactions = [] sql = "SELECT * FROM transactions" self.__cursor.execute(sql) records = self.__cursor.fetchall() for row in records: id = str(row[0]) customerId = str(row[1]) itemId = str(row[3]) number = str(row[5]) employeeId = str(row[7]) cIndex = self.__customers.index(Customer(customerId, "", "", "")) iIndex = self.__items.index(Item(itemId, "", "", "")) eIndex = self.__employees.\ index(Employee(employeeId, "", "", "", "")) transaction = Transaction(id, self.__customers[cIndex], self.__items[iIndex], number, self.__employees[eIndex]) self.__transactions.append(transaction) return self.__transactions
def test_item_creation(): item = Item("Mars Bar", 65) assert item.name == "Mars Bar" assert item.price == 65
def adminCheck(login, password): # check if login pass true----------------- if shopManager.checkAdmin(login, password): printWriter.helloAdmin(shopManager.getNameOfAdmin(login, password)) modifyingOperation = 1 while modifyingOperation is not 0: while True: try: modifyingOperation = int(input(printWriter.welcomeAdmin())) break except: print("Please enter one of these numbers: 0,1,2,3,4 ") if modifyingOperation == 0: break elif modifyingOperation == 1: printWriter.seeAllItems(shopManager.getItemList()) elif modifyingOperation == 2: printWriter.seeAllWorkers(shopManager.getWorkerList()) elif modifyingOperation == 3: while True: while True: try: choose = int(input(printWriter.modifyItemPrint())) break except: print("Please enter one of these numbers: 0,1,2,3") if choose == 0: break elif choose == 1: while True: while True: titleModify = input( printWriter.itemTitlePrint()) if titleModify == "": print("Title can't be empty. Try again") else: break while True: try: priceModify = int( input(printWriter.itemPricePrint())) if priceModify <= 0 or priceModify > 1000000000: print("Price must be more than 0") else: break except: print("Price must be an integer") while True: try: countModify = int( input(printWriter.itemCountPrint())) if countModify <= 0 or countModify > 1000000000: print("Count must be more than 0") else: break except: print("Count must be an integer") id = len(shopManager.getItemManager().getList()) shopManager.getItemManager().addItem( Item(id, titleModify, priceModify, countModify)) printWriter.seeAllItems(shopManager.getItemList()) titleModify = None priceModify = None countModify = None any = input(printWriter.addAnythingElse()) if any == "n": break elif any is not "y": print( "Pleases enter 'y' for 'yes' or 'n' for 'no'" ) # edit item--------------------------- elif choose == 2: printWriter.seeAllItems(shopManager.getItemList()) while True: try: enteredId = int(input(printWriter.idPrint())) if enteredId < 0 or enteredId >= len( shopManager.getItemList()): print("Id must be more than 0") else: break except: print("Id must be an integer") while True: try: editItemField = int( input(printWriter.editItem())) if editItemField <= 0: print( "Please enter one of these numbers: 0,1,2,3" ) break except: print( "Please enter one of these numbers: 0,1,2,3" ) if editItemField == 0: break elif editItemField == 1: title = input(printWriter.itemTitlePrint()) shopManager.getItemManager().editItemTitle( enteredId, title) enteredId = None title = None any = input(printWriter.editAnythingElse()) if any == "n": break elif any is not "y": print( "Pleases enter 'y' for 'yes' or 'n' for 'no'" ) elif editItemField == 2: while True: try: price = int( input(printWriter.itemPricePrint())) if price <= 0 or price > 1000000000: print("Price must be more than 0") break except: print("Price must be must be an integer") shopManager.getItemManager().editItemPrice( enteredId, price) enteredId = None price = None any = input(printWriter.editAnythingElse()) if any == "n": break elif any is not "y": print( "Pleases enter 'y' for 'yes' or 'n' for 'no'" ) elif editItemField == 3: while True: try: count = int( input(printWriter.itemCountPrint())) if count <= 0 or count > 1000000000: print("Count must be more than 0") break except: print("Count must be must be an integer") shopManager.getItemManager().editItemCount( enteredId, count) printWriter.seeAllItems(shopManager.getItemList()) enteredId = None count = None any = input(printWriter.editAnythingElse()) if any == "n": break elif any is not "y": print( "Pleases enter 'y' for 'yes' or 'n' for 'no'" ) # remove item------------------------- elif choose == 3: printWriter.seeAllItems(shopManager.getItemList()) while True: try: enteredId = int(input(printWriter.idPrint())) if enteredId < 0 or enteredId >= len( shopManager.getItemList()): print("Id must be more than 0") else: break except: print("Id must be an integer") while True: try: count = int(input( printWriter.itemCountPrint())) if count <= 0 or count > 1000000000: print("Count must be more than 0") break except: print("Count must be must be an integer") shopManager.getItemManager().deleteItem( enteredId, count, "") printWriter.seeAllItems(shopManager.getItemList()) enteredId = None count = None any = input(printWriter.removeAnythingElse()) if any == "n": break elif any is not "y": print( "Pleases enter 'y' for 'yes' or 'n' for 'no'") elif modifyingOperation == 4: while True: while True: try: chooseWorker = int( input(printWriter.modifyWorkerPrint())) break except: print("Please enter one of these numbers: 0,1,2,3") if chooseWorker == 0: break elif chooseWorker == 1: while True: while True: workerName = input( printWriter.workerNamePrint()) if workerName == "": print("Name can't be empty. Try again") else: break while True: workerSurname = input( printWriter.workerSurnamePrint()) if workerSurname == "": print("Surname can't be empty. Try again") else: break while True: try: workerAge = int( input(printWriter.workerAgePrint())) if workerAge <= 0 or workerAge > 100: print("Age must be more than 0") else: break except: print("Age must be an integer") while True: try: workerSalary = int( input(printWriter.workerSalaryPrint())) if workerSalary <= 0 or workerSalary > 100000000: print("Salary must be more than 0") else: break except: print("Salary must be an integer") id = len(shopManager.getWorkerManager().getList()) shopManager.getWorkerManager().addWorker( Worker(id, workerName, workerSurname, workerAge, workerSalary)) printWriter.seeAllWorkers( shopManager.getWorkerList()) workerName = None workerSalary = None workerSurname = None workerAge = None any = input(printWriter.addOtherWorker()) if any == "n": break elif any is not "y": print( "Please enter 'y' for 'yes' or 'n' for 'no'" ) # edit worker--------------------------- elif chooseWorker == 2: printWriter.seeAllWorkers(shopManager.getWorkerList()) while True: try: enteredId = int(input(printWriter.idPrint())) if enteredId < 0 or enteredId >= len( shopManager.getWorkerList()): print("Id must be more than 0") else: break except: print("Id must be an integer") while True: try: editWorkerField = int( input(printWriter.editWorker())) if editWorkerField <= 0: print( "Please enter one of these numbers: 0,1,2,3,4" ) break except: print( "Please enter one of these numbers: 0,1,2,3,4" ) if editWorkerField == 0: break elif editWorkerField == 1: name = input(printWriter.workerNamePrint()) shopManager.getWorkerManager().editWorkerName( enteredId, name) enteredId = None name = None any = input(printWriter.editOtherWorker()) if any == "n": break elif any is not "y": print( "Please enter 'y' for 'yes' or 'n' for 'no'" ) elif editWorkerField == 2: surname = input(printWriter.workerSurnamePrint()) shopManager.getWorkerManager().editWorkerName( enteredId, surname) enteredId = None surname = None any = input(printWriter.editOtherWorker()) if any == "n": break elif any is not "y": print( "Please enter 'y' for 'yes' or 'n' for 'no'" ) elif editWorkerField == 3: while True: try: age = int( input(printWriter.workerAgePrint())) if age <= 0 or age > 100: print("Age must be more than 0") break except: print("Age must be must be an integer") shopManager.getWorkerManager().editWorkerAge( enteredId, age) printWriter.seeAllWorkers( shopManager.getWorkerList()) enteredId = None age = None any = input(printWriter.editOtherWorker()) if any == "n": break elif any is not "y": print( "Please enter 'y' for 'yes' or 'n' for 'no'" ) elif editWorkerField == 4: while True: try: salary = int( input(printWriter.workerSalaryPrint())) if salary <= 0 or salary > 1000000000: print("Salary must be more than 0") break except: print("Salary must be must be an integer") shopManager.getWorkerManager().editWorkerSalary( enteredId, salary) printWriter.seeAllWorkers( shopManager.getWorkerList()) enteredId = None salary = None any = input(printWriter.editOtherWorker()) if any == "n": break elif any is not "y": print( "Please enter 'y' for 'yes' or 'n' for 'no'" ) # remove worker------------------------- elif chooseWorker == 3: printWriter.seeAllWorkers(shopManager.getWorkerList()) while True: try: enteredId = int(input(printWriter.idPrint())) if enteredId < 0 or enteredId >= len( shopManager.getWorkerList()): print("Id must be more than 0") else: break except: print("Id must be an integer") shopManager.getWorkerManager().deleteWorker(enteredId) printWriter.seeAllWorkers(shopManager.getWorkerList()) enteredId = None any = input(printWriter.deleteOtherWorker()) if any == "n": break elif any is not "y": print("Please enter 'y' for 'yes' or 'n' for 'no'") modifyingOperation = 0 else: print("Incorrect inputs")
''' Created on 24 mag 2018 @author: davideorlando ''' import unittest from model.Item import Item from unittest.test.test_assertions import Test_Assertions propGatto = "propGatto" itemOne = "1" properties = {propGatto} item1 = Item(itemOne, properties) def resetProp(itemOne): for prop in itemOne._properties: itemOne._valutations[prop] = -1 class Test(unittest.TestCase): def setUp(self): pass def tearDown(self): resetProp(item1) def testItemCreation(self): self.assertEqual(itemOne, str(item1)) def testItemCreation_evaluatedFalse(self):
def __init__(self): Item.__init__(self) self.heuristic = 0 self.safe_humans = []
def __init__(self): Item.__init__(self) self.heuristic = float("inf")
def evaluateCheck(self): passed = self.dynamicProperties.addDynamicPropertiesFromCheck( self.check, self.testName, self.failon) if Check.Type.getType(self) == Check.Type.COMPARE_PROPERTY: source_resource = ResourceBuilder.build( property=self.check['source'], testName=self.testName, checkName=self.checkName, dynamicProperties=self.dynamicProperties) target_resource = ResourceBuilder.build( property=self.check['target'], testName=self.testName, checkName=self.checkName, dynamicProperties=self.dynamicProperties) if source_resource.has_error( self.failon) or target_resource.has_error(self.failon): passed = False if source_resource.failed( self.failon) or target_resource.failed( self.failon) else passed else: source_item = source_resource.items[0] if source_item.has_error(self): passed = False if source_item.failed( self.failon) else passed elif self.cardinality == 'one-to-one': fromPropertiesIndex = 0 for target_item in target_resource.items: if target_item.has_error(self): passed = False if target_item.failed( self.failon) else passed else: toPropertiesIndex = fromPropertiesIndex + len( target_item.properties) if toPropertiesIndex <= len( source_item.properties): sourceProperties = source_item.properties[ fromPropertiesIndex:toPropertiesIndex] fromPropertiesIndex += len( target_item.properties) passed = self.compareItem( Item(source_item.file, sourceProperties, source_item.error), target_item) and passed else: passed = False comparelog.print_error( msg="Number of source properties from (" + source_resource.file + ") != Number of target properties from (" + target_resource.file + ")", args={ "testName": self.testName, "type": Error.VALUE_MISMATCH, "checkName": self.checkName }) break elif self.cardinality == 'one-to-many': for target_item in target_resource.items: if target_item.has_error(self): passed = False if target_item.failed( self.failon) else passed else: passed = self.compareItem(source_item, target_item, True) and passed elif Check.Type.getType(self) == Check.Type.COMPARE_FILES: source_resource = ResourceBuilder.build( property=self.check['source'], testName=self.testName, checkName=self.checkName, dynamicProperties=self.dynamicProperties) target_resource = self.check['target'] if source_resource.has_error(self.failon): passed = False if source_resource.failed( self.failon) else passed else: targetProperties = [] if source_resource.items[0].properties: for property in source_resource.items[0].properties: targetProperties.append(property.name) target_resource['property'] = targetProperties target_resource = ResourceBuilder.build( property=self.check['target'], testName=self.testName, checkName=self.checkName, dynamicProperties=self.dynamicProperties) passed = self.compareItem(source_resource.items[0], target_resource.items[0]) and passed elif Check.Type.getType(self) == Check.Type.SUCCESS: if 'target' not in self.check: passed = False comparelog.print_error(msg="'target' not defined in check: " + self.checkName, args={ 'testName': self.testName, 'type': Error.SYNTAX_ERROR, 'checkName': self.checkName }) else: target_resource = ResourceBuilder.build( property=self.check['target'], testName=self.testName, checkName=self.checkName, dynamicProperties=self.dynamicProperties) if target_resource.type == ResourceBuilder.Type.SHELL: if target_resource.error and target_resource.error.type == Error.SHELL_COMMAND_ERROR: passed = False comparelog.print_info(msg=str( target_resource.property), args={ "testName": self.testName, "checkName": self.checkName, "type": "FAILED" }) elif target_resource.error and target_resource.error.type == Error.MISSING_PROPERTY: comparelog.print_info(msg=str( target_resource.property), args={ "testName": self.testName, "checkName": self.checkName, "type": "PASSED" }, console=False) else: for item in target_resource.items: passed = self.isSuccessShell(item) and passed else: if not target_resource.has_error(self.failon): for item in target_resource.items: passed = self.isSuccess(item) and passed else: passed = False if target_resource.failed( self.failon) else passed else: comparelog.print_error( msg="Unsupported check type '" + self.checkType + "'. Only 'COMPARE' and 'SUCCESS' is supported.", args={ "testName": self.testName, "checkName": self.checkName, "type": Error.SYNTAX_ERROR }) return passed