def test_finds_cheapest_with_single_min(self): stations = [ Station('Caltex Beckenham', '63 William St', 128.9, 0), Station('Caltex Bassendean', '309 Guild Rd', 129.9, 0) ] expected_cheapest_station = stations[0] cheapest_station = fuelscanner.find_cheapest_station(stations, 1) self.assertEqual([expected_cheapest_station], cheapest_station)
def test_finds_cheapest_with_multiple_min(self): stations = [ Station('Caltex Beckenham', '63 William St', 128.9, 0), Station('Caltex Bassendean', '309 Guild Rd', 128.9, 0), Station('Shell Gidgegannup', '2095 Toodyay Rd', 137.9, 0) ] expected_cheapest_stations = stations[:2] cheapest_stations = fuelscanner.find_cheapest_station(stations, 2) self.assertEqual(expected_cheapest_stations, cheapest_stations)
def test_applies_discount_while_parsing(self): test_vouchers = {'caltex': 5, 'some_other_voucher': 7} test_urls = [TEST_URL_ONE, TEST_URL_TWO] expected_stations = [ Station('Caltex Beckenham', '63 William St', 128.9, 5), Station('Caltex Bassendean', '309 Guild Rd', 129.9, 5), Station('Shell Gidgegannup', '2095 Toodyay Rd', 137.9, 0) ] actual_stations = fuelscanner.parse_feed(test_urls, test_vouchers) self.assertEqual(expected_stations, actual_stations)
def test_correct_station_returned_from_parser(self): actual_stations = fuelscanner.parse_feed(TEST_URL_ONE) self.assertTrue(len(actual_stations) == 2) expected_stations = [ Station('Caltex Beckenham', '63 William St', 128.9, 0), Station('Caltex Bassendean', '309 Guild Rd', 129.9, 0) ] self.assertEqual(expected_stations, actual_stations) station = Station('Vibe Mt Helena', '9 McVicar Pl', 126.9, 0) self.assertNotIn(station, actual_stations)
def test_parses_correctly_given_multiple_feeds(self): test_urls = (TEST_URL_ONE, TEST_URL_TWO) expected_stations = [ Station('Caltex Beckenham', '63 William St', 128.9, 0), Station('Caltex Bassendean', '309 Guild Rd', 129.9, 0), Station('Shell Gidgegannup', '2095 Toodyay Rd', 137.9, 0) ] actual_stations = fuelscanner.parse_feed(test_urls) self.assertEqual(expected_stations, actual_stations) station = Station('Vibe Mt Helena', '9 McVicar Pl', 126.9, 0) self.assertNotIn(station, actual_stations)
def test_formats_multiple_stations(self): fuel_stations = [ Station('Caltex Beckenham', '63 William St', 128.9, 5), Station('Shell Gidgegannup', '2095 Toodyay Rd', 137.9, 0) ] expected_message = '\n'.join([ 'The cheapest fuel stations:', '128.9 (5) at Caltex Beckenham, 63 William St', '137.9 (0) at Shell Gidgegannup, 2095 Toodyay Rd' ]) message = fuelscanner.format_message(fuel_stations) self.assertEqual(message, expected_message)
def test_ignores_poorly_formated_rss_feeds(self): test_urls = [TEST_URL_TWO, 'poorly_formatted_feed.xml'] expected_station = [ Station('Shell Gidgegannup', '2095 Toodyay Rd', 137.9, 0) ] actual_stations = fuelscanner.parse_feed(test_urls) self.assertEqual(expected_station, actual_stations)
def test_message_formats_single_station(self): fuel_station = Station('Caltex Beckenham', '63 William St', 128.9, 5) expected_message = '\n'.join([ 'The cheapest fuel stations:', '128.9 (5) at Caltex Beckenham, 63 William St' ]) message = fuelscanner.format_message([fuel_station]) self.assertEqual(message, expected_message)