Ejemplo n.º 1
0
 def test_cancel_contract_before_end(self):
     """ Test that if a contract is cancelled before its end date, the
     deposit is forfeited.
     """
     tc = TermContract(datetime.date(2000, 9, 29),
                       datetime.date(2007, 9, 29))
     # go to last month of contract (contract not over, but almost!)
     tc.new_month(month=9, year=2007, bill=Bill())
     cancel = tc.cancel_contract()
     # check that the deposit has been forfeited
     self.assertAlmostEqual(cancel, TERM_MONTHLY_FEE)
Ejemplo n.º 2
0
 def test_cancel_contract_after_end(self):
     """ Test that if a contract is cancelled after its end date, the
     deposit is returned.
     """
     tc = TermContract(datetime.date(2000, 9, 29),
                       datetime.date(2007, 9, 29))
     # go to first month after contract
     tc.new_month(month=10, year=2007, bill=Bill())
     cancel = tc.cancel_contract()
     # check that the deposit has been returned
     self.assertAlmostEqual(cancel, TERM_MONTHLY_FEE - TERM_DEPOSIT)
Ejemplo n.º 3
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
            # TODO:
            # 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 TODO list when you're done.

            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
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
Ejemplo n.º 5
0
 def test_new_month_first_month(self):
     """ Test that the new_month function works as expected, and also that it
     bills the term deposit on the first month of the term.
     """
     tc = TermContract(datetime.date(2000, 9, 29),
                       datetime.date(2007, 9, 29))
     bill = Bill()
     tc.new_month(month=9, year=2000, bill=bill)
     assert tc.bill is bill
     # check that the rate per minute is appropriate for the class
     self.assertEqual(tc.bill.min_rate, TERM_MINS_COST)
     # check that the deposit and monthly fee have been billed
     self.assertAlmostEqual(tc.bill.fixed_cost,
                            TERM_MONTHLY_FEE + TERM_DEPOSIT)
     # check that nothing else has been billed, since no calls were made
     self.assertAlmostEqual(tc.bill.fixed_cost, tc.bill.get_cost())
Ejemplo n.º 6
0
 def test_new_month_not_first_month(self):
     """ Test that the new_month function works in general, aka test that it
     sets up the bill and rate correctly, and that it bills the right monthly
     fee.
     """
     tc = TermContract(datetime.date(2000, 9, 29),
                       datetime.date(2007, 9, 29))
     bill = Bill()
     tc.new_month(month=10, year=2000, bill=bill)
     assert tc.bill is bill
     # check that the rate per minute is appropriate for the class
     self.assertEqual(tc.bill.min_rate, TERM_MINS_COST)
     # check that the monthly fee has been billed
     self.assertEqual(tc.bill.fixed_cost, TERM_MONTHLY_FEE)
     # check that nothing else has been billed, since no calls were made
     self.assertAlmostEqual(tc.bill.fixed_cost, tc.bill.get_cost())
Ejemplo n.º 7
0
 def test_init(self, start, end):
     """ Test if a TermContract can be initialized properly with random
     start/end dates.
     """
     tc = TermContract(start, end)
     assert tc.start is start
     assert tc.end is end
Ejemplo n.º 8
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]
Ejemplo n.º 9
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
            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
Ejemplo n.º 10
0
    def test_bill_call_partially_free(self, t1):
        """ Test that a call is billed correctly even if it is longer than the
        number of free minutes remaining for the month.

        E.g. if 10 free minutes are remaining for the month and a call lasts 11
        minutes, then 10 minutes should be counted as free and 1 minute should
        be billed normally.
        """
        t1_mins = ceil(t1 / 60)
        tc = TermContract(datetime.date(2000, 9, 29),
                          datetime.date(2007, 9, 29))
        tc.new_month(10, 2007, Bill())
        # make a call whose duration is longer than the number of free mins left
        c1 = Call(src_nr="123-4567",
                  dst_nr="987-6543",
                  calltime=datetime.datetime(year=2007,
                                             month=10,
                                             day=31,
                                             hour=20,
                                             minute=30,
                                             second=0),
                  duration=t1,
                  src_loc=(-79.45188229255568, 43.62186408875219),
                  dst_loc=(-79.36866519485261, 43.680793196449336))
        tc.bill_call(c1)
        # check that free mins have been maxed out
        self.assertEqual(tc.bill.free_min, TERM_MINS)
        # check that the rest of the call has been billed
        self.assertEqual(tc.bill.billed_min, t1_mins - TERM_MINS)
