Ejemplo n.º 1
0
    def test_rent_by_a_representant_member(self):

        representant = "Alberto"
        family_members = [("Carlos", "brother"), ("Olga", "mother"),
                          ("Argenis", "father")]
        bike_rental = BikeRental()
        family_rent = bike_rental.family_rent(representant, family_members)
        alberto_rent = family_rent.rent(representant, "days")
        self.assertIsInstance(alberto_rent, Rent)
        self.assertEqual(alberto_rent.client, "Alberto")
        self.assertEqual(alberto_rent.type, "days")
        self.assertEqual(len(family_rent.rent_list), 1)
Ejemplo n.º 2
0
    def test_return_bike_errors(self):

        representant = "Alberto"
        family_members = [("Carlos", "brother"), ("Olga", "mother"),
                          ("Argenis", "father")]
        bike_rental = BikeRental()
        family_rent = bike_rental.family_rent(representant, family_members)
        with self.assertRaises(ValueError) as context:
            family_rent.rent("Carlossss", "hours")
            self.assertTrue('Invalid Member' in context.exception)
            invalid_rent = family_rent.rent("Carlos", "hours")
            family_rent.return_bike(invalid_rent)
            self.assertTrue('Must enter return date' in context.exception)
            family_rent.return_bike(invalid_rent, "2019-03-20")
            self.assertTrue(
                'Return date must be a datetime object' in context.exception)
Ejemplo n.º 3
0
    def test_errors(self):

        bike_rental = BikeRental()
        with self.assertRaises(ValueError) as context:

            bike_rental.family_rent("Alberto", "Hermano")
            self.assertTrue(
                'Invalid family_member format' in context.exception)
            bike_rental.rent("Miguel", "minutes")
            self.assertTrue('Invalid type' in context.exception)
            bike_rental.rent("Alberto", "hours", "2019-03-20")
            self.assertTrue(
                'Start time has to be datetime instance' in context.exception)
            olga_rent = bike_rental.rent("Olga", "days")
            carlos_rent = bike_rental.rent("Carlos", "hours")
            sonia_rent = bike_rental.rent("Sonia", "weeks")
            olga_rent.get_price("2019-4-10")
            self.assertTrue(
                'Return date must be a datetime object' in context.exception)
            carlos_rent.get_price("2019-4-10")
            self.assertTrue(
                'Return date must be a datetime object' in context.exception)
            sonia_rent.get_price("2019-4-10")
            self.assertTrue(
                'Return date must be a datetime object' in context.exception)
        with self.assertRaises(ValueError) as context:

            day_rent = bike_rental.rent("Raul", "days")
            day_rent.get_price()
            self.assertTrue('Must enter return date' in context.exception)
            hour_rent = bike_rental.rent("Raul", "hours")
            hour_rent.get_price()
            self.assertTrue('Must enter return date' in context.exception)
            week_rent = bike_rental.rent("Raul", "weeks")
            week_rent.get_price()
            self.assertTrue('Must enter return date' in context.exception)

        with self.assertRaises(ValueError) as context:
            invalid_end_price = datetime.datetime(2018, 1, 1)
            d_rent = bike_rental.rent("Raul", "days")

            h_rent = bike_rental.rent("Raul", "hours")

            w_rent = bike_rental.rent("Raul", "weeks")
            d_rent.get_price(invalid_end_price)
            self.assertTrue('Invalid return date' in context.exception)
            h_rent.get_price(invalid_end_price)
            self.assertTrue('Invalid return date' in context.exception)
            w_rent.get_price(invalid_end_price)
            self.assertTrue('Invalid return date' in context.exception)
Ejemplo n.º 4
0
    def test_full_family_promotion(self):

        representant = "Alberto"
        family_members = [("Carlos", "brother"), ("Olga", "mother"),
                          ("Argenis", "father")]
        bike_rental = BikeRental()
        family_rent = bike_rental.family_rent(representant, family_members)
        # First Rent
        start_date = datetime.datetime(2019, 3, 10, 21, 40, 42, 0)
        end_date = datetime.datetime(2019, 3, 28, 21, 41, 42, 0)
        carlos_rent = family_rent.rent("Carlos", "days", start_date)
        family_rent.return_bike(carlos_rent, end_date=end_date)
        self.assertEqual(carlos_rent.price, 380)
        # Second Rent
        start_date = datetime.datetime(2019, 3, 10, 21, 40, 42, 0)
        end_date = datetime.datetime(2019, 3, 10, 23, 40, 42, 0)
        olga_rent = family_rent.rent("Olga", "hours", start_date=start_date)
        family_rent.return_bike(olga_rent, end_date=end_date)
        self.assertEqual(olga_rent.price, 10)
        # Trying to get discount with less than three rents
        with self.assertRaises(ValueError) as context:

            family_rent.get_promotion_price()
            self.assertTrue('You need at least 3 rents to get discount' in
                            context.exception)
        # Third Rent
        start_date = datetime.datetime(2019, 3, 10, 21, 40, 42, 0)
        end_date = datetime.datetime(2019, 3, 20, 21, 40, 42, 0)
        argenis_rent = family_rent.rent("Argenis", "days", start_date)
        family_rent.return_bike(argenis_rent, end_date)
        self.assertEqual(argenis_rent.price, 200)
        # Fourth Rent
        start_date = datetime.datetime(2019, 3, 10, 21, 40, 42, 0)
        end_date = datetime.datetime(2019, 5, 10, 21, 40, 42, 0)
        alberto_rent = family_rent.rent("Alberto", "weeks")
        # Trying to get discount with no returned bikes
        with self.assertRaises(ValueError) as context:

            family_rent.get_promotion_price()
            self.assertTrue(
                'This promotion has no returned bikes' in context.exception)
        # Now is returned
        family_rent.return_bike(alberto_rent, end_date)
        self.assertEqual(alberto_rent.price, 600)
        expected_total_price = (alberto_rent.price + argenis_rent.price +
                                olga_rent.price + carlos_rent.price)
        expeced_promotion_price = (expected_total_price -
                                   (expected_total_price * 0.3))
        self.assertEqual(family_rent.get_total_price(), expected_total_price)
        self.assertEqual(family_rent.get_promotion_price(),
                         expeced_promotion_price)
        # Fifth Rent
        start_date = datetime.datetime(2019, 3, 10, 21, 40, 42, 0)
        end_date = datetime.datetime(2019, 3, 11, 12, 40, 42, 0)
        alberto2_rent = family_rent.rent("Argenis", "hours", start_date)
        # Test error when introducing rent object
        # that does not belong to this promotion
        invalid_rent = bike_rental.rent("Invalid", "hours")
        with self.assertRaises(ValueError) as context:

            family_rent.return_bike(invalid_rent, end_date)
            self.assertTrue("Invalid ID" in context.exception)
        alberto2_rent = family_rent.return_bike(alberto2_rent, end_date)

        # Test more than five rents error
        with self.assertRaises(ValueError) as context:

            family_rent.rent("Invalid", "hours")
            self.assertTrue("Not more rents available" in context.exception)