示例#1
0
def app_factory(**kw):
    """
    Create an app. Keyword arguments are passed to addon_factory.

    complete -- fills out app details + creates content ratings.
    rated -- creates content ratings
    """
    complete = kw.pop('complete', False)
    rated = kw.pop('rated', False)
    if complete:
        kw.setdefault('support_email', '*****@*****.**')

    kw.update(type=amo.ADDON_WEBAPP)
    app = amo.tests.addon_factory(**kw)

    if rated or complete:
        make_rated(app)

    if complete:
        if not app.categories:
            app.update(categories=['utilities'])
        app.addondevicetype_set.create(device_type=DEVICE_TYPES.keys()[0])
        app.previews.create()

    return app
示例#2
0
def device_list(product):
    device_types = product.device_types
    if device_types:
        t = env.get_template('detail/helpers/device_list.html')
        return jinja2.Markup(t.render({
            'device_types': device_types,
            'all_device_types': DEVICE_TYPES.values()}))
示例#3
0
    def _step(self):
        self.user.update(read_dev_agreement=datetime.datetime.now())
        self.cl = AppSubmissionChecklist.objects.create(addon=self.webapp, terms=True, manifest=True)

        # Associate app with user.
        AddonUser.objects.create(addon=self.webapp, user=self.user)

        # Associate device type with app.
        self.dtype = DEVICE_TYPES.values()[0]
        AddonDeviceType.objects.create(addon=self.webapp, device_type=self.dtype.id)
        self.device_types = [self.dtype]

        # Associate category with app.
        self.webapp.update(categories=[self.cat1])
示例#4
0
    def setUp(self):
        super(TestVersionPackaged, self).setUp()
        self.login('*****@*****.**')
        self.app.update(is_packaged=True)
        self.app = self.get_app()
        # Needed for various status checking routines on fully complete apps.
        make_rated(self.app)
        if not self.app.categories:
            self.app.update(categories=['utilities'])
        self.app.addondevicetype_set.create(device_type=DEVICE_TYPES.keys()[0])
        self.app.previews.create()

        self.url = self.app.get_dev_url('versions')
        self.delete_url = self.app.get_dev_url('versions.delete')
    def setUp(self):
        super(TestVersionPackaged, self).setUp()
        self.login('*****@*****.**')
        self.app.update(is_packaged=True)
        self.app = self.get_app()
        # Needed for various status checking routines on fully complete apps.
        make_rated(self.app)
        if not self.app.categories:
            self.app.update(categories=['utilities'])
        self.app.addondevicetype_set.create(device_type=DEVICE_TYPES.keys()[0])
        self.app.previews.create()

        self.url = self.app.get_dev_url('versions')
        self.delete_url = self.app.get_dev_url('versions.delete')
示例#6
0
def website_factory(**kwargs):
    text = rand_text()
    data = {
        'description': 'Description for %s' % text.capitalize(),
        'name': text.capitalize(),
        'short_name': text[:10].capitalize(),
        'status': STATUS_PUBLIC,
        'title': 'Title for %s' % text.capitalize(),
        'url': 'http://%s.example.com' % text,
        'mobile_url': 'http://mobile.%s.example.com' % text,
        'devices': DEVICE_TYPES.keys(),
    }
    data.update(kwargs)
    return Website.objects.create(**data)
示例#7
0
    def _step(self):
        self.user.update(read_dev_agreement=datetime.datetime.now())
        self.cl = AppSubmissionChecklist.objects.create(addon=self.webapp,
                                                        terms=True,
                                                        manifest=True)

        # Associate app with user.
        AddonUser.objects.create(addon=self.webapp, user=self.user)

        # Associate device type with app.
        self.dtype = DEVICE_TYPES.values()[0]
        AddonDeviceType.objects.create(addon=self.webapp,
                                       device_type=self.dtype.id)
        self.device_types = [self.dtype]

        # Associate category with app.
        self.webapp.update(categories=[self.cat1])
示例#8
0
    def test_additional_info(self):
        """
        One of the ways `additional_info` is used it to pass the device type of
        the request and filter apps by device.
        """
        # By default app_factory creates apps with device being
        # DEVICE_TYPES.keys()[0]. Let's change a couple and query by that
        # device.
        device = DEVICE_TYPES.keys()[1]
        self.apps[0].addondevicetype_set.create(device_type=device)
        self.apps[1].addondevicetype_set.create(device_type=device)
        # Reindex b/c we changed an off-model attribute.
        self.reindex(Webapp, 'webapp')

        sq = WebappIndexer.get_app_filter(self.request, {'device': device},
                                          app_ids=self.app_ids)
        results = sq.execute().hits
        eq_(len(results), 2)
示例#9
0
    def test_additional_info(self):
        """
        One of the ways `additional_info` is used it to pass the device type of
        the request and filter apps by device.
        """
        # By default app_factory creates apps with device being
        # DEVICE_TYPES.keys()[0]. Let's change a couple and query by that
        # device.
        device = DEVICE_TYPES.keys()[1]
        self.apps[0].addondevicetype_set.create(device_type=device)
        self.apps[1].addondevicetype_set.create(device_type=device)
        # Reindex b/c we changed an off-model attribute.
        self.reindex(Webapp, 'webapp')

        sq = WebappIndexer.get_app_filter(self.request, {'device': device},
                                          app_ids=self.app_ids)
        results = sq.execute().hits
        eq_(len(results), 2)
