コード例 #1
0
ファイル: __init__.py プロジェクト: ngokevin/flue
def review(**kw):
    global counter
    counter += 1

    version = None
    if rand_bool():
        version = {
            'name': random.randint(1, 3),
            'latest': False,
        }

    return dict({
        'rating': random.randint(1, 5),
        'body': rand_text(n=20),
        'created': rand_datetime(),
        'is_flagged': False,
        'is_author': False,
        'modified': rand_datetime(),
        'report_spam': '/api/v1/apps/rating/%d/flag/' % counter,
        'resource_uri': '/api/v1/apps/rating/%d/' % counter,
        'user': {
            'display_name': text(random.choice(USER_NAMES)),
            'id': counter,
        },
        'version': version,
    }, **kw)
コード例 #2
0
def review(slug=None, **kw):
    global counter
    counter += 1

    version = None
    if rand_bool():
        version = {"name": random.randint(1, 3), "latest": False}

    data = dict(
        {
            "rating": random.randint(1, 5),
            "body": rand_text(n=20),
            "created": rand_datetime(),
            "has_flagged": False,
            "is_author": False,
            "modified": rand_datetime(),
            "report_spam": "/api/v1/apps/rating/%d/flag/" % counter,
            "resource_uri": "/api/v1/apps/rating/%d/" % counter,
            "user": {"display_name": text(random.choice(USER_NAMES)), "id": counter},
            "version": version,
        },
        **kw
    )

    if slug == "has_flagged":
        data["has_flagged"] = True

    return data
コード例 #3
0
def review(slug=None, **kw):
    global review_counter
    review_counter += 1

    version = None
    if rand_bool():
        version = {
            'name': random.randint(1, 3),
            'latest': False,
        }

    data = dict({
        'rating': random.randint(1, 5),
        'body': rand_text(n=20),
        'created': rand_datetime(),
        'has_flagged': False,
        'is_author': False,
        'modified': rand_datetime(),
        'report_spam': '/api/v1/apps/rating/%d/flag/' % review_counter,
        'resource_uri': '/api/v1/apps/rating/%d/' % review_counter,
        'user': {
            'display_name': text(random.choice(USER_NAMES)),
            'id': review_counter,
        },
        'version': version,
    }, **kw)

    if slug == 'has_flagged':
        data['has_flagged'] = True

    return data
コード例 #4
0
def app_user_data(slug=None):
    data = {"user": {"developed": rand_bool()}}
    # Conditional slugs for great debugging.
    if slug == "developed":
        data["user"]["developed"] = True
    elif slug == "user":
        data["user"]["developed"] = False

    return data
コード例 #5
0
ファイル: __init__.py プロジェクト: ngokevin/flue
def app_user_data(slug=None):
    data = {
        'user': {
            'developed': rand_bool(),
        }
    }
    # Conditional slugs for great debugging.
    if slug == 'developed':
        data['user']['developed'] = True
    elif slug == 'user':
        data['user']['developed'] = False

    return data
コード例 #6
0
def app_user_data(slug=None):
    data = {
        'user': {
            'developed': rand_bool(),
        }
    }
    # Conditional slugs for great debugging.
    if slug == 'developed':
        data['user']['developed'] = True
    elif slug == 'user':
        data['user']['developed'] = False

    return data
