def test_two_rentals_statement(self): self.assertEqual( "Rental record for Jim\n" + "\t---\n\t---\n" + "Amount owed is 0.0\n" + "You earned 0 frequent renter points", CustomerBuilder( rentals=[create_rental_mock(), create_rental_mock()]).build().statement())
def test_one_rental_html_statement(self): self.assertEqual( "<h1>Rental record for <em>Jim</em></h1>\n" + "<p>---</p>\n" + "<p>Amount owed is <em>0.0</em></p>\n" + "<p>You earned <em>0 frequent renter points</em></p>", CustomerBuilder( rental=create_rental_mock()).build().html_statement())
def test_points_for_two_different_rentals(self): self.assertEqual( 3, CustomerBuilder(rentals=[ create_rental_mock(**{"get_points.return_value": 2}), create_rental_mock(**{"get_points.return_value": 1}) ]).build().get_total_points())
def test_charge_for_two_different_rentals(self): self.assertEqual( 5.2, CustomerBuilder(rentals=[ create_rental_mock(**{"get_charge.return_value": 2.0}), create_rental_mock(**{"get_charge.return_value": 3.2}) ]).build().get_total_charge())
def test_recent_rentals_with_4_rentals(self): godfather = Mock(spec_set=Movie, **{"get_title.return_value": "None"}) lionking = Mock(spec_set=Movie, **{"get_title.return_value": "None"}) mulan = Mock(spec_set=Movie, **{"get_title.return_value": "None"}) tron = Mock(spec_set=Movie, **{"get_title.return_value": "None"}) godfather_rental = Mock(spec_set=Rental, **{ "get_movie.side_effect": lambda b: godfather if (type(b) == bool) else DEFAULT }) lionking_rental = Mock(spec_set=Rental, **{ "get_movie.side_effect": lambda b: lionking if (type(b) == bool) else DEFAULT }) mulan_rental = Mock(spec_set=Rental, **{ "get_movie.side_effect": lambda b: mulan if (type(b) == bool) else DEFAULT }) tron_rental = Mock(spec_set=Rental, **{ "get_movie.side_effect": lambda b: tron if (type(b) == bool) else DEFAULT }) self.assertEqual( "Recent rentals:\nNone\nNone\nNone", CustomerBuilder(rentals=[ godfather_rental, lionking_rental, mulan_rental, tron_rental ]).build().recent_rentals())
def test_recent_rentals_with_3_rentals(self): godfather = Mock(spec_set=Movie, **{ "get_title.side_effect": lambda *x: title_override("Godfather 4", *x) }) lionking = Mock(spec_set=Movie, **{ "get_title.side_effect": lambda *x: title_override("Lion King", *x) }) mulan = Mock(spec_set=Movie, **{ "get_title.side_effect": lambda *x: title_override("Mulan", *x) }) godfather_rental = Mock( spec_set=Rental, **{"get_movie.side_effect": lambda b: godfather if b else DEFAULT}) lionking_rental = Mock( spec_set=Rental, **{"get_movie.side_effect": lambda b: lionking if b else DEFAULT}) mulan_rental = Mock( spec_set=Rental, **{"get_movie.side_effect": lambda b: mulan if b else DEFAULT}) self.assertEqual( "Recent rentals:\nGodfather 4\nLion King\nMulan", CustomerBuilder( rentals=[godfather_rental, lionking_rental, mulan_rental ]).build().recent_rentals())
def test_one_new_release_statement(self): self.assertEqual( "Rental record for John\n" + "\tGodfather 4 9.0\n" + "Amount owed is 9.0\n" + "You earned 2 frequent renter points", CustomerBuilder( name="John", builder=RentalBuilder(builder=MovieBuilder( movietype=TYPE_NEW_RELEASE))).build().statement())
def test_one_new_release_html_statement(self): self.assertEqual( "<h1>Rental record for <em>John</em></h1>\n" + "<p>Godfather 4 9.0</p>\n" + "<p>Amount owed is <em>9.0</em></p>\n" + "<p>You earned <em>2 frequent renter points</em></p>", CustomerBuilder( name="John", builder=RentalBuilder(builder=MovieBuilder( movietype=TYPE_NEW_RELEASE))).build().html_statement())
def test_recent_rentals_with_3_rentals(self): movie_mock = Mock(spec_set=Movie, **{"get_title.return_value": "None"}) rental_mock = Mock(spec_set=Rental, **{ "get_movie.side_effect": lambda b: movie_mock if (type(b) == bool) else DEFAULT }) self.assertEqual( "Recent rentals:\nNone\nNone\nNone", CustomerBuilder(rentals=[rental_mock, rental_mock, rental_mock ]).build().recent_rentals())
def test_new_release_and_regular_statement(self): self.assertEqual( "Rental record for Steve\n" + "\tGodfather 4 9.0\n" + "\tScarface 3.5\n" + "Amount owed is 12.5\n" + "You earned 3 frequent renter points", CustomerBuilder(name="Steve", builders=[ RentalBuilder(builder=MovieBuilder( movietype=TYPE_NEW_RELEASE)), RentalBuilder(builder=MovieBuilder( name="Scarface", movietype=TYPE_REGULAR)) ]).build().statement())
def test_new_release_and_regular_html_statement(self): self.assertEqual( "<h1>Rental record for <em>Steve</em></h1>\n" + "<p>Godfather 4 9.0</p>\n" + "<p>Scarface 3.5</p>\n" + "<p>Amount owed is <em>12.5</em></p>\n" + "<p>You earned <em>3 frequent renter points</em></p>", CustomerBuilder(name="Steve", builders=[ RentalBuilder(builder=MovieBuilder( movietype=TYPE_NEW_RELEASE)), RentalBuilder(builder=MovieBuilder( name="Scarface", movietype=TYPE_REGULAR)) ]).build().html_statement())
def test_all_rental_types_statement(self): self.assertEqual( "Rental record for Pat\n" + "\tGodfather 4 9.0\n" + "\tScarface 3.5\n" + "\tLion King 1.5\n" + "Amount owed is 14.0\n" + "You earned 4 frequent renter points", CustomerBuilder(name="Pat", builders=[ RentalBuilder(builder=MovieBuilder( movietype=TYPE_NEW_RELEASE)), RentalBuilder(builder=MovieBuilder( name="Scarface", movietype=TYPE_REGULAR)), RentalBuilder(builder=MovieBuilder( name="Lion King", movietype=TYPE_CHILDREN)) ]).build().statement())
def test_all_rental_types_html_statement(self): self.assertEqual( "<h1>Rental record for <em>Pat</em></h1>\n" + "<p>Godfather 4 9.0</p>\n" + "<p>Scarface 3.5</p>\n" + "<p>Lion King 1.5</p>\n" + "<p>Amount owed is <em>14.0</em></p>\n" + "<p>You earned <em>4 frequent renter points</em></p>", CustomerBuilder(name="Pat", builders=[ RentalBuilder(builder=MovieBuilder( movietype=TYPE_NEW_RELEASE)), RentalBuilder(builder=MovieBuilder( name="Scarface", movietype=TYPE_REGULAR)), RentalBuilder(builder=MovieBuilder( name="Lion King", movietype=TYPE_CHILDREN)) ]).build().html_statement())
def test_get_name(self): self.assertEqual("John", CustomerBuilder(name="John").build().name)
def test_points_for_no_rentals(self): self.assertEqual(0, CustomerBuilder().build().get_total_points())
def test_no_rentals_html_statement(self): self.assertEqual( "<h1>Rental record for <em>David</em></h1>\n" + "<p>Amount owed is <em>0</em></p>\n" + "<p>You earned <em>0 frequent renter points</em></p>", CustomerBuilder(name="David").build().html_statement())
def test_charge_for_no_rentals(self): self.assertEqual(0.0, CustomerBuilder().build().get_total_charge())
def test_no_rentals_statement(self): self.assertEqual( "Rental record for David\n" + "Amount owed is 0\n" + "You earned 0 frequent renter points", CustomerBuilder(name="David").build().statement())
def test_invalid_title(self): with self.assertRaises(TypeError): CustomerBuilder(name="John", builder=RentalBuilder(builder=MovieBuilder( movietype=TYPE_UNKNOWN))).build()