예제 #1
0
    def formset_media(self, prev_blank=None, *args, **kw):
        prev_blank = prev_blank or {}
        kw.setdefault("initial_count", 0)
        kw.setdefault("prefix", "files")

        # Preview formset.
        fs = formset(*list(args) + [self.formset_new_form(**prev_blank)], **kw)

        # Image asset formset
        assets = len(APP_IMAGE_SIZES)
        kw = {"initial_count": assets, "prefix": "images"}
        fs.update(formset(*repeat({"upload_hash": ""}, assets), **kw))

        return dict((k, "" if v is None else v) for k, v in fs.items())
예제 #2
0
    def formset_media(self, prev_blank=None, *args, **kw):
        prev_blank = prev_blank or {}
        kw.setdefault('initial_count', 0)
        kw.setdefault('prefix', 'files')

        # Preview formset.
        fs = formset(*list(args) + [self.formset_new_form(**prev_blank)], **kw)

        # Image asset formset
        assets = len(APP_IMAGE_SIZES)
        kw = {'initial_count': assets, 'prefix': 'images'}
        fs.update(formset(*repeat({'upload_hash': ''}, assets), **kw))

        return dict((k, '' if v is None else v) for k, v in fs.items())
예제 #3
0
    def test_content_flag_update(self):
        self.log_in_with("Apps:Configure")
        data = {"position": "-1", "child_content": "on"}
        r = self.client.post(self.edit_url, formset(**data))
        eq_(r.status_code, 200)
        webapp = self.get_webapp()
        eq_(webapp.has_flag("adult_content"), False)
        eq_(webapp.has_flag("child_content"), True)

        data = {"position": "-1", "adult_content": "on"}
        r = self.client.post(self.edit_url, formset(**data))
        eq_(r.status_code, 200)
        webapp = self.get_webapp()
        eq_(webapp.has_flag("adult_content"), True)
        eq_(webapp.has_flag("child_content"), False)
예제 #4
0
    def test_toggles(self):
        # Turn everything on.
        data = dict(developer_comments='Test comment!',
                    flash='checked')
        r = self.client.post(self.edit_url, formset(**data))
        self.assertNoFormErrors(r)
        expected = dict(developer_comments='Test comment!',
                        uses_flash=True)
        self.compare(expected)

        # And off.
        r = self.client.post(self.edit_url,
                             formset(developer_comments='Test comment!'))
        expected.update(uses_flash=False)
        self.compare(expected)
예제 #5
0
 def test_edit_categories_nonexistent(self):
     self.cat_initial['categories'] = [100]
     r = self.client.post(self.basic_edit_url, formset(self.cat_initial,
                                                       initial_count=1))
     eq_(r.context['cat_form'].errors[0]['categories'],
         ['Select a valid choice. 100 is not one of the available '
          'choices.'])
예제 #6
0
    def formset_media(self, blank_kw={}, *args, **kw):
        kw.setdefault('initial_count', 0)
        kw.setdefault('prefix', 'files')

        fs = formset(*[a for a in args] + [self.formset_new_form(**blank_kw)],
                     **kw)
        return dict([(k, '' if v is None else v) for k, v in fs.items()])
예제 #7
0
 def test_log(self):
     data = formset(developer_comments='This is a test')
     o = ActivityLog.objects
     eq_(o.count(), 0)
     r = self.client.post(self.edit_url, data)
     self.assertNoFormErrors(r)
     eq_(o.filter(action=amo.LOG.EDIT_PROPERTIES.id).count(), 1)
예제 #8
0
 def test_disabled_autocomplete_errors(self):
     """If any collection errors, autocomplete field should be enabled."""
     d = dict(application=amo.FIREFOX.id, collection=999)
     data = formset(self.initial, d, initial_count=1)
     r = self.client.post(self.url, data)
     doc = pq(r.content)
     assert not doc('#features .collection-ac[disabled]')
예제 #9
0
 def test_log(self):
     data = formset(developer_comments='This is a test')
     o = ActivityLog.objects
     eq_(o.count(), 0)
     r = self.client.post(self.edit_url, data)
     self.assertNoFormErrors(r)
     eq_(o.filter(action=amo.LOG.EDIT_PROPERTIES.id).count(), 1)