コード例 #7
0
ファイル: __init__.py プロジェクト: ngokevin/flue
def app(**kw):
    """
    In the API everything here except `user` should be serialized and keyed off
    counter:region:locale.
    """
    global counter
    counter += 1

    slug = kw.get('slug', 'app-%d' % counter)

    data = {
        'id': SPECIAL_SLUGS_TO_IDS.get(slug, counter),
        'author': random.choice(AUTHORS),
        'categories': ['social', 'games'],
        'content_ratings': {
            'body': 'generic',
            'rating': '12',
            'descriptors': ['scary', 'lang', 'drugs'],
            'interactives': ['users-interact', 'shares-info']
        },
        'current_version': text('%d.0' % int(random.random() * 20)),
        'description': {'en-US': escape(kw.get('description',
                                               rand_text(100)))},
        'device_types': ['desktop', 'firefoxos', 'android-mobile',
                         'android-tablet'],
        'file_size': 12345,
        'homepage': 'http://marketplace.mozilla.org/',
        'icons': {
            64: '/media/img/logos/64.png'
        },
        'is_packaged': slug == 'packaged' or rand_bool(),
        'manifest_url':
            'http://%s%s.testmanifest.com/manifest.webapp' %
            (rand_text(1), random.randint(1, 50000)),  # Minifest if packaged
        'name': text('App %d' % counter),
        'notices': random.choice(MESSAGES),
        'previews': [_app_preview() for i in range(4)],
        'privacy_policy': kw.get('privacy_policy', rand_text()),
        'public_stats': False,
        'slug': slug,
        'ratings': {
            'average': random.random() * 4 + 1,
            'count': int(random.random() * 500),
        },
        'release_notes': kw.get('release_notes', rand_text(100)),
        'support_email': text('support@%s.com' % slug),
        'support_url': text('support.%s.com' % slug),
        'upsell': False,
    }

    has_price = rand_bool()
    price = '%.2f' % (random.random() * 10)
    if slug == 'free':
        has_price = False
    elif slug == 'paid':
        has_price = True
        price = '0.99'

    if slug == 'upsell':
        data['upsell'] = {
            'id': random.randint(1, 10000),
            'name': rand_text(),
            'icon_url': '/media/img/logos/firefox-256.png',
            'app_slug': 'upsold',
            'resource_uri': '/api/v1/fireplace/app/%s/' % 'upsold',
        }

    if has_price:
        data.update(price=price, price_locale='$%s' % price)
    else:
        data.update(price=None, price_locale='$0.00')

    data['payment_required'] = has_price

    if slug == 'packaged':
        data['current_version'] = '1.0'

    if slug in SPECIAL_APP_SLUGS:
        data['name'] = string.capwords(slug.replace('_', ' '))

    data.update(app_user_data(slug))

    return dict(data, **kw)
コード例 #8
0
def app(**kw):
    """
    In the API everything here except `user` should be serialized and keyed off
    counter:region:locale.
    """
    global counter
    counter += 1

    num_previews = kw.get('num_previews', 4)
    slug = kw.get('slug', 'app-%d' % counter)

    data = {
        'id': SPECIAL_SLUGS_TO_IDS.get(slug, counter),
        'author': random.choice(AUTHORS),
        'categories': ['social', 'games'],
        'content_ratings': {
            'body': 'generic',
            'rating': '12',
            'descriptors': ['scary', 'lang', 'drugs'],
            'interactives': ['users-interact', 'shares-info']
        },
        'current_version': text('%d.0' % int(random.random() * 20)),
        'description': {'en-US': escape(kw.get('description',
                                               rand_text(100)))},
        'device_types': ['desktop', 'firefoxos', 'android-mobile',
                         'android-tablet', 'firefoxos-tv'],
        'file_size': 12345,
        'homepage': 'http://marketplace.mozilla.org/',
        'icons': {
            64: '/media/img/logos/64.png'
        },
        'is_packaged': slug == 'packaged' or rand_bool(),
        'last_updated': rand_datetime(),
        'manifest_url':
            # Minifest if packaged
            'http://%s.testmanifest.com/manifest.webapp' % slug,
        'name': text('App %d' % counter),
        'notices': random.choice(MESSAGES),
        'premium_type': 'free',
        'previews': [_app_preview() for i in range(num_previews)],
        'price': None,
        'price_locale': '$0.00',
        'promo_images': {
            'small': random.choice(PROMO_IMAGES),
            'large': random.choice(PROMO_IMAGES),
        },
        'privacy_policy': kw.get('privacy_policy', rand_text()),
        'public_stats': False,
        'slug': slug,
        'ratings': {
            'average': random.random() * 4 + 1,
            'count': int(random.random() * 500),
        },
        'release_notes': kw.get('release_notes', rand_text(100)),
        'support_email': text('support@%s.com' % slug),
        'support_url': text('support.%s.com' % slug),
        'tv_featured': random.choice([True, False]),
        'upsell': False,
    }

    data.update(app_user_data(slug))
    data = dict(data, **kw)

    # Special apps.
    if slug == 'paid':
        data.update(
            price=3.50,
            price_locale='$3.50',
            payment_required=True
        )
    elif slug == 'upsell':
        data['upsell'] = {
            'id': random.randint(1, 10000),
            'name': rand_text(),
            'icon_url': '/media/img/logos/firefox-256.png',
            'app_slug': 'upsold',
            'resource_uri': '/api/v1/fireplace/app/%s/' % 'upsold',
        }
    elif slug == 'packaged':
        data['current_version'] = '1.0'
    elif slug == 'unrated':
        data['ratings'] = {
            'average': 0,
            'count': 0,
        }
    elif slug == 'tracking':
        data['id'] = 1234
        data['author'] = 'Tracking'
        data['name'] = 'Tracking'
    elif slug.startswith('num-previews-'):
        data['previews'] = [_app_preview() for x in
                            range(int(slug.split('num-previews-')[1]))]

    if slug in SPECIAL_APP_SLUGS or slug.startswith('num-previews-'):
        data['name'] = string.capwords(
            slug.replace('_', ' ').replace('-', ' '))

    return data
