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): tagging = models.Tagging('tagging-id', 'shop-id', 'tag-id') assert tagging.id == 'tagging-id' assert tagging.shop_id == 'shop-id' assert tagging.tag_id == 'tag-id' with pytest.raises(KeyError) as exc: tagging.tag assert "KeyError: 'tag-id'" in str(exc) with pytest.raises(KeyError) as exc: tagging.shop assert "KeyError: 'shop-id'" in str(exc)
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_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_aggregator(self): tagging = models.Tagging('tagging-id', 'shop-id', 'tag-id') assert models.Taggings['tagging-id'] == tagging assert models.Taggings['shop_id']['shop-id'] == [tagging] assert models.Taggings['tag_id']['tag-id'] == [tagging]
def test_tag(self): tagging = models.Tagging('tagging-id', 'shop-id', 'tag-id') tag = models.Tag('tag-id', 'tag-name') assert tagging.tag == tag
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_taggings(self): tag = models.Tag('tag-id', 'my-tag') tagging = models.Tagging(1, 'shop-id', 'tag-id') assert tag.taggings == [tagging]
def tagging(): return models.Tagging('tagging-id', 'shop-id', 'tag-id')