Esempio n. 1
0
    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]
Esempio n. 2
0
    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])
Esempio n. 3
0
    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]
Esempio n. 4
0
    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)
Esempio n. 5
0
    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,
            }
        ]
Esempio n. 6
0
    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]
Esempio n. 7
0
    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]
Esempio n. 8
0
    def test_tag(self):
        tagging = models.Tagging('tagging-id', 'shop-id', 'tag-id')

        tag = models.Tag('tag-id', 'tag-name')

        assert tagging.tag == tag
Esempio n. 9
0
    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
Esempio n. 10
0
    def test_taggings(self):
        tag = models.Tag('tag-id', 'my-tag')

        tagging = models.Tagging(1, 'shop-id', 'tag-id')

        assert tag.taggings == [tagging]
Esempio n. 11
0
def tagging():
    return models.Tagging('tagging-id', 'shop-id', 'tag-id')