Exemple #1
0
def website(**kw):
    global website_counter
    website_counter += 1

    domain = '%s.example.com' % rand_text(2, separator='')
    data = {
        'categories': [
            'news-weather'
        ],
        'description': {
            'en-US': escape(kw.get('description', rand_text(30))),
        },
        'device_types': [
            'firefoxos'
        ],
        'icons': {
            '64': '%s/media/img/mkt/logos/64.png' % CDN_URL,
            '128': '%s/media/img/mkt/logos/128.png' % CDN_URL,
        },
        'id': website_counter,
        'mobile_url': 'http://m.%s/' % domain,
        'name': {
            'en-US': text('Website %d' % website_counter),
        },
        'short_name': {
            'en-US': text('Site %d' % website_counter),
        },
        'title': {
            'en-US': text('Website Title %d' % website_counter),
        },
        'url': 'http://%s/' % domain
    }
    data = dict(data, **kw)
    return data
Exemple #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
Exemple #3
0
def shelf(**kw):
    global counter
    counter += 1

    _carrier = carrier()['slug']
    app_count = kw.get('app_count', 6)

    data = {
        'apps': [app() for i in xrange(app_count)],
        'app_count': app_count,
        'background_image': SAMPLE_BG,
        'background_image_landing': SAMPLE_BG,
        'carrier': _carrier,
        'description': '',
        'id': counter,
        'name': '%s Op Shelf' % _carrier.replace('_', ' ').capitalize(),
        'region': 'restofworld',
        'slug': 'shelf-%d' % counter,
        'url': '/api/v2/feed/shelves/%d/' % counter
    }

    data = dict(data, **kw)

    if data['slug'] == 'shelf':
        data.update({
            'name': 'Shelf'
        })
    elif data['slug'] == 'shelf-desc':
        data.update({
            'description': rand_text(),
            'name': 'Shelf Description'
        })

    return data
Exemple #4
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)
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
Exemple #6
0
def shelf(**kw):
    global counter
    counter += 1

    _carrier = carrier()['slug']
    app_count = kw.get('app_count', 6)

    data = {
        'apps': [app() for i in xrange(app_count)],
        'app_count': app_count,
        'background_image': SAMPLE_BG,
        'background_image_landing': SAMPLE_BG,
        'carrier': _carrier,
        'description': '',
        'id': counter,
        'name': '%s Op Shelf' % _carrier.replace('_', ' ').capitalize(),
        'region': 'restofworld',
        'slug': 'shelf-%d' % counter,
        'url': '/api/v2/feed/shelves/%d/' % counter
    }

    data = dict(data, **kw)

    if data['slug'] == 'shelf':
        data.update({
            'name': 'Shelf'
        })
    elif data['slug'] == 'shelf-desc':
        data.update({
            'description': rand_text(),
            'name': 'Shelf Description'
        })

    return data
def _app_preview():
    """Generate app preview object."""
    url = "https://marketplace.cdn.mozilla.net/" "img/uploads/previews/%%s/%d/%d.png" % random.choice(SCREENSHOT_MAP)
    return {
        "caption": rand_text(n=5),
        "filetype": "image/png",
        "thumbnail_url": url % "thumbs",
        "image_url": url % "full",
    }
Exemple #8
0
def _app_preview():
    """Generate app preview object."""
    url = ('https://marketplace.cdn.mozilla.net/'
           'img/uploads/previews/%%s/%d/%d.png' %
           random.choice(SCREENSHOT_MAP))
    return {
        'caption': rand_text(n=5),
        'filetype': 'image/png',
        'thumbnail_url': url % 'thumbs',
        'image_url': url % 'full',
    }
Exemple #9
0
def _app_preview():
    """Generate app preview object."""
    url = ('https://marketplace.cdn.mozilla.net/'
           'img/uploads/previews/%%s/%d/%d.png' %
           random.choice(SCREENSHOT_MAP))
    return {
        'caption': rand_text(n=5),
        'filetype': 'image/png',
        'thumbnail_url': url % 'thumbs',
        'image_url': url % 'full',
    }
