Ejemplo n.º 1
0
    def test_create_or_modify_with_relationships_search(self, app):
        # Given
        offer = Offer.create_or_modify(
            {
                '__SEARCH_BY__': 'name',
                'name': 'foo',
                'type': 'bar'
            },
            with_add=True,
            with_flush=True)
        tag = Tag.create_or_modify({
            '__SEARCH_BY__': 'label',
            'label': 'car'
        },
                                   with_add=True,
                                   with_flush=True)

        # When
        offer_tag = OfferTag.create_or_modify({
            '__SEARCH_BY__': ['offer', 'tag'],
            'offer': offer,
            'tag': tag
        })

        #Then
        assert offer.id != None
        assert offer.name == 'foo'
        assert offer.type == 'bar'
        assert tag.id != None
        assert tag.label == 'car'
        assert offer_tag.id == None
Ejemplo n.º 2
0
    def test_dictify_with_sync_map(self, app):
        # given
        offer = Offer(name='foo', type='bar')
        tag1 = Tag(label='beep')
        offer_tag1 = OfferTag(offer=offer, tag=tag1)
        tag2 = Tag(label='boop')
        offer_tag2 = OfferTag(offer=offer, tag=tag2)

        # when
        includes = [{'key': 'offerTags', 'includes': ['tag']}]
        offer_dict = as_dict(offer, includes=includes)

        # then
        assert len(offer_dict['offerTags']) == 2
        assert offer_dict['offerTags'][0]['tag']['label'] == 'beep'
        assert offer_dict['offerTags'][1]['tag']['label'] == 'boop'
Ejemplo n.º 3
0
    def test_dictify_with_async_map_join(self, app):
        # given
        offer_tags_count = 10
        offer = Offer(name='foo', type='bar')
        offer_tags = []
        for index in range(0, offer_tags_count):
            tag = Tag(label=str(index))
            offer_tags.append(OfferTag(offer=offer, tag=tag))

        # when
        includes = [{'key': '|offerTags', 'includes': ['tag']}]
        offer_dict = as_dict(offer, includes=includes)

        # then
        assert len(offer_dict['offerTags']) == offer_tags_count
        for index in range(0, offer_tags_count):
            assert offer_dict['offerTags'][index]['tag']['label'] == str(index)
            assert offer_dict['offerTags'][index]['tag']['sleptFoo'] == 0
Ejemplo n.º 4
0
    def test_dictify_with_async_map_key(self, app):
        # given
        offer_tags_count = 10
        offer = Offer(name='foo', type='bar')
        offer_tags = []
        for index in range(0, offer_tags_count):
            tag = Tag(label=str(index))
            offer_tags.append(OfferTag(offer=offer, tag=tag))

        # when
        includes = ['|offerTags']
        offer_dict = as_dict(offer, includes=includes)

        # then
        assert len(offer_dict['offerTags']) == offer_tags_count
        for index in range(0, offer_tags_count):
            assert offer_dict['offerTags'][index]['tagId'] == offer_tags[
                index].id
Ejemplo n.º 5
0
    def test_dictify_with_custom_async_map(self, app):
        # given
        offer_tags_count = 10
        offer = Offer(name='foo', type='bar')
        offer_tags = []
        for index in range(0, offer_tags_count):
            tag = Tag(label=str(index))
            offer_tags.append(OfferTag(offer=offer, tag=tag))

        # when
        includes = [{'key': '|offerTags', 'includes': ['tag']}]
        with ThreadPoolExecutor(max_workers=5) as executor:
            offer_dict = as_dict(offer,
                                 async_map=executor.map,
                                 includes=includes)

            # then
            assert len(offer_dict['offerTags']) == offer_tags_count
            for index in range(0, offer_tags_count):
                assert offer_dict['offerTags'][index]['tag']['label'] == str(
                    index)
                assert offer_dict['offerTags'][index]['tag']['sleptFoo'] == 0