def test_get_shops_correctly(self): address_1 = Address('Street 1', '12345', 'Country 1', 42.42, 13.37) address_2 = Address('Street 2', '54321', 'Country 2', 8.15, 44.44) shop_1 = Shop('Shop 1', address_1, str(ObjectId())) shop_2 = Shop('Shop 2', address_2, str(ObjectId())) shop_1_id = self.dao.store_one(shop_1.to_db_object()) shop_2_id = self.dao.store_one(shop_2.to_db_object()) shops = self.shop_handler.get_shops() self.assertEqual(len(shops), 2) self.assertIn(shop_1_id, [shop['id'] for shop in shops]) self.assertIn(shop_2_id, [shop['id'] for shop in shops])
def test_get_shops_correctly_with_session_id(self): session_id = 'sessionId' shop_owner_id = str(ObjectId()) shop_owner = ShopOwner('login', 'pw', 'first', 'last', shop_owner_id) self.shop_owner_handler.active_user_sessions[session_id] = shop_owner address_1 = Address('Street 1', '12345', 'Country 1', 42.42, 13.37) address_2 = Address('Street 2', '54321', 'Country 2', 8.15, 44.44) shop_1 = Shop('Shop 1', address_1, shop_owner_id) shop_2 = Shop('Shop 2', address_2, str(ObjectId())) shop_1_id = self.dao.store_one(shop_1.to_db_object()) shop_2_id = self.dao.store_one(shop_2.to_db_object()) shops = self.shop_handler.get_shops(session_id=session_id) self.assertEqual(len(shops), 1) self.assertEqual(shops[0]['id'], shop_1_id)
def test_add_item_correctly(self): session_id = 'someId' name = 'ItemName' price = 42.42 category = 'Category' description = 'This is some item' attributes = {'att1': 42, 'att2': 'bla'} image_id = 'imageId' image_url = 'https://image.com' owner_id = str(ObjectId()) owner = ShopOwner('login', 'pw', 'first', 'last', id=owner_id) self.shop_owner_handler.active_user_sessions[session_id] = owner shop = Shop('Shop', Address('', '', '', 0, 0), owner_id) shop_id = self.shops_dao.store_one(shop.to_db_object()) item_id = self.item_handler.add_item(name, price, category, shop_id, description, attributes, image_id, image_url, session_id) items = self.items_dao.get_all() self.assertEqual(len(items), 1) self.assertEqual(str(items[0]['_id']), item_id) self.assertEqual(items[0]['name'], name) self.assertEqual(items[0]['price'], price) self.assertEqual(items[0]['category'], category) self.assertEqual(str(items[0]['shop']), shop_id) self.assertEqual(items[0]['details']['description'], description) self.assertEqual(items[0]['details']['attributes'], attributes) self.assertEqual(items[0]['image']['id'], image_id) self.assertEqual(items[0]['image']['url'], image_url)
def test_add_item_with_incorrect_owner_id(self): session_id = 'sessionId' owner_id = str(ObjectId()) other_owner_id = str(ObjectId()) owner = ShopOwner('login', 'pw', 'first', 'last', id=other_owner_id) self.shop_owner_handler.active_user_sessions[session_id] = owner shop = Shop('Shop', Address('', '', '', 0, 0), owner_id) shop_id = self.shops_dao.store_one(shop.to_db_object()) with self.assertRaises(UnauthorizedAccessError): self.item_handler.add_item('Item', 42.42, 'Category', shop_id, 'Description', {}, 'imageId', 'imageUrl', session_id)