Example #1
0
 def _get_auction_catalog(auction_id):
     catalog = postmeta.by_key(auction_id, 'katalog')
     if catalog is None:
         auction = models.Posts.query.filter_by(id=auction_id).first()
         if auction:
             catalog = postmeta.by_key(auction.post_parent, 'katalog')
     return catalog
def test_if_when_there_are_no_newer_revisions_then_original_post_is_returned(
        client):
    auction_test_id = 19819

    res = client.get('/api/auctions')
    data = json.loads(res.data.decode('utf-8'))

    auction_obj = None

    for obj in data:
        if obj['id'] == auction_test_id:
            auction_obj = obj
            break

    assert auction_obj

    real_auction_obj = models.Posts.query.filter_by(id=auction_test_id).first()

    assert real_auction_obj

    assert auction_obj['id'] == real_auction_obj.id
    assert auction_obj['title'] == real_auction_obj.post_title
    assert auction_obj['description_content'] == html_utils.clean(
        real_auction_obj.post_content)
    assert auction_obj['description_excerpt'] == html_utils.clean(
        real_auction_obj.post_excerpt)
    assert real_auction_obj.post_name in auction_obj['guid']
    assert auction_obj['auction_start'] == postmeta.by_key(
        real_auction_obj.id, 'aukcja_start')
    assert auction_obj['auction_end'] == postmeta.by_key(
        real_auction_obj.id, 'aukcja_end')
    def _get_artwork_from_postmeta(self, artwork_id):
        sold = postmeta.by_key(artwork_id, 'oferta_status', '0')
        initial_price = postmeta.by_key(artwork_id, 'oferta_cena', '')
        sold_price = postmeta.by_key(artwork_id, 'oferta_cena_sprzedazy', '')

        if not all([sold, initial_price, sold_price]):
            catalog_data = models.Postmeta.query.filter(
                models.Postmeta.meta_key == 'katalog',
                models.Postmeta.meta_value.like(
                    f'%:"{artwork_id}";%')).first()

            if catalog_data:
                self._set_featured_catalogs(catalog_data)
                meta_val = to_dict(catalog_data.meta_value)
                for d in meta_val.values():
                    if isinstance(
                            d,
                            dict) and 'id' in d and d['id'] == str(artwork_id):
                        return {
                            'sold': string_to_bool(d.get('sprzedana', '0')),
                            'initial_price': d.get('cena_wywolawcza', ''),
                            'sold_price': d.get('cena_sprzedazy', ''),
                            'after_auction_price':
                            d.get('cena_poaukcyjna', ''),
                        }

        return {
            'sold': string_to_bool(sold),
            'initial_price': initial_price,
            'sold_price': sold_price
        }
 def _perform_realness_test(auction_obj):
     real_auction_obj = models.Posts.query.filter_by(id=auction_obj.id).first()
     assert auction_obj['id'] == real_auction_obj.id
     assert auction_obj['title'] == real_auction_obj.post_title
     assert auction_obj['description_content'] == real_auction_obj.post_content
     assert auction_obj['description_excerpt'] == real_auction_obj.post_excerpt
     assert real_auction_obj.post_name in auction_obj['guid']
     assert auction_obj['auction_start'] == postmeta.by_key(real_auction_obj.id, 'aukcja_start')
     assert auction_obj['auction_end'] == postmeta.by_key(real_auction_obj.id, 'aukcja_end')
def test_if_when_there_exists_newer_revision_then_it_is_returned_instead(
        client):
    auction_test_id = 16123

    res = client.get('/api/auctions')
    data = json.loads(res.data.decode('utf-8'))

    auction_obj = None

    for obj in data:
        if obj['id'] == auction_test_id:
            auction_obj = obj
            break

    assert auction_obj

    real_parent = models.Posts.query.filter_by(id=auction_test_id).first()

    assert real_parent

    new_revision = models.Posts.query.filter_by(
        post_parent=real_parent.id).order_by(
            models.Posts.post_modified.desc()).first()

    assert new_revision

    assert auction_obj['id'] == real_parent.id
    assert auction_obj['title'] == new_revision.post_title
    assert auction_obj['description_content'] == html_utils.clean(
        new_revision.post_content)
    assert auction_obj['description_excerpt'] == html_utils.clean(
        new_revision.post_excerpt)
    assert real_parent.post_name in auction_obj['guid']
    assert auction_obj['auction_start'] == postmeta.by_key(
        real_parent.id, 'aukcja_start')
    assert auction_obj['auction_end'] == postmeta.by_key(
        real_parent.id, 'aukcja_end')
    assert auction_obj['image_thumbnail'] == thumbnails.by_id(
        real_parent.id)['image_thumbnail']
    def _get_artwork_from_post(self, artwork_post, author=None):
        artwork_id = artwork_post.id

        author_id = getattr(author, 'term_id', '')
        author_name = getattr(author, 'name', '')

        result = {
            'id':
            artwork_id,
            'title':
            getattr(artwork_post, 'post_title', ''),
            'author_id':
            author_id,
            'author':
            author_name,
            'description':
            html_utils.clean(getattr(artwork_post, 'post_content', '')),
            'year':
            postmeta.by_key(artwork_id, 'oferta_rok', ''),
            **thumbnails.by_id(artwork_id),
        }
        sold_info = self._get_artwork_from_postmeta(artwork_id) or {}

        return {**result, **sold_info}
Example #7
0
def test_by_key_returns_default_if_postmeta_not_exists(app):
    assert 'someDefault' == postmeta.by_key(post_id=29464,
                                            key='aukcja_end',
                                            default='someDefault')
Example #8
0
def test_by_key_returns_meta_value_if_postmeta_exists(app):
    assert '0' == postmeta.by_key(post_id=29727,
                                  key='aukcja_status',
                                  default='10')