Exemplo n.º 1
0
    def process(self, input_str):
        command = input_str.split()[0]
        customer_name = input_str.split()[1]
        card_type = input_str.split()[2]

        if command == "Add":
            card_number = input_str.split()[3]
            amount = int(input_str.split()[4].strip('$'))
            spending_limit = amount
            customer = self.get_customer(customer_name)
            if customer == None:
                customer = Customer(name=customer_name)
                self.customers[customer_name] = customer
            customer.add_card(card_type, card_number, spending_limit)
        elif command == "Charge":
            amount = int(input_str.split()[3].strip('$'))
            customer = self.get_customer(customer_name)
            customer.get_card(card_type).charge(amount)
        elif command == "Refund":
            amount = int(input_str.split()[3].strip('$'))
            customer = self.get_customer(customer_name)
            customer.get_card(card_type).refund(amount)
        else:
            print("Invalid")
            pass
Exemplo n.º 2
0
def test_customer_with_card():
    customer = Customer(name="Kirby")
    add_card = customer.add_card("TestType", "7969024409737685", 500)

    assert add_card == True
    assert customer.get_card("TestType") != None
    assert len(customer.cards) == 1
    assert customer.get_card("TestType").spending_limit == 500
    assert customer.get_card("TestType").number == "7969024409737685"