Beispiel #1
0
    def test_validator(self):
        validator = Validator.get_instance()
        customer = Individual()
        customer.set_cnp("198121203415")
        customer.set_last_name("Dan")
        customer.set_first_name("Popescu")
        customer.set_phone_number("0756234876")
        customer.set_email_address("*****@*****.**")
        item = Item()
        currency = Currency("$", "dollar", "USD")
        item.set_name("Apple")
        item.set_price(2)
        item.set_discount(0)
        item.set_currency(currency)
        company = Company()
        company.set_company_name("La Gigi")
        company.set_fiscal_no("RO0123")
        company.set_registration_number("123456")
        company.set_email_address("*****@*****.**")
        company.set_first_name("Ion")
        company.set_last_name("Bogdan")
        company.set_phone_number("0752314567")
        company.set_fiscal_no("0000012345678")
        company.set_registration_number("RO01923")
        bill = Bill()
        bill.set_currency(currency)
        bill.set_customer(customer)
        bill.set_issuer(company)
        bill.set_issue_date("21.12.2020")
        bill.set_due_date("21.02.2021")
        bill.add_items(item)

        validator.validate_bill(bill)
Beispiel #2
0
 def setUp(self):
     self.auction = Auction(
         creator=User("test_user"),
         items=[
             Item(1, "test_item", "test", Money(12.0)),
             Item(1, "test_item", "test", Money(12.0)),
         ],
     )
     self.repository = FakeAuctionRepository()
     self.repository.add(self.auction)
def parse_data(in_file):
    """
    Function to pare data
    :param in_file: input file
    :return: a knapsack object containing the list of objects and the maximum weight
    """

    with open(in_file, "r") as f_read:  # closes file in case of error

        f_read.readline()
        w_string = f_read.readline().split(",")
        weights = []
        for weight in w_string:
            weights.append(int(weight))
        c_string = f_read.readline().split(",")
        costs = []
        for cost in c_string:
            costs.append(int(cost))

        max_w = int(f_read.readline())

        knapsack = Knapsack(max_w)
        for i in range(0, len(costs)):
            knapsack.add_item(Item(weights[i], costs[i]))

        return knapsack
Beispiel #4
0
def add_an_item(name, price, add_item, item_does_exist, *args, **kwargs):
    if item_does_exist(name):
        return None
    else:
        item_to_create = Item(name, price)
        add_item(item_to_create, *args, **kwargs)
        return item_to_create
Beispiel #5
0
 def test_update_auction(self):
     self.repository.update(
         self.auction.auction_id,
         {
             "items": [
                 Item(1, "test_item", "test", Money(12.0)),
                 Item(1, "test_item", "test", Money(12.0)),
             ]
         },
     )
     self.assertNotEqual(
         self.auction.items,
         [
             Item(1, "test_item", "test", Money(12.0)),
             Item(1, "test_item", "test", Money(11.0)),
         ],
     )
Beispiel #6
0
 def _get_all_objects(self):
     items = []
     for row in self._database.select(
             'SELECT '
             'comment, host, id, method, path, port, protocol, request, response, status, tags, time, tool '
             'FROM items '
             'ORDER BY id'):
         row[7] = self._decode_data(row[7])
         row[8] = self._decode_data(row[8])
         row[10] = InfrastructureHelpers.split(row[10])
         items.append(Item(*row))
     return items