Ejemplo n.º 11
0
 def test_bill_call_not_free(self, t1):
     """ Test that a call is billed correctly if there are no free minutes
     remaining for the month.
     """
     t1_mins = ceil(t1 / 60)
     tc = TermContract(datetime.date(2000, 9, 29),
                       datetime.date(2007, 9, 29))
     bill = Bill()
     tc.new_month(month=10, year=2007, bill=bill)
     # max out free mins so that a new call must be billed
     tc.bill.add_free_minutes(TERM_MINS)
     c1 = Call(src_nr="123-4567",
               dst_nr="987-6543",
               calltime=datetime.datetime(year=2007,
                                          month=10,
                                          day=31,
                                          hour=20,
                                          minute=30,
                                          second=0),
               duration=t1,
               src_loc=(-79.45188229255568, 43.62186408875219),
               dst_loc=(-79.36866519485261, 43.680793196449336))
     tc.bill_call(c1)
     # check that the entire call has been billed
     self.assertAlmostEqual(tc.bill.get_cost() - TERM_MONTHLY_FEE,
                            t1_mins * TERM_MINS_COST)
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
Ejemplo n.º 13
0
    def test_bill_call_free(self, t1: int, t2: int):
        """ Test that calls are billed as free as long as there are enough free
        minutes remaining.

        (The examples test the case the calls use all the free minutes.)
        """
        tc = TermContract(datetime.date(2000, 9, 29),
                          datetime.date(2007, 9, 29))
        bill = Bill()
        tc.new_month(month=10, year=2007, bill=bill)
        c1 = Call(src_nr="123-4567",
                  dst_nr="987-6543",
                  calltime=datetime.datetime(year=2007,
                                             month=10,
                                             day=31,
                                             hour=20,
                                             minute=30,
                                             second=0),
                  duration=t1,
                  src_loc=(-79.45188229255568, 43.62186408875219),
                  dst_loc=(-79.36866519485261, 43.680793196449336))
        c2 = Call(src_nr="123-4567",
                  dst_nr="987-6543",
                  calltime=datetime.datetime(year=2007,
                                             month=10,
                                             day=31,
                                             hour=21,
                                             minute=30,
                                             second=0),
                  duration=t2,
                  src_loc=(-79.45188229255568, 43.62186408875219),
                  dst_loc=(-79.36866519485261, 43.680793196449336))
        tc.bill_call(c1)
        tc.bill_call(c2)
        # the calls should be free, so the only cost billed should be the
        # monthly fee
        self.assertEqual(tc.bill.get_cost() - TERM_MONTHLY_FEE, 0, (t1, t2))
Ejemplo n.º 14
0
def test_task3_term() -> None:
    contract = TermContract(datetime.date(2017, 1, 1),
                            datetime.date(2018, 1, 1))
    bill = Bill()
    contract.new_month(1, 2017, bill)
    assert bill.get_cost() == pytest.approx(320)
    contract.bill_call(gen_call(20 * 60))
    assert bill.get_cost() == pytest.approx(320)
    contract.bill_call(gen_call(20 * 60))
    assert bill.get_cost() == pytest.approx(320)
    contract.bill_call(gen_call(70 * 60))
    assert bill.get_cost() == pytest.approx(321)
    contract.bill_call(gen_call(100 * 60))
    assert bill.get_cost() == pytest.approx(331)

    bill = Bill()
    contract.new_month(2, 2017, bill)
    assert bill.get_cost() == pytest.approx(20)
    contract.bill_call(gen_call(150 * 60))
    assert bill.get_cost() == pytest.approx(25)

    assert contract.cancel_contract() == pytest.approx(25)

    contract = TermContract(datetime.date(2017, 1, 1),
                            datetime.date(2017, 2, 1))
    contract.new_month(1, 2017, Bill())
    contract.new_month(2, 2017, Bill())
    assert contract.cancel_contract() == pytest.approx(-280)