def create_customers(log: Dict[str, List[Dict]]) -> List[Customer]:
    """ Returns a list of Customer instances for each customer from the input
    dataset from the dictionary <log>.

    Precondition:
    - The <log> dictionary contains the input data in the correct format,
    matching the expected input format described in the handout.
    """
    customer_list = []
    for cust in log['customers']:
        customer = Customer(cust['id'])
        for line in cust['lines']:
            contract = None
            if line['contract'] == 'prepaid':

                contract = PrepaidContract(datetime.date(2017, 12, 25), 100)
            elif line['contract'] == 'mtm':
                contract = MTMContract(datetime.date(2017, 12, 25))
            elif line['contract'] == 'term':
                contract = TermContract(datetime.date(2017, 12, 25),
                                        datetime.date(2019, 6, 25))
            else:
                print("ERROR: unknown contract type")

            line = PhoneLine(line['number'], contract)

            customer.add_phone_line(line)
        customer_list.append(customer)
    return customer_list
Example #2
0
def create_customers(log: Dict[str, List[Dict]]) -> List[Customer]:
    """ Returns a list of Customer instances for each customer from the input
    dataset from the dictionary <log>.

    Precondition:
    - The <log> dictionary contains the input data in the correct format,
    matching the expected input format described in the handout.
    """
    customer_list = []
    for cust in log['customers']:
        customer = Customer(cust['id'])
        for line in cust['lines']:
            contract = None
            #
            # 1) Uncomment the piece of code below once you've implemented
            #    all types of contracts.
            # 2) Make sure to import the necessary contract classes in this file
            # 3) Remove this
            if line['contract'] == 'prepaid':
                # start with $100 credit on the account
                contract = PrepaidContract(datetime.date(2017, 12, 25), 100)
            elif line['contract'] == 'mtm':
                contract = MTMContract(datetime.date(2017, 12, 25))
            elif line['contract'] == 'term':
                contract = TermContract(datetime.date(2017, 12, 25),
                                        datetime.date(2019, 6, 25))
            else:
                print("ERROR: unknown contract type")

            line = PhoneLine(line['number'], contract)
            customer.add_phone_line(line)
        customer_list.append(customer)
    return customer_list
Example #3
0
def create_two_customer_with_all_lines() -> List[Customer]:
    """ Create a customer with one of each type of PhoneLine
    """
    contracts = [
        TermContract(start=datetime.date(year=2017, month=12, day=25),
                     end=datetime.date(year=2019, month=6, day=25)),
        MTMContract(start=datetime.date(year=2017, month=12, day=25)),
        PrepaidContract(start=datetime.date(year=2017, month=12, day=25),
                        balance=100)
    ]
    numbers = ['123-4567', '987-6543', '654-3210', '246-8101', '135-7911',
               '112-3581']
    customer1 = Customer(cid=6666)
    customer2 = Customer(cid=7777)

    for i in range(len(contracts)):
        customer1.add_phone_line(PhoneLine(numbers[i], contracts[i]))

    # create another customer with different phone number but same contracts
    for i in range(len(contracts)):
        customer2.add_phone_line(PhoneLine(numbers[i + 3], contracts[i]))

    customer1.new_month(12, 2017)
    customer2.new_month(12, 2017)
    return [customer1, customer2]
def create_customer() -> Customer:
    """ Create a customer with one of each type of PhoneLine
    """
    contracts = [
        TermContract(start=datetime.date(year=2017, month=12, day=1),
                     end=datetime.date(year=2018, month=12, day=30)),
        MTMContract(start=datetime.date(year=2017, month=12, day=1)),
        PrepaidContract(start=datetime.date(year=2017, month=12, day=1),
                        balance=100)
    ]
    numbers = ['867-5309', '273-8255', '649-2568']
    customer = Customer(cid=5555)

    for i in range(len(contracts)):
        customer.add_phone_line(PhoneLine(numbers[i], contracts[i]))

    customer.new_month(12, 2017)
    return customer
def create_customers(log: Dict[str, List[Dict]]) -> List[Customer]:
    """ Returns a list of Customer instances for each customer from the input
    dataset from the dictionary <log>.

    Precondition:
    - The <log> dictionary contains the input data in the correct format,
    matching the expected input format described in the handout.
    """
    customer_list = []
    for cust in log['customers']:
        customer = Customer(cust['id'])
        for line in cust['lines']:
            contract = None
            if line['number'] == '100-1200': #Term: Test Free Min
                contract = TermContract(datetime.date(2018, 11, 1), datetime.date(2019, 1, 1))
            elif line['number'] == '200-1200': #Term: Test Cancel After
                contract = TermContract(datetime.date(2018, 11, 1), datetime.date(2018, 12, 1))
            elif line['number'] == '100-2101': #Term: Test Cancel On
                contract = TermContract(datetime.date(2018, 11, 1),
                                        datetime.date(2019, 1, 25))
            elif line['number'] == '100-3111': #Term: Test Cancel Before
                contract = TermContract(datetime.date(2018, 11, 1),
                                        datetime.date(2019, 2, 1))
            elif line['number'] == '001-2101': #Prepaid: positive balance
                contract = PrepaidContract(datetime.date(2018, 11, 1), 25)
            elif line['number'] == '001-3111':  # Prepaid: negative balance
                contract = PrepaidContract(datetime.date(2018, 11, 1), 25)
            elif line['number'] == '001-2011':  # Prepaid: mixed balance
                contract = PrepaidContract(datetime.date(2018, 11, 1), 25)
            elif line['contract'] == 'prepaid':
                # start with $100 credit on the account
                contract = PrepaidContract(datetime.date(2018, 11, 1), 100)
            elif line['contract'] == 'mtm':
                contract = MTMContract(datetime.date(2018, 11, 1))
            elif line['contract'] == 'term':
                contract = TermContract(datetime.date(2018, 11, 1),
                                        datetime.date(2019, 6, 25))
            else:
                print("ERROR: unknown contract type")

            line = PhoneLine(line['number'], contract)
            customer.add_phone_line(line)
        customer_list.append(customer)
    return customer_list
Example #6
0
def test_task3_MTM() -> None:
    # MTM Contracts
    contract = MTMContract(datetime.date(2017, 2, 15))
    bill = Bill()
    contract.new_month(3, 2017, bill)
    assert bill.get_cost() == pytest.approx(50.0)
    contract.bill_call(gen_call(10))
    assert bill.get_cost() == pytest.approx(50.05)
    contract.bill_call(gen_call(50))
    assert bill.get_cost() == pytest.approx(50.1)
    bill = Bill()
    contract.new_month(4, 2017, bill)
    assert bill.get_cost() == pytest.approx(50.0)
    assert contract.cancel_contract() == pytest.approx(50.0)