Beispiel #7
0
    def list(
            self,
            filters: typing.Mapping[str,
                                    typing.Any] = None) -> typing.List[Item]:
        if not filters:
            result = self._entries
        else:
            result = list()
            result.extend(self._entries)
            for key, value in filters.items():
                result = [e for e in result if self._check(e, key, value)]

        return [Item.from_dict(r) for r in result]
 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)
 def test_item_repo(self):
     item1 = Item()
     currency = Currency("$", "Dollar", "USD")
     item1.set_id(1)
     item1.set_name("Apple")
     item1.set_discount(0)
     item1.set_price(2)
     item1.set_currency(currency)
     item1.set_description("A fruit")
     item_repo = ItemRepo()
     item_repo.store(item1)
     self.assertEqual(len(item_repo.get_all()), 1)
     item2 = Item()
     item2.set_name("Pear")
     item2.set_currency(currency)
     item2.set_price(3)
     item2.set_discount(0)
     item2.set_description("A fruit")
     item_repo.update(1, item2)
     self.assertEqual(item_repo.get(1), item2)
     item_repo.delete(item2.get_id())
     self.assertEqual(item_repo.get_all(), [])
     self.assertIsNone(item_repo.get(-1))
 def test_item_service(self):
     service = ItemService(ItemRepo())
     item = Item()
     currency = Currency("$", "Dollar", "USD")
     item.set_id(1)
     item.set_currency(currency)
     item.set_name("McChicken")
     item.set_description("Chicken hamburger")
     item.set_price(2)
     item.set_discount(0)
     service.create_item(item)
     self.assertEqual(item, service.choose_item(1))
     item.set_price(3)
     item.set_id(2)
     service.modify_item(1, item)
     self.assertEqual(item, service.choose_item(1))
     service.delete_item(1)
     self.assertEqual(service.view_all_item(), [])
 def test_service(self):
     service = Service("json_test.json", "json_test.json", "json_test.json",
                       "json_test.json")
     # Customer Options
     company = Company()
     address = Address()
     address.set_address("Strada Academiei nr. 7")
     address.set_county("Bucuresti")
     address.set_country("Romania")
     address.set_postal_code("010011")
     company.set_id(1)
     company.set_address(address)
     company.set_company_name("La Geani")
     company.set_registration_number("RO0123")
     company.set_fiscal_no("0000231523647")
     company.set_email_address("*****@*****.**")
     company.set_first_name("Ion")
     company.set_last_name("Bogdan")
     company.set_phone_number("0752314567")
     company.set_fiscal_no("0000012345678")
     company.set_registration_number("RO01923")
     service.create_customer(company)
     self.assertEqual(service.get_company_customer(1), company)
     company.set_company_name("Marketplex")
     service.modify_customer(1, company)
     self.assertEqual(service.get_company_customer(1), company)
     service.delete_customer(company)
     self.assertEqual(service.view_all_company_customer(), [])
     individual = Individual()
     individual.set_cnp("1971209075425")
     individual.set_id(1)
     individual.set_first_name("Petre")
     individual.set_last_name("Vasile")
     individual.set_phone_number("0745321784")
     individual.set_email_address("*****@*****.**")
     service.create_customer(individual)
     self.assertEqual(service.get_individual_customer(1), individual)
     individual.set_last_name("Gigel")
     service.modify_customer(1, individual)
     self.assertEqual(service.get_individual_customer(1), individual)
     service.delete_customer(individual)
     self.assertEqual(service.view_all_individual_customer(), [])
     individual.set_address(address)
     # Currency Options
     currency = Currency("$", "Dollar", "USD")
     currency.set_id(1)
     currency.set_exchange_rate(4.5)
     service.create_currency(currency)
     self.assertEqual(currency, service.get_currency(1))
     currency.set_exchange_rate(4.2)
     service.modify_currency(1, currency)
     self.assertEqual(currency, service.get_currency(1))
     service.delete_currency(1)
     self.assertEqual(service.view_currency(), [])
     # Item Options
     item = Item()
     item.set_id(1)
     item.set_currency(currency)
     item.set_name("McChicken")
     item.set_description("Chicken hamburger")
     item.set_price(2)
     item.set_discount(0)
     service.create_item(item)
     self.assertEqual(item, service.choose_item(1))
     item.set_price(3)
     service.modify_item(1, item)
     self.assertEqual(item, service.choose_item(1))
     service.delete_item(1)
     self.assertEqual(service.view_items(), [])
     # Bill Options
     bill_item = BillItem()
     bill_item.set_id(1)
     bill_item.set_currency(currency)
     bill_item.set_name("McChicken")
     bill_item.set_description("Chicken hamburger")
     bill_item.set_price(3)
     bill_item.set_discount(0)
     bill = Invoice()
     bill.set_customer(individual)
     bill.set_currency(currency)
     bill.set_items([bill_item])
     bill.set_id(1)
     bill.set_issuer(company)
     bill.set_issue_date("24.01.2021")
     bill.set_due_date("10.02.2021")
     bill.set_notes("Platiti la Banca Transilvania")
     service.create_item(item)
     service.create_bill(bill)
     self.assertEqual(service.get_invoice(1), bill)
     bill.set_notes("asdfge")
     service.modify_bill(1, bill)
     self.assertEqual(service.get_invoice(1), bill)
     service.add_item_to_bill(1, bill)
     bill.add_items(bill_item)
     self.assertEqual(service.get_invoice(1), bill)
     service.invoice_to_fiscal(1)
     fiscal_bill = FiscalBill()
     fiscal_bill.set_customer(individual)
     fiscal_bill.set_currency(currency)
     bill_item.set_quantity(2)
     fiscal_bill.set_total(3.0)
     fiscal_bill.set_items([bill_item])
     fiscal_bill.set_id(1)
     fiscal_bill.set_issuer(company)
     fiscal_bill.set_issue_date("24.01.2021")
     fiscal_bill.set_due_date("10.02.2021")
     fiscal_bill.set_notes("asdfge")
     self.assertEqual(fiscal_bill, service.get_fiscal(1))
     service.delete_bill(bill)
     file = open("json_test.json", "w")
     file.truncate(0)
     file.write("{}")
     file.close()
Beispiel #12
0
 def add_item(self, quantity: int, name: AnyStr, description: AnyStr,
              price: Money) -> None:
     self.items.append(Item(quantity, name, description, price))
Beispiel #13
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()
Beispiel #14
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)
Beispiel #15
0
 def _create_item(self, command):
     return Item('', command.url.getHost(), None, command.method,
                 command.url.getPath(), command.url.getPort(),
                 command.url.getProtocol(), command.request,
                 command.response, 'New', [], command.time, command.tool)
Beispiel #16
0
 def test_item_getters_and_setters(self):
     item = Item()
     currency = Currency("$", "Dollar", "USD")
     item.set_name("Apple")
     item.set_price(1)
     item.set_discount(0)
     item.set_currency(currency)
     item.set_description("A round fruit")
     self.assertEqual(item.get_name(), "Apple")
     self.assertEqual(item.get_price(), 1)
     self.assertEqual(item.get_discount(), 0)
     self.assertEqual(item.get_currency(), currency)
     self.assertEqual(item.get_description(), "A round fruit")
Beispiel #17
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