def testGetById(self): restaurant_logic.add('fulinmenid', 'fulinmen', self.image_key) restaurant = restaurant_logic.get_by_id('fulinmenid') self.assertEqual('fulinmen', restaurant.name) restaurant = restaurant_logic.get_by_id('notexist') self.assertIsNone(restaurant)
def testAddingRestaurantWhenIdExis(self): restaurant_logic.add('fulinmen', 'fulinmen', self.image_key) try: restaurant_logic.add('fulinmen', 'fulinmen', self.image_key) self.fail('Should throw RestaurantExistError1') except RestaurantExistError: pass
def testGetCategories(self): restaurant_uid = 'uid' restaurant_logic.add(restaurant_uid, 'fulinmen') category_logic.add(restaurant_uid, 'category 1') category_logic.add(restaurant_uid, 'category 2') response = self.testapp.get('/api/category?uid=%s' % restaurant_uid) self.assertEqual(response.status_int, 200) self.assertEqual(json.dumps(response.json), '[{"restaurant_key": "agx0ZXN0YmVkLXRlc3RyEwsSClJlc3RhdXJhbnQiA3VpZAw", "name": "category 1", "key": "agx0ZXN0YmVkLXRlc3RyDgsSCENhdGVnb3J5GAEM"}, {"restaurant_key": "agx0ZXN0YmVkLXRlc3RyEwsSClJlc3RhdXJhbnQiA3VpZAw", "name": "category 2", "key": "agx0ZXN0YmVkLXRlc3RyDgsSCENhdGVnb3J5GAIM"}]')
def testAddCategory(self): restaurant_uid = 'uid' category_name = 'name' restaurant_logic.add(restaurant_uid, 'restaurant_name') params = {'uid': restaurant_uid, 'name': category_name} response = self.testapp.post('/api/category', params) self.assertEqual(response.status_int, 200) self.assertEqual(json.dumps(response.json), '{"restaurant_key": "agx0ZXN0YmVkLXRlc3RyEwsSClJlc3RhdXJhbnQiA3VpZAw", "name": "name", "key": "agx0ZXN0YmVkLXRlc3RyDgsSCENhdGVnb3J5GAEM"}')
def testInsertAndDeleteRestaurant(self): restaurant_uid = 'FuLinMen' restaurant_logic.add(restaurant_uid, 'restaurant', self.image_key) restaurants = restaurant_logic.get_all() self.assertEqual(1, len(restaurants)) restaurant_logic.delete(restaurant_uid) restaurants = restaurant_logic.get_all() self.assertEqual(0, len(restaurants))
def testGetDishes(self): restaurant_uid = 'uid' category_name = 'soup' restaurant_logic.add(restaurant_uid, 'fulinmen') category_logic.add(restaurant_uid, category_name) dish_logic.add(restaurant_uid, category_name, 'Dish 1') dish_logic.add(restaurant_uid, category_name, 'Dish 2') response = self.testapp.get('/api/dish?uid=%s' % restaurant_uid) self.assertEqual(response.status_int, 200) self.assertEqual(json.dumps(response.json), '[{"category_key": "agx0ZXN0YmVkLXRlc3RyDgsSCENhdGVnb3J5GAEM", "img_key": null, "restaurant_key": "agx0ZXN0YmVkLXRlc3RyEwsSClJlc3RhdXJhbnQiA3VpZAw", "name": "Dish 1", "key": "agx0ZXN0YmVkLXRlc3RyCgsSBERpc2gYAgw"}, {"category_key": "agx0ZXN0YmVkLXRlc3RyDgsSCENhdGVnb3J5GAEM", "img_key": null, "restaurant_key": "agx0ZXN0YmVkLXRlc3RyEwsSClJlc3RhdXJhbnQiA3VpZAw", "name": "Dish 2", "key": "agx0ZXN0YmVkLXRlc3RyCgsSBERpc2gYAww"}]')
def testCheckRestaurantUid(self): response = self.testapp.get('/api/check_restaurant_uid?uid=notexist') self.assertEqual(response.status_int, 200) self.assertEqual(json.dumps(response.json), '{"exist": false}') restaurant_logic.add('restaurant_uid', 'reataurant_name') response = self.testapp.get('/api/check_restaurant_uid?uid=restaurant_uid') self.assertEqual(response.status_int, 200) self.assertEqual(json.dumps(response.json), '{"exist": true}')
def testAddAndDeleteDish(self): restaurant_uid = 'uid' restaurant_logic.add(restaurant_uid, 'fulinmen') category_logic.add(restaurant_uid, 'category 1') params = {'uid': restaurant_uid, 'category_name': 'category 1', 'name': 'dish 1', "image_data": self.image_data} response = self.testapp.post('/api/dish', params) self.assertEqual(response.status_int, 200) self.assertEqual(json.dumps(response.json), ('{"category_key": "agx0ZXN0YmVkLXRlc3RyDgsSCENhdGVnb3J5GAEM", "img_key": "agx0ZXN0YmVkLXRlc3RyCwsSBUltYWdlGAIM", "restaurant_key": "agx0ZXN0YmVkLXRlc3RyEwsSClJlc3RhdXJhbnQiA3VpZAw", "name": "dish 1", "key": "agx0ZXN0YmVkLXRlc3RyCgsSBERpc2gYAww"}')) dishes = dish_logic.get_all_by_restaurant_uid(restaurant_uid) self.assertEqual(1, len(dishes)) self.testapp.delete('/api/dish/agx0ZXN0YmVkLXRlc3RyCgsSBERpc2gYAww') self.assertEqual(response.status_int, 200) dishes = dish_logic.get_all_by_restaurant_uid(restaurant_uid) self.assertEqual(0, len(dishes))
def post(self): restaurant_name = self.request.get(NAME) restaurant_uid = self.request.get(RESTAURANT_UID) restaurant_image_data = self.request.get(IMAGE_DATA) image = Image.from_image_data(restaurant_image_data) image.put() restaurant = restaurant_logic.add(restaurant_uid, restaurant_name, image.key) self.send_response(restaurant)
def test_add_and_get_categories(self): restaurant = restaurant_logic.add('FulinMen', 'restaurant', self.image_key) category_logic.add(restaurant.key, "Category 1") category_logic.add(restaurant.key, "Cateogyr 2") categories = category_logic.get_all_by_restaurant_key(restaurant.key) self.assertEqual(2, len(categories)) self.assertIsNotNone(category_logic.add('FulinMen', 'Category 3')) category_logic.add('FulinMen', 'Category 4') categories = category_logic.get_all_by_restaurant_key(restaurant.key) self.assertEqual(4, len(categories))
def test_add_and_get_dishes(self): restaurant = restaurant_logic.add('FulinMen', 'restaurant', self.image_key) category = category_logic.add(restaurant.key, "category") dish_logic.add_by_category_key(category.key, 'Dish1') dish_logic.add_by_category_key(category.key, 'Dish2') dishes = dish_logic.get_all_by_category_key(category.key) self.assertEqual(2, len(dishes)) "Test adding by restaurant_uid and category name" dish_logic.add('FulinMen', 'category', 'Dish3') dish_logic.add('FulinMen', 'category', 'Dish4') dishes = dish_logic.get_all_by_category_key(category.key) self.assertEqual(4, len(dishes)) dishes = dish_logic.get_all_by_restaurant_uid('FulinMen') self.assertEquals(4, len(dishes)) dish_logic.delete_by_id(dishes[0].key.id()) dishes = dish_logic.get_all_by_restaurant_uid('FulinMen') self.assertEquals(3, len(dishes))
def testGetById(self): restaurant_logic.add('fulinmenid', 'fulinmen', self.image_key) self.assertTrue(restaurant_logic.check_uid_exist('fulinmenid')) self.assertFalse(restaurant_logic.check_uid_exist('fulinmen'))
def testGetByName(self): restaurant_logic.add('fulinmen', 'fulinmen', self.image_key) restaurants = restaurant_logic.get_by_name('fulinmen') self.assertEqual(1, len(restaurants)) restaurant = restaurants[0] self.assertEqual('fulinmen', restaurant.name)