Exemplo n.º 1
0
def main():
    # Initialize different plans
    single_plan = Plan('Single', 49, 1)
    plus_plan = Plan('Plus', 99, 3)
    infinite_plan = Plan('Infinite', 249, -1)

    # Initialize multiple websites
    website_1 = Website('https://website_1.com')
    website_2 = Website('https://website_2.com')
    website_3 = Website('https://website_3.com')
    website_4 = Website('https://website_4.com')

    # Initialize multiple customers
    customer_1 = Customer('customer_1', '123456789', '*****@*****.**')
    customer_2 = Customer('customer_2', '123456789', '*****@*****.**')
    customer_3 = Customer('customer_3', '123456789', '*****@*****.**')

    # customer_1 subscribed for single_plan
    customer_1.add_subscription(single_plan)
    print("{} has subscribed for {} plan".format(customer_1,
                                                 customer_1.subscription.plan))

    # customer_1 added one website
    customer_1.add_website(website_1)
    print("{} has added website {} as per the {} plan".format(customer_1, \
            customer_1.websites, customer_1.subscription.plan))

    # customer_1 can not add more website in single_plan
    customer_1.add_website(website_2)
    print("{} can't add website {} as per the {} plan".format(customer_1, \
            website_2, customer_1.subscription.plan))

    # customer_1 can change plan from single_plan to plus_plan
    customer_1.change_plan(plus_plan)
    print("{} has changed his current plan {} to {} plan".format(customer_1, \
            single_plan, customer_1.subscription.plan))

    # customer_2 subscribe for infinite_plan
    customer_2.add_subscription(infinite_plan)

    # customer_2 can add multiple websites
    customer_2.add_website(website_1)
    customer_2.add_website(website_2)
    customer_2.add_website(website_3)
    customer_2.add_website(website_4)

    print("{} has added four websites {} under infinite plan".format(customer_2, \
            customer_2.websites))
class TestCustomer(unittest.TestCase):

    def setUp(self):
        self.single_plan = Plan('Single', 49, 1)
        self.plus_plan = Plan('Plus', 99, 3)

        self.website_1 = Website('https://google.com')
        self.website_2 = Website('https://google.com')
        
        self.customer_1 = Customer('customer_1', '123456789', '*****@*****.**')
    
    def test_customer_can_add_website(self):
        self.customer_1.add_subscription(self.single_plan)
        self.customer_1.add_website(self.website_1)
        self.assertEqual(len(self.customer_1.websites), 1)
    
    def test_customer_can_add_website_as_per_the_plan(self):
        self.customer_1.add_subscription(self.plus_plan)
        self.customer_1.add_website(self.website_1)
        self.customer_1.add_website(self.website_2)
        self.assertEqual(len(self.customer_1.websites), 2)
    
    def test_customer_can_not_add_website(self):
        self.customer_1.add_subscription(self.single_plan)
        self.customer_1.add_website(self.website_1)
        self.customer_1.add_website(self.website_1)
        self.assertNotEqual(len(self.customer_1.websites), 2)
    
    def test_customer_can_change_plan(self):
        self.customer_1.add_subscription(self.single_plan)
        old_plan = self.customer_1.subscription.plan
        self.customer_1.add_subscription(self.plus_plan)
        new_plan = self.customer_1.subscription.plan
        self.assertNotEqual(old_plan, new_plan)
    
    def test_customer_can_add_subscription(self):
        self.customer_1.add_subscription(self.single_plan)
        self.assertIsInstance(self.customer_1.subscription, Subscription)