예제 #10
0
 def test_edit_categories_max(self):
     eq_(amo.MAX_CATEGORIES, 2)
     self.cat_initial['categories'] = [22, 23, 24]
     r = self.client.post(self.basic_edit_url, formset(self.cat_initial,
                                                       initial_count=1))
     eq_(r.context['cat_form'].errors[0]['categories'],
         ['You can have only 2 categories.'])
예제 #11
0
 def test_bad_locale(self):
     d = dict(application=amo.FIREFOX.id, locale='klingon', collection=80)
     data = formset(self.initial, d, initial_count=1)
     r = self.client.post(self.url, data)
     eq_(r.context['form'].errors[0]['locale'],
         ['Select a valid choice. klingon is not one of the available '
          'choices.'])
예제 #12
0
 def get_dict(self, **kw):
     fs = formset(self.cat_initial, initial_count=1)
     result = {'name': 'new name', 'slug': 'test_slug',
               'summary': 'new summary'}
     result.update(**kw)
     result.update(fs)
     return result
예제 #13
0
 def test_bad_app(self):
     d = dict(application=999, collection=80)
     data = formset(self.initial, d, initial_count=1)
     r = self.client.post(self.url, data)
     eq_(r.context['form'].errors[0]['application'],
         ['Select a valid choice. That choice is not one of the available '
          'choices.'])
예제 #14
0
 def test_disabled_autocomplete_errors(self):
     """If any collection errors, autocomplete field should be enabled."""
     d = dict(application=amo.FIREFOX.id, collection=999)
     data = formset(self.initial, d, initial_count=1)
     r = self.client.post(self.url, data)
     doc = pq(r.content)
     assert not doc('#features .collection-ac[disabled]')
예제 #15
0
    def _post(self, action):
        ctx = self.client.get(self.url).context
        data_formset = formset(initial(ctx['reviews_formset'].forms[0]))
        data_formset['form-0-action'] = action

        res = self.client.post(self.url, data_formset)
        self.assert3xx(res, self.url)
예제 #16
0
    def test_devcomment_optional(self):
        data = dict(developer_comments='')
        r = self.client.post(self.edit_url, formset(**data))
        self.assertNoFormErrors(r)

        expected = dict(developer_comments='')
        self.compare(expected)
예제 #17
0
 def test_success_insert(self):
     dupe = initial(self.f)
     del dupe['id']
     dupe.update(locale='fr')
     data = formset(initial(self.f), dupe, initial_count=1)
     r = self.client.post(self.url, data)
     eq_(FeaturedCollection.objects.count(), 2)
     eq_(FeaturedCollection.objects.all()[1].locale, 'fr')
예제 #18
0
 def test_bad_locale(self):
     d = dict(application=amo.FIREFOX.id, locale='klingon', collection=80)
     data = formset(self.initial, d, initial_count=1)
     r = self.client.post(self.url, data)
     eq_(r.context['form'].errors[0]['locale'], [
         'Select a valid choice. klingon is not one of the available '
         'choices.'
     ])
예제 #19
0
 def test_bad_app(self):
     d = dict(application=999, collection=80)
     data = formset(self.initial, d, initial_count=1)
     r = self.client.post(self.url, data)
     eq_(r.context['form'].errors[0]['application'], [
         'Select a valid choice. That choice is not one of the available '
         'choices.'
     ])
예제 #20
0
 def test_success_insert(self):
     dupe = initial(self.f)
     del dupe['id']
     dupe.update(locale='fr')
     data = formset(initial(self.f), dupe, initial_count=1)
     self.client.post(self.url, data)
     eq_(FeaturedCollection.objects.count(), 2)
     eq_(FeaturedCollection.objects.all()[1].locale, 'fr')
예제 #21
0
 def test_edit_categories_other_failure(self):
     Category.objects.get(id=22).update(misc=True)
     self.cat_initial['categories'] = [22, 23]
     r = self.client.post(self.basic_edit_url, formset(self.cat_initial,
                                                       initial_count=1))
     eq_(r.context['cat_form'].errors[0]['categories'],
         ['The miscellaneous category cannot be combined with additional '
          'categories.'])
예제 #22
0
 def get_dict(self, **kw):
     fs = formset(self.cat_initial, initial_count=1)
     result = {'name': 'new name', 'slug': 'test_slug',
               'summary': 'new summary',
               'tags': ', '.join(self.tags)}
     result.update(**kw)
     result.update(fs)
     return result
