def get_restaurant_by_id(c, id): c.execute("""SELECT * FROM Restaurants WHERE ID=?""", (id, )) res = c.fetchone() if res: r = Restaurant(id=res[0], name=res[1], suburb=res[2], address=res[3], postcode=res[4], phone=res[5], hours=res[6], cuisine=res[7], owner=res[8], website=res[9], cost=res[10], image=res[11], rating=find_average_rating(c, res[0]), numRating=find_number_rating(c, res[0])) return r
def get_restaurants(c): results = [] c.execute("SELECT * FROM Restaurants LIMIT 1000") for restaurant in c.fetchall(): r = Restaurant(id=restaurant[0], name=restaurant[1], suburb=restaurant[2], address=restaurant[3], postcode=restaurant[4], phone=restaurant[5], hours=restaurant[6], cuisine=restaurant[7], owner=restaurant[8], website=restaurant[9], cost=restaurant[10], image=restaurant[11], rating=find_average_rating(c, restaurant[0]), numRating=find_number_rating(c, restaurant[0])) results.append(r) return results
def test_set_website(self): r = Restaurant(0, "restaurant1", "kensington", "12 anzac parade", "pizza", "john smith") r.set_website("https://www.google.com") self.assertEqual(r.get_website(), "https://www.google.com")
def test_set_rating(self): r = Restaurant(0, "restaurant1", "kensington", "12 anzac parade", "pizza", "john smith") r.set_rating(4.5) self.assertEqual(r.get_rating(), 4.5)
def test_set_hours(self): r = Restaurant(0, "restaurant1", "kensington", "12 anzac parade", "pizza", "john smith") r.set_hours("7am-5pm") self.assertEqual(r.get_hours(), "7am-5pm")
def test_set_phone(self): r = Restaurant(0, "restaurant1", "kensington", "12 anzac parade", "pizza", "john smith") r.set_phone("0000 0000") self.assertEqual(r.get_phone(), "0000 0000")
def test_set_owner(self): r = Restaurant(0, "restaurant1", "kensington", "12 anzac parade", "pizza", "john smith") r.set_owner("bob smith") self.assertEqual(r.get_owner(), "bob smith")
def test_set_address(self): r = Restaurant(0, "restaurant1", "kensington", "12 anzac parade", "pizza", "john smith") r.set_address("13 anzac pde") self.assertEqual(r.get_address(), "13 anzac pde")
def test_set_suburb(self): r = Restaurant(0, "restaurant1", "kensington", "12 anzac parade", "pizza", "john smith") r.set_suburb("kingsford") self.assertEqual(r.get_suburb(), "kingsford")
def test_constructor(self): # No optional arguments r = Restaurant(0, "restaurant1", "kensington", "12 anzac parade", "pizza", "john smith") self.assertEqual(r.get_id(), 0) self.assertEqual(r.get_name(), "restaurant1") self.assertEqual(r.get_suburb(), "kensington") self.assertEqual(r.get_address(), "12 anzac parade") self.assertEqual(r.get_cuisine(), "pizza") self.assertEqual(r.get_owner(), "john smith") # All optional arguments r = Restaurant(0, "restaurant1", "kensington", "12 anzac parade", "pizza", "john smith", phone="1234 5678", hours="8am-10pm", rating=3.5, website="https://restaurant1.com", cost=10.5) self.assertEqual(r.get_id(), 0) self.assertEqual(r.get_name(), "restaurant1") self.assertEqual(r.get_suburb(), "kensington") self.assertEqual(r.get_address(), "12 anzac parade") self.assertEqual(r.get_cuisine(), "pizza") self.assertEqual(r.get_owner(), "john smith") self.assertEqual(r.get_phone(), "1234 5678") self.assertEqual(r.get_hours(), "8am-10pm") self.assertEqual(r.get_rating(), 3.5) self.assertEqual(r.get_website(), "https://restaurant1.com") self.assertEqual(r.get_cost(), 10.5)
def test_set_cost(self): r = Restaurant(0, "restaurant1", "kensington", "12 anzac parade", "pizza", "john smith") r.set_cost(13.25) self.assertEqual(r.get_cost(), 13.25)
from classes import Restaurant restaurant = Restaurant('Itsudemo', 'Japanese') print(f"{restaurant.restaurant_name} has {restaurant.cuisine_type} cuisine") restaurant.describe_restaurant() restaurant.open_restaurant() print(restaurant.number_served) restaurant.set_number_served(2) print(restaurant.number_served) another_restaurant = Restaurant('Burger King', 'American') another_restaurant.describe_restaurant() restaurant2 = Restaurant('Pho', 'Viet') restaurant2.describe_restaurant()