Пример #1
0
 def test_equal(self):
     item = Item()
     currency = Currency("$", "Dollar", "USD")
     currency2 = copy.deepcopy(currency)
     currency2.set_name("dollar")
     item.set_name("Apple")
     item.set_price(1)
     item.set_discount(0)
     item.set_currency(currency)
     item.set_description("A round fruit")
     item.set_id(1)
     item.set_percent_discount(False)
     item2 = copy.deepcopy(item)
     item2.set_id(2)
     self.assertNotEqual(item, item2)
     item2.set_id(item.get_id())
     item2.set_name("pear")
     self.assertNotEqual(item, item2)
     item2.set_name(item.get_name())
     item2.set_currency(currency2)
     self.assertNotEqual(item, item2)
     item2.set_currency(item.get_currency())
     item2.set_description("asdf")
     self.assertNotEqual(item, item2)
     item2.set_description(item.get_description())
     item2.set_price(0)
     self.assertNotEqual(item, item2)
     item2.set_price(item.get_price())
     item2.set_discount(1)
     self.assertNotEqual(item, item2)
     item2.set_discount(item.get_discount())
     item2.set_percent_discount(True)
     self.assertNotEqual(item, item2)
 def test_json(self):
     item_repo = JsonItemRepo("json_test.json")
     currency = Currency("Leu", "Leu", "RON")
     item1 = Item()
     item1.set_name("Pear")
     item1.set_currency(currency)
     item1.set_price(3)
     item1.set_discount(0)
     item1.set_percent_discount(False)
     item1.set_description("A sweet fruit")
     item2 = copy.deepcopy(item1)
     item2.set_name("Apple")
     item1.set_price(2)
     item_repo.store(item1)
     item_repo.store(item2)
     item_repo2 = JsonItemRepo("json_test.json")
     item_list2 = item_repo2.get_all()
     item_list = item_repo.get_all()
     self.assertEqual(item_list, item_list2)
     item2.set_name("Green Apple")
     item_repo2.update(2, item2)
     self.assertEqual(item_repo2.get(2), item2)
     item_repo.reset_id()
     item_repo.delete(1)
     item_repo.delete(2)
Пример #3
0
 def input_item(self):
     item = Item()
     item.set_name(input("Give name: "))
     item.set_description(input("Give description: "))
     item.set_price(int(input("Give price: ")))
     item.set_discount(int(input("Give discount: ")))
     print("Is the discount a percent?\nYes of No")
     percent = input()
     if percent == "Yes":
         item.set_percent_discount(True)
     else:
         item.set_percent_discount(False)
     item.set_currency(self.choose_currency())
     return item
Пример #4
0
 def __load_from_file(self):
     file = open(self.__file_name, "r")
     json_file = json.loads(file.read())
     if "current_item_index" in json_file:
         self._id = json_file["current_item_index"]
     if "item_list" in json_file:
         for item in json_file["item_list"]:
             symbol = item["currency"]["symbol"]
             name = item["currency"]["name"]
             code = item["currency"]["code"]
             currency = Currency(symbol, name, code)
             exchange_rate = item["currency"]["exchange_rate"]
             currency.set_exchange_rate(exchange_rate)
             item_to_store = Item()
             item_to_store.set_id(item["id"])
             item_to_store.set_name(item["name"])
             item_to_store.set_price(item["price"])
             item_to_store.set_discount(item["discount"])
             item_to_store.set_description(item["description"])
             item_to_store.set_percent_discount(item["percent_discount"])
             item_to_store.set_currency(currency)
             self._list.append(item_to_store)
     file.close()