예제 #23
0
 def get_dict(self, **kw):
     fs = formset(self.cat_initial, initial_count=1)
     result = {'device_types': self.dtype.id, 'name': 'new name',
               'slug': 'test_slug', 'summary': 'new summary',
               'manifest_url': self.get_webapp().manifest_url}
     result.update(**kw)
     result.update(fs)
     return result
예제 #24
0
 def test_edit_categories_max(self):
     new1 = Category.objects.create(name='Books', type=amo.ADDON_WEBAPP)
     new2 = Category.objects.create(name='Lifestyle', type=amo.ADDON_WEBAPP)
     self.cat_initial['categories'] = [self.cat.id, new1.id, new2.id]
     r = self.client.post(self.edit_url,
                          formset(self.cat_initial, initial_count=1))
     eq_(r.context['cat_form'].errors[0]['categories'],
         ['You can have only 2 categories.'])
예제 #25
0
    def formset_media(self, blank_kw=None, *args, **kw):
        blank_kw = blank_kw or {}
        kw.setdefault('initial_count', 0)
        kw.setdefault('prefix', 'files')

        fs = formset(*[a for a in args] + [self.formset_new_form(**blank_kw)],
                     **kw)
        return dict([(k, '' if v is None else v) for k, v in fs.items()])
예제 #26
0
 def test_edit_categories_other_failure(self):
     new = Category.objects.create(type=amo.ADDON_WEBAPP, misc=True)
     self.cat_initial['categories'] = [self.cat.id, new.id]
     r = self.client.post(self.edit_url, formset(self.cat_initial,
                                                 initial_count=1))
     eq_(r.context['cat_form'].errors[0]['categories'],
         ['The miscellaneous category cannot be combined with additional '
          'categories.'])
예제 #27
0
 def test_edit_categories_max(self):
     new1 = Category.objects.create(name='Books', type=amo.ADDON_WEBAPP)
     new2 = Category.objects.create(name='Lifestyle', type=amo.ADDON_WEBAPP)
     self.cat_initial['categories'] = [self.cat.id, new1.id, new2.id]
     r = self.client.post(self.edit_url, formset(self.cat_initial,
                                                 initial_count=1))
     eq_(r.context['cat_form'].errors[0]['categories'],
         ['You can have only 2 categories.'])
예제 #28
0
 def test_success_add_owner(self):
     u = UserProfile.objects.get(id=999)
     u = dict(user=u.email, listed=True, role=amo.AUTHOR_ROLE_OWNER,
              position=0)
     r = self.client.post(self.url, formset(u, initial_count=0))
     self.assertRedirects(r, self.url, 302)
     owners = (AddonUser.objects.filter(addon=self.webapp.id)
               .values_list('user', flat=True))
     eq_(list(owners), [31337, 999])
예제 #29
0
 def test_edit_categories_other_failure(self):
     new = Category.objects.create(type=amo.ADDON_WEBAPP, misc=True)
     self.cat_initial['categories'] = [self.cat.id, new.id]
     r = self.client.post(self.edit_url,
                          formset(self.cat_initial, initial_count=1))
     eq_(r.context['cat_form'].errors[0]['categories'], [
         'The miscellaneous category cannot be combined with additional '
         'categories.'
     ])
예제 #30
0
    def test_edit_categories_xss(self):
        new = Category.objects.create(name='<script>alert("xss");</script>',
                                      type=amo.ADDON_WEBAPP)
        self.cat_initial['categories'] = [self.cat.id, new.id]
        r = self.client.post(self.edit_url,
                             formset(self.cat_initial, initial_count=1))

        assert '<script>alert' not in r.content
        assert '&lt;script&gt;alert' in r.content
예제 #31
0
    def test_edit_categories_xss(self):
        new = Category.objects.create(name='<script>alert("xss");</script>',
                                      type=amo.ADDON_WEBAPP)
        self.cat_initial['categories'] = [self.cat.id, new.id]
        r = self.client.post(self.edit_url, formset(self.cat_initial,
                                                          initial_count=1))

        assert '<script>alert' not in r.content
        assert '&lt;script&gt;alert' in r.content
예제 #32
0
 def test_success_add_owner(self):
     u = UserProfile.objects.get(id=999)
     u = dict(user=u.email, listed=True, role=amo.AUTHOR_ROLE_OWNER,
              position=0)
     r = self.client.post(self.url, formset(u, initial_count=0))
     self.assertRedirects(r, self.url, 302)
     owners = (AddonUser.objects.filter(addon=self.webapp.id)
               .values_list('user', flat=True))
     eq_(list(owners), [31337, 999])
