def test_exclude_outside_radius(self): # Will be retrieved tag = models.Tag('tag-id', 'tag-name') shop = models.Shop('shop-id', 'shop-name', 1, 2) models.Tagging('tagging-id', shop.id, tag.id) # Wont be retrieved because it's outside radius tag2 = models.Tag('tag-id-2', 'tag-name-2') shop2 = models.Shop('shop-id-2', 'shop-name-2', 5, 10) models.Tagging('tagging-id-2', shop2.id, tag2.id) position = utils.Position(1, 2) radius = 3 shops = utils._find_close_shops(position, radius) assert shops == [shop]
def test_without_tags(self): """The function if not specifying tags returns all shops within radius.""" # Will be retrieved tag = models.Tag('tag-id', 'tag-name') shop = models.Shop('shop-id', 'shop-name', 1, 2) models.Tagging('tagging-id', shop.id, tag.id) # Will be retrieved tag2 = models.Tag('tag-id-2', 'tag-name-2') shop2 = models.Shop('shop-id-2', 'shop-name-2', 1, 2) models.Tagging('tagging-id-2', shop2.id, tag2.id) position = utils.Position(1, 2) radius = 3 shops = utils._find_close_shops(position, radius) assert sorted(shops) == sorted([shop, shop2])
def test_with_tags(self): # Will be retrieved tag = models.Tag('tag-id', 'tag-name') shop = models.Shop('shop-id', 'shop-name', 1, 2) models.Tagging('tagging-id', shop.id, tag.id) # Wont be retrieved tag2 = models.Tag('tag-id-2', 'tag-name-2') shop2 = models.Shop('shop-id-2', 'shop-name-2', 1, 2) models.Tagging('tagging-id-2', shop2.id, tag2.id) position = utils.Position(1, 2) radius = 3 tags = ['tag-name'] shops = utils._find_close_shops(position, radius, tags) assert shops == [shop]
def test_attributes(self): shop = models.Shop('shop-id', 'shop-name', 1, 2) assert shop.id == 'shop-id' assert shop.name == 'shop-name' assert shop.lat == 1 assert shop.lng == 2 assert shop.taggings == [] assert shop.products == []
def test_products(self): shop = models.Shop('shop-id', 'shop-name', 1, 2) shop2 = models.Shop('shop-id-2', 'shop-name-2', 5, 10) # generate some products for `shop` for i in range(1, 10, 2): models.Product('product-id-%d' % i, shop.id, 'product-title', .1 * i, 10) # generate some products for `shop2` for i in range(2, 11, 2): models.Product('product-id-%d' % i, shop2.id, 'product-title', .1 * i, 10) products = utils._find_best_products(models.Shops.values(), 3) assert products == [ models.Products['product-id-10'], models.Products['product-id-9'], models.Products['product-id-8'], ]
def test_returns(self, get): shop = models.Shop('shop-id', 'shop-name', 59.33258, 18.0649) product = models.Product('product-id', shop.id, 'product-title', .8, 10) tag = models.Tag('tag-id', 'trousers') tagging = models.Tagging('tagging-id', shop.id, tag.id) response = get('%s?%s' % ( self.endpoint, 'count=10&radius=500&position[lat]=59.33258&position[lng]=18.0649&tags=trousers&tags=shirts' )) assert response.status_code == 200 assert 'products' in response.json assert response.json['products'] == [ { 'shop': {'lat': 59.33258, 'lng': 18.0649}, 'title': 'product-title', 'popularity': .8, } ]
def test_aggregator(self): shop = models.Shop('shop-id', 'shop-name', 1, 2) assert models.Shops['shop-id'] == shop assert len(models.Shops.indexes) == 0
def test_products(self, tagging): shop = models.Shop('shop-id', 'shop-name', 1, 2) product = models.Product('product-id', 'shop-id', 'product-title', .8, 10) assert shop.products == [product]
def test_taggings(self): shop = models.Shop('shop-id', 'shop-name', 1, 2) tagging = models.Tagging('tagging-id', 'shop-id', 'tag-id') assert shop.taggings == [tagging]
def test_shop(self): tagging = models.Tagging('tagging-id', 'shop-id', 'tag-id') shop = models.Shop('shop-id', 'shop-name', 1, 2) assert tagging.shop == shop
def test_shop(self): product = models.Product('product-id', 'shop-id', 'product-title', .8, 10) shop = models.Shop('shop-id', 'shop-name', 1, 2) assert product.shop == shop
def shop(): return models.Shop('shop-id', 'shop-name', 1, 2)