Exemple #10
0
def feed_app(**kw):
    pullquote_text = '"' + rand_text(n=12) + '"'
    description = random.choice([rand_text(n=20), ''])
    feedapp_type = random.choice(FEED_APP_TYPES)
    rand_color = random.choice(COLLECTION_COLORS)

    return dict({
        'app': app(),
        'background_color': rand_color[1],
        'color': rand_color[0],
        'description': description,
        'type': FEED_APP_TYPES[0],
        'background_image': SAMPLE_BG,
        'id': counter,
        'preview': preview(),
        'pullquote_attribute': random.choice(AUTHORS),
        'pullquote_rating': random.randint(1, 5),
        'pullquote_text': pullquote_text,
        'slug': 'feed-app-%d' % counter,
        'url': '/api/v2/feed/apps/%d' % counter
    }, **kw)
Exemple #11
0
def feed_app(**kw):
    pullquote_text = '"' + rand_text(n=12) + '"'
    description = random.choice([rand_text(n=20), ''])
    feedapp_type = random.choice(FEED_APP_TYPES)
    rand_color = random.choice(COLLECTION_COLORS)

    return dict({
        'app': app(),
        'background_color': rand_color[1],
        'color': rand_color[0],
        'description': description,
        'type': FEED_APP_TYPES[0],
        'background_image': SAMPLE_BG,
        'id': counter,
        'preview': preview(),
        'pullquote_attribute': random.choice(AUTHORS),
        'pullquote_rating': random.randint(1, 5),
        'pullquote_text': pullquote_text,
        'slug': 'feed-app-%d' % counter,
        'url': '/api/v2/feed/apps/%d' % counter
    }, **kw)
Exemple #12
0
def extension(**kw):
    global extension_counter
    extension_counter += 1
    slug = kw.get('slug', 'add-on-%d' % extension_counter)
    uuid = unicode(uuid4()).replace('-', '')

    data = {
        'id': SPECIAL_SLUGS_TO_IDS.get(slug, extension_counter),
        'author': random.choice(AUTHORS),
        'description': {
            'en-US': escape(kw.get('description', rand_text(20))),
        },
        'device_types': [
            'firefoxos'
        ],
        'disabled': False,
        'icons': {
            '64': '%s/media/img/mkt/logos/64.png' % CDN_URL,
            '128': '%s/media/img/mkt/logos/128.png' % CDN_URL,
        },
        'last_updated': '2015-10-30T15:50:40',
        'latest_public_version': {
            'id': 294,
            'created': '2015-10-29T13:53:12',
            'download_url': '/extension/%s/42/extension-0.1.zip' % uuid,
            'reviewer_mini_manifest_url':
                '/extension/reviewers/%s/42/manifest.json' % uuid,
            'unsigned_download_url':
                '/downloads/extension/unsigned/%s/42/extension-0.1.zip' % uuid,
            'size': 19062,
            'status': 'public',
            'version': '0.1'
        },
        'mini_manifest_url': '/extension/%s/manifest.json' % uuid,
        'name': {
            'en-US': text('Add-on %d' % extension_counter),
        },
        'slug': slug,
        'status': 'public',
        'uuid': uuid,
    }
    data = dict(data, **kw)
    return data
Exemple #13
0
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)
Exemple #14
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
Exemple #15
0
def app_user_review(slug, **kw):
    data = {
        'body': kw.get('review', rand_text()),
        'rating': 4
    }
    return data
Exemple #16
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
Exemple #17
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': 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
Exemple #18
0
def app_user_review(slug, **kw):
    data = {
        'body': kw.get('review', rand_text()),
        'rating': 4
    }
    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
def app_user_review(slug, **kw):
    data = {"body": kw.get("review", rand_text()), "rating": 4}
    return data