示例#10
0
    def test_extract_device(self):
        device = DEVICE_TYPES.keys()[0]
        AddonDeviceType.objects.create(addon=self.app, device_type=device)

        obj, doc = self._get_doc()
        eq_(doc['device'], [device])
示例#11
0
    def test_extract_device(self):
        device = DEVICE_TYPES.keys()[0]
        AddonDeviceType.objects.create(addon=self.app, device_type=device)

        obj, doc = self._get_doc()
        eq_(doc['device'], [device])
示例#12
0
文件: utils.py 项目: clouserw/zamboni
def app_factory(status=mkt.STATUS_PUBLIC, version_kw={}, file_kw={}, **kw):
    """
    Create an app.

    complete -- fills out app details + creates content ratings.
    rated -- creates content ratings

    """
    from mkt.webapps.models import update_search_index, Webapp
    # Disconnect signals until the last save.
    post_save.disconnect(update_search_index, sender=Webapp,
                         dispatch_uid='webapp.search.index')

    complete = kw.pop('complete', False)
    rated = kw.pop('rated', False)
    if complete:
        kw.setdefault('support_email', '*****@*****.**')
    when = _get_created(kw.pop('created', None))

    # Keep as much unique data as possible in the uuid: '-' aren't important.
    name = kw.pop('name',
                  u'Webapp %s' % unicode(uuid.uuid4()).replace('-', ''))

    kwargs = {
        # Set artificially the status to STATUS_PUBLIC for now, the real
        # status will be set a few lines below, after the update_version()
        # call. This prevents issues when calling app_factory with
        # STATUS_DELETED.
        'status': mkt.STATUS_PUBLIC,
        'name': name,
        'app_slug': name.replace(' ', '-').lower()[:30],
        'bayesian_rating': random.uniform(1, 5),
        'created': when,
        'last_updated': when,
    }
    kwargs.update(kw)

    # Save 1.
    app = Webapp.objects.create(**kwargs)
    version = version_factory(file_kw, addon=app, **version_kw)  # Save 2.
    app.status = status
    app.update_version()

    # Put signals back.
    post_save.connect(update_search_index, sender=Webapp,
                      dispatch_uid='webapp.search.index')

    app.save()  # Save 4.

    if 'nomination' in version_kw:
        # If a nomination date was set on the version, then it might have been
        # erased at post_save by addons.models.watch_status() or
        # mkt.webapps.models.watch_status().
        version.save()

    if rated or complete:
        make_rated(app)

    if complete:
        if not app.categories:
            app.update(categories=['utilities'])
        app.addondevicetype_set.create(device_type=DEVICE_TYPES.keys()[0])
        app.previews.create()

    return app
示例#13
0
def app_factory(status=amo.STATUS_PUBLIC, version_kw={}, file_kw={}, **kw):
    """
    Create an app.

    complete -- fills out app details + creates content ratings.
    rated -- creates content ratings

    """
    # Disconnect signals until the last save.
    post_save.disconnect(app_update_search_index,
                         sender=Webapp,
                         dispatch_uid='webapp.search.index')

    complete = kw.pop('complete', False)
    rated = kw.pop('rated', False)
    if complete:
        kw.setdefault('support_email', '*****@*****.**')
    popularity = kw.pop('popularity', None)
    when = _get_created(kw.pop('created', None))

    # Keep as much unique data as possible in the uuid: '-' aren't important.
    name = kw.pop('name',
                  u'Webapp %s' % unicode(uuid.uuid4()).replace('-', ''))

    kwargs = {
        # Set artificially the status to STATUS_PUBLIC for now, the real
        # status will be set a few lines below, after the update_version()
        # call. This prevents issues when calling app_factory with
        # STATUS_DELETED.
        'status': amo.STATUS_PUBLIC,
        'name': name,
        'slug': name.replace(' ', '-').lower()[:30],
        'bayesian_rating': random.uniform(1, 5),
        'weekly_downloads': popularity or random.randint(200, 2000),
        'created': when,
        'last_updated': when,
    }
    kwargs.update(kw)

    # Save 1.
    app = Webapp.objects.create(**kwargs)
    version = version_factory(file_kw, addon=app, **version_kw)  # Save 2.
    app.status = status
    app.update_version()

    # Put signals back.
    post_save.connect(app_update_search_index,
                      sender=Webapp,
                      dispatch_uid='webapp.search.index')

    app.save()  # Save 4.

    if 'nomination' in version_kw:
        # If a nomination date was set on the version, then it might have been
        # erased at post_save by addons.models.watch_status() or
        # mkt.webapps.models.watch_status().
        version.save()

    if rated or complete:
        make_rated(app)

    if complete:
        if not app.categories:
            app.update(categories=['utilities'])
        app.addondevicetype_set.create(device_type=DEVICE_TYPES.keys()[0])
        app.previews.create()

    return app