예제 #33
0
 def test_required_app(self):
     d = dict(locale='zh-CN', collection=80)
     data = formset(self.initial, d, initial_count=1)
     r = self.client.post(self.url, data)
     eq_(r.status_code, 200)
     eq_(r.context['form'].errors[0]['application'],
         ['This field is required.'])
     eq_(r.context['form'].errors[0]['collection'],
         ['Invalid collection for this application.'])
예제 #34
0
 def test_required_app(self):
     d = dict(locale='zh-CN', collection=80)
     data = formset(self.initial, d, initial_count=1)
     r = self.client.post(self.url, data)
     eq_(r.status_code, 200)
     eq_(r.context['form'].errors[0]['application'],
         ['This field is required.'])
     eq_(r.context['form'].errors[0]['collection'],
         ['Invalid collection for this application.'])
예제 #35
0
    def test_toggles(self):
        # Turn everything on.
        data = dict(flash="checked")
        r = self.client.post(self.edit_url, formset(**data))
        self.assertNoFormErrors(r)
        self.compare({"uses_flash": True})

        # And off.
        r = self.client.post(self.edit_url)
        self.compare({"uses_flash": False})
예제 #36
0
    def setup_actions(self, action):
        ctx = self.client.get(self.url).context
        fs = initial(ctx['reviews_formset'].forms[0])

        eq_(len(Review.objects.filter(addon=1865)), 2)

        data_formset = formset(fs)
        data_formset['form-0-action'] = action

        r = self.client.post(reverse('editors.queue_moderated'), data_formset)
        eq_(r.status_code, 302)
예제 #37
0
 def setUp(self):
     super(TestEditTechnical, self).setUp()
     self.dependent_addon = Addon.objects.get(id=5579)
     AddonDependency.objects.create(addon=self.addon,
                                    dependent_addon=self.dependent_addon)
     self.technical_url = self.get_url('technical')
     self.technical_edit_url = self.get_url('technical', edit=True)
     ctx = self.client.get(self.technical_edit_url).context
     self.dep = initial(ctx['dependency_form'].initial_forms[0])
     self.dep_initial = formset(self.dep, prefix='dependencies',
                                initial_count=1)
예제 #38
0
    def test_edit_categories_xss(self):
        c = Category.objects.get(id=22)
        c.name = '<script>alert("test");</script>'
        c.save()

        self.cat_initial['categories'] = [22, 24]
        r = self.client.post(self.basic_edit_url, formset(self.cat_initial,
                                                          initial_count=1))

        assert '<script>alert' not in r.content
        assert '&lt;script&gt;alert' in r.content
예제 #39
0
    def test_public_stats(self):
        self.create_switch('app-stats')

        eq_(self.webapp.public_stats, False)
        assert not self.webapp.public_stats, (
            'Unexpectedly found public stats for app. Says Basta.')

        data = dict(public_stats=True)
        r = self.client.post(self.edit_url, formset(**data))
        self.assertNoFormErrors(r)

        self.compare(dict(public_stats=True))
예제 #40
0
    def test_public_stats(self):
        o = ActivityLog.objects
        eq_(o.count(), 0)

        eq_(self.webapp.public_stats, False)
        assert not self.webapp.public_stats, "Unexpectedly found public stats for app. Says Basta."

        r = self.client.post(self.edit_url, formset(public_stats=True))
        self.assertNoFormErrors(r)

        self.compare({"public_stats": True})
        eq_(o.filter(action=amo.LOG.EDIT_PROPERTIES.id).count(), 1)
예제 #41
0
 def get_dict(self, **kw):
     fs = formset(self.cat_initial, initial_count=1)
     result = {
         'device_types': self.dtype.id,
         'name': 'new name',
         'slug': 'test_slug',
         'summary': 'new summary',
         'manifest_url': self.get_webapp().manifest_url
     }
     result.update(**kw)
     result.update(fs)
     return result
예제 #42
0
    def test_devcomment_optional(self):
        data = dict(developer_comments='',
                    external_software='on',
                    site_specific='on',
                    view_source='on')
        r = self.client.post(self.edit_url, formset(**data))
        self.assertNoFormErrors(r)

        expected = dict(developer_comments='',
                        external_software=True,
                        site_specific=True,
                        view_source=True)
        self.compare(expected)
예제 #43
0
    def test_toggles(self):
        # Turn everything on.
        data = dict(developer_comments='Test comment!',
                    external_software='on',
                    site_specific='on',
                    view_source='on')

        r = self.client.post(self.edit_url, formset(**data))
        self.assertNoFormErrors(r)
        expected = dict(developer_comments='Test comment!',
                        external_software=True,
                        site_specific=True,
                        view_source=True)
        self.compare(expected)

        # And off.
        r = self.client.post(self.edit_url,
                             formset(developer_comments='Test comment!'))
        expected.update(external_software=False,
                        site_specific=False,
                        view_source=False)
        self.compare(expected)
예제 #44
0
    def test_toggles(self):
        # Turn everything on.
        data = dict(developer_comments='Test comment!',
                    external_software='on',
                    site_specific='on',
                    view_source='on')

        r = self.client.post(self.edit_url, formset(**data))
        self.assertNoFormErrors(r)
        expected = dict(developer_comments='Test comment!',
                        external_software=True,
                        site_specific=True,
                        view_source=True)
        self.compare(expected)

        # And off.
        r = self.client.post(self.edit_url,
                             formset(developer_comments='Test comment!'))
        expected.update(external_software=False,
                        site_specific=False,
                        view_source=False)
        self.compare(expected)
예제 #45
0
    def test_devcomment_optional(self):
        data = dict(developer_comments='',
                    external_software='on',
                    site_specific='on',
                    view_source='on')
        r = self.client.post(self.edit_url, formset(**data))
        self.assertNoFormErrors(r)

        expected = dict(developer_comments='',
                        external_software=True,
                        site_specific=True,
                        view_source=True)
        self.compare(expected)
예제 #46
0
 def _form_data(self, data={}, compat_forms=None):
     """Build the initial data set for the form."""
     initial_data = {'author_name': 'author',
                     'contributors': '',
                     'description': '',
                     'name': 'My Addon',
                     'package_name': 'my_addon',
                     'id': '*****@*****.**',
                     'version': '1.2.3'}
     if not compat_forms:
         compat_forms = [self.compat_form]
     initial_data.update(formset(*compat_forms))
     if data:
         initial_data.update(data)
     return initial_data
예제 #47
0
 def setUp(self):
     super(TestVersionEditDetails, self).setUp()
     ctx = self.client.get(self.url).context
     compat = initial(ctx['compat_form'].forms[0])
     files = initial(ctx['file_form'].forms[0])
     self.initial = formset(compat, **formset(files, prefix='files'))
예제 #48
0
 def formset(self, *args, **kw):
     defaults = {'approvalnotes': 'xxx'}
     defaults.update(kw)
     return formset(*args, **defaults)
예제 #49
0
    def preview_formset(self, *args, **kw):
        kw.setdefault('initial_count', 0)
        kw.setdefault('prefix', 'files')

        fs = formset(*[a for a in args] + [self.new_preview_formset()], **kw)
        return dict([(k, '' if v is None else v) for k, v in fs.items()])
예제 #50
0
 def test_edit_categories_required(self):
     del self.cat_initial['categories']
     r = self.client.post(self.basic_edit_url, formset(self.cat_initial,
                                                       initial_count=1))
     eq_(r.context['cat_form'].errors[0]['categories'],
         ['This field is required.'])
예제 #51
0
 def test_edit_categories_required(self):
     del self.cat_initial['categories']
     r = self.client.post(self.edit_url,
                          formset(self.cat_initial, initial_count=1))
     assert_required(r.context['cat_form'].errors[0]['categories'][0])
예제 #52
0
 def formset(self, *args, **kw):
     defaults = formset(prefix='files')
     defaults.update(kw)
     return super(TestVersionEditCompat, self).formset(*args, **defaults)
예제 #53
0
 def dep_formset(self, *args, **kw):
     kw.setdefault('initial_count', 1)
     kw.setdefault('prefix', 'dependencies')
     return formset(self.dep, *args, **kw)
예제 #54
0
 def formset(self, *args, **kw):
     return formset(*args, **kw)
예제 #55
0
 def formset(self, *args, **kw):
     compat = formset(self.compat, initial_count=1)
     compat.update(kw)
     return super(TestVersionEditFiles, self).formset(*args, **compat)