Пример #1
0
    def test_create_or_modify_with_relationship_search(self, app):
        # Given
        offer = Offer.create_or_modify(
            {
                '__SEARCH_BY__': 'name',
                'name': 'foo',
                'type': 'bar'
            },
            with_add=True,
            with_flush=True)
        stock1 = Stock.create_or_modify({
            '__SEARCH_BY__': ['offer', 'price'],
            'offer': offer,
            'price': 2
        })

        # When
        stock2 = Stock.create_or_modify({
            '__SEARCH_BY__': ['offer', 'price'],
            'offer': offer,
            'price': 3
        })

        #Then
        assert offer.id != None
        assert offer.name == 'foo'
        assert offer.type == 'bar'
        assert stock1.offer.id == offer.id
        assert stock2.offer.id == offer.id
        assert stock1.id == None
        assert stock2.id == None
Пример #2
0
    def test_create_or_modify_with_flatten_new_datum(self, app):
        # Given
        datum = {
            'offer.name': 'foo',
            'offer.offerTags.0.tag.label': 'bar',
            'offer.type': 'bar',
            'price': 2
        }

        # When
        stock = Stock.create_or_modify(datum)

        # Then
        for (key, value) in datum.items():
            assert stock.get(key) == value

        stock = Stock.create_or_modify(datum)
        for (key, value) in datum.items():
            assert stock.get(key) == value
Пример #3
0
    def test_create_or_modify_with_flatten_search_existing_datum(self, app):
        # Given
        offer = Offer(name='foo', type='bar')
        ApiHandler.save(offer)
        datum = {
            'offer.name': 'foo',
            'offer.__SEARCH_BY__': 'name',
            'offer.type': 'bar',
            'price': 2,
        }

        # When
        stock = Stock.create_or_modify(datum)

        # Then
        for (key, value) in datum.items():
            if key.endswith('__SEARCH_BY__'):
                continue
            assert stock.get(key) == value
        assert stock.offer.id == offer.id