コード例 #9
0
def app(**kw):
    """
    In the API everything here except `user` should be serialized and keyed off
    counter:region:locale.
    """
    global counter
    counter += 1

    num_previews = kw.get("num_previews", 4)
    slug = kw.get("slug", "app-%d" % counter)

    data = {
        "id": SPECIAL_SLUGS_TO_IDS.get(slug, counter),
        "author": random.choice(AUTHORS),
        "categories": ["social", "games"],
        "content_ratings": {
            "body": "generic",
            "rating": "12",
            "descriptors": ["scary", "lang", "drugs"],
            "interactives": ["users-interact", "shares-info"],
        },
        "current_version": text("%d.0" % int(random.random() * 20)),
        "description": {"en-US": escape(kw.get("description", rand_text(100)))},
        "device_types": ["desktop", "firefoxos", "android-mobile", "android-tablet"],
        "file_size": 12345,
        "homepage": "http://marketplace.mozilla.org/",
        "icons": {64: "/media/img/logos/64.png"},
        "is_packaged": slug == "packaged" or rand_bool(),
        "last_updated": rand_datetime(),
        "manifest_url":
        # Minifest if packaged
        "http://%s.testmanifest.com/manifest.webapp" % slug,
        "name": text("App %d" % counter),
        "notices": random.choice(MESSAGES),
        "premium_type": "free",
        "previews": [_app_preview() for i in range(num_previews)],
        "price": None,
        "price_locale": "$0.00",
        "privacy_policy": kw.get("privacy_policy", rand_text()),
        "public_stats": False,
        "slug": slug,
        "ratings": {"average": random.random() * 4 + 1, "count": int(random.random() * 500)},
        "release_notes": kw.get("release_notes", rand_text(100)),
        "support_email": text("support@%s.com" % slug),
        "support_url": text("support.%s.com" % slug),
        "upsell": False,
    }

    data.update(app_user_data(slug))
    data = dict(data, **kw)

    # Special apps.
    if slug == "paid":
        data.update(price=3.50, price_locale="$3.50", payment_required=True)
    elif slug == "upsell":
        data["upsell"] = {
            "id": random.randint(1, 10000),
            "name": rand_text(),
            "icon_url": "/media/img/logos/firefox-256.png",
            "app_slug": "upsold",
            "resource_uri": "/api/v1/fireplace/app/%s/" % "upsold",
        }
    elif slug == "packaged":
        data["current_version"] = "1.0"
    elif slug == "unrated":
        data["ratings"] = {"average": 0, "count": 0}
    elif slug == "tracking":
        data["id"] = 1234
        data["author"] = "Tracking"
        data["name"] = "Tracking"
    elif slug.startswith("num-previews-"):
        data["previews"] = [_app_preview() for x in range(int(slug.split("num-previews-")[1]))]

    if slug in SPECIAL_APP_SLUGS or slug.startswith("num-previews-"):
        data["name"] = string.capwords(slug.replace("_", " ").replace("-", " "))

    return data
コード例 #10
0
ファイル: feed.py プロジェクト: ngokevin/flue
def collection(**kw):
    global counter
    counter += 1

    slug = 'collection-%s' % counter
    rand_color = random.choice(COLLECTION_COLORS)
    app_count = kw.get('app_count', 6)

    data = {
        'name': text('Collection %s' % counter),
        'id': counter,
        'slug': slug,
        'app_count': app_count,
        'type': 'listing',
        'description': random.choice([rand_text(n=20), '']),
        'apps': [app() for i in xrange(app_count)],
        'background_color': rand_color[1],
        'color': rand_color[0],
        'icon': 'http://f.cl.ly/items/103C0e0I1d1Q1f2o3K2B/'
                'mkt-collection-logo.png',
        'url': '/api/v2/feed/collections/%d/' % counter
    }

    if rand_bool():
        data['background_image'] = SAMPLE_BG,
        data['type'] = 'promo'

    data = dict(data, **kw)

    if data['slug'] == 'grouped':
        # Divide into three groups for mega collections.
        data.update({
            'background_image': SAMPLE_BG,
            'description': rand_text(),
            'name': 'Mega Collection',
            'type': 'promo'
        })
        for i, _app in enumerate(data['apps']):
            if i < data['app_count'] / 3:
                _app['group'] = 'Group 1'
            elif i < data['app_count'] * 2 / 3:
                _app['group'] = 'Group 2'
            else:
                _app['group'] = 'Group 3'
    elif data['slug'] == 'coll-promo':
        data.update({
            'name': 'Coll Promo',
            'type': 'promo',
        })
    elif data['slug'] == 'coll-promo-desc':
        data.update({
            'description': rand_text(),
            'name': 'Coll Promo Desc',
            'type': 'promo',
        })
    elif data['slug'] == 'coll-promo-bg':
        data.update({
            'background_image': SAMPLE_BG,
            'name': 'Coll Promo Background',
            'type': 'promo',
        })
    elif data['slug'] == 'coll-promo-bg-desc':
        data.update({
            'background_image': SAMPLE_BG,
            'description': rand_text(),
            'name': 'Coll Promo Background Desc',
            'type': 'promo',
        })
    elif data['slug'] == 'coll-listing':
        data.update({
            'name': 'Coll Listing',
            'type': 'listing',
        })
    elif data['slug'] == 'coll-listing-desc':
        data.update({
            'description': rand_text(),
            'name': 'Coll Listing Desc',
            'type': 'listing',
        })

    return data
コード例 #11
0
def collection(**kw):
    global counter
    counter += 1

    slug = 'collection-%s' % counter
    rand_color = random.choice(COLLECTION_COLORS)
    app_count = kw.get('app_count', 6)

    data = {
        'name': text('Collection %s' % counter),
        'id': counter,
        'slug': slug,
        'app_count': app_count,
        'type': 'listing',
        'description': '',
        'apps': [app() for i in xrange(app_count)],
        'background_color': rand_color[1],
        'color': rand_color[0],
        'icon': 'http://f.cl.ly/items/103C0e0I1d1Q1f2o3K2B/'
                'mkt-collection-logo.png',
        'url': '/api/v2/feed/collections/%d/' % counter
    }

    if rand_bool():
        data['background_image'] = SAMPLE_BG,
        data['type'] = 'promo'

    data = dict(data, **kw)

    if data['slug'] == 'grouped':
        # Divide into three groups for mega collections.
        data.update({
            'background_image': SAMPLE_BG,
            'description': rand_text(n=100),
            'name': 'Mega Collection',
            'type': 'promo'
        })
        for i, _app in enumerate(data['apps']):
            if i < data['app_count'] / 3:
                _app['group'] = 'Group 1'
            elif i < data['app_count'] * 2 / 3:
                _app['group'] = 'Group 2'
            else:
                _app['group'] = 'Group 3'
    elif data['slug'] == 'coll-promo':
        data.update({
            'name': 'Coll Promo',
            'type': 'promo',
        })
    elif data['slug'] == 'coll-promo-desc':
        data.update({
            'background_image': '',
            'description': rand_text(n=100),
            'name': 'Coll Promo Desc',
            'type': 'promo',
        })
    elif data['slug'] == 'coll-promo-bg':
        data.update({
            'background_image': SAMPLE_BG,
            'description': '',
            'name': 'Coll Promo Background',
            'type': 'promo',
        })
    elif data['slug'] == 'coll-promo-bg-desc':
        data.update({
            'background_image': SAMPLE_BG,
            'description': rand_text(n=100),
            'name': 'Coll Promo Background Desc',
            'type': 'promo',
        })
    elif data['slug'] == 'coll-listing':
        data.update({
            'name': 'Coll Listing',
            'type': 'listing',
        })
    elif data['slug'] == 'coll-listing-desc':
        data.update({
            'description': rand_text(n=100),
            'name': 'Coll Listing Desc',
            'type': 'listing',
        })

    return data