Esempio n. 1
0
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)
Esempio n. 2
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
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
Esempio n. 4
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
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