Esempio n. 1
0
    def test_form_choices_legacy(self):
        version = Addon.objects.get(id=3615).current_version
        version.file.update(is_webextension=False)

        firefox_57 = AppVersion.objects.get(application=amo.FIREFOX.id,
                                            version='57.0')
        firefox_57_s = AppVersion.objects.get(application=amo.FIREFOX.id,
                                              version='57.*')

        expected_min_choices = [('', '---------')] + list(
            AppVersion.objects.filter(application=amo.FIREFOX.id).exclude(
                version__contains='*').exclude(
                    pk__in=(firefox_57.pk, firefox_57_s.pk)).values_list(
                        'pk', 'version').order_by('version_int'))
        expected_max_choices = [('', '---------')] + list(
            AppVersion.objects.filter(application=amo.FIREFOX.id).exclude(
                pk__in=(firefox_57.pk, firefox_57_s.pk)).values_list(
                    'pk', 'version').order_by('version_int'))

        formset = forms.CompatFormSet(None,
                                      queryset=version.apps.all(),
                                      form_kwargs={'version': version})
        form = formset.forms[0]
        assert form.app == amo.FIREFOX
        assert list(form.fields['min'].choices) == expected_min_choices
        assert list(form.fields['max'].choices) == expected_max_choices

        expected_an_choices = [('', '---------')] + list(
            AppVersion.objects.filter(application=amo.ANDROID.id).values_list(
                'pk', 'version').order_by('version_int'))
        form = formset.forms[1]
        assert form.app == amo.ANDROID
        assert list(form.fields['min'].choices) == expected_an_choices
        assert list(form.fields['max'].choices) == expected_an_choices
Esempio n. 2
0
 def test_forms(self):
     version = Addon.objects.get(id=3615).current_version
     formset = forms.CompatFormSet(None,
                                   queryset=version.apps.all(),
                                   form_kwargs={'version': version})
     apps = [form.app for form in formset.forms]
     assert set(apps) == set(amo.APP_USAGE)
Esempio n. 3
0
    def test_form_choices_no_compat(self):
        AppVersion.objects.create(application=amo.THUNDERBIRD.id,
                                  version='50.0')
        AppVersion.objects.create(application=amo.FIREFOX.id, version='56.0')
        AppVersion.objects.create(application=amo.FIREFOX.id, version='56.*')
        AppVersion.objects.create(application=amo.FIREFOX.id, version='57.0')
        AppVersion.objects.create(application=amo.FIREFOX.id, version='57.*')

        expected_min_choices = [(u'', u'---------')]
        expected_min_choices.extend(
            list(
                AppVersion.objects.filter(application=amo.FIREFOX.id).exclude(
                    version__contains='*').values_list(
                        'pk', 'version').order_by('version_int')))
        expected_max_choices = [(u'', u'---------')]
        expected_max_choices.extend(
            list(
                AppVersion.objects.filter(
                    application=amo.FIREFOX.id).values_list(
                        'pk', 'version').order_by('version_int')))

        version = Addon.objects.get(id=3615).current_version
        version.files.all().update(is_webextension=False)
        version.addon.update(type=amo.ADDON_DICT)
        del version.all_files
        formset = forms.CompatFormSet(None,
                                      queryset=version.apps.all(),
                                      form_kwargs={'version': version})
        form = formset.forms[0]
        assert form.app == amo.FIREFOX
        assert list(form.fields['min'].choices) == expected_min_choices
        assert list(form.fields['max'].choices) == expected_max_choices
    def test_forms_disallow_thunderbird_and_seamonkey_even_if_present(self):
        self.create_switch('disallow-thunderbird-and-seamonkey')
        version = Addon.objects.get(id=3615).current_version
        current_min = version.apps.filter(application=amo.FIREFOX.id).get().min
        current_max = version.apps.filter(application=amo.FIREFOX.id).get().max
        version.files.all().update(is_webextension=False)
        ApplicationsVersions.objects.create(
            version=version,
            application=amo.THUNDERBIRD.id,
            min=AppVersion.objects.get(application=amo.THUNDERBIRD.id,
                                       version='50.0'),
            max=AppVersion.objects.get(application=amo.THUNDERBIRD.id,
                                       version='58.0'))
        del version.all_files
        formset = forms.CompatFormSet(None,
                                      queryset=version.apps.all(),
                                      form_kwargs={'version': version})
        apps = [form.app for form in formset.forms]
        assert set(apps) == set(amo.APP_USAGE_FIREFOXES_ONLY)

        form = formset.forms[0]
        assert form.app == amo.FIREFOX
        assert form.initial['application'] == amo.FIREFOX.id
        assert form.initial['min'] == current_min.pk
        assert form.initial['max'] == current_max.pk

        # Android compatibility was not set: it's present as an extra with no
        # initial value set other than "application".
        form = formset.forms[1]
        assert form.app == amo.ANDROID
        assert form.initial['application'] == amo.ANDROID.id
        assert 'min' not in form.initial
        assert 'max' not in form.initial
Esempio n. 5
0
 def test_forms_disallow_thunderbird_and_seamonkey(self):
     self.create_switch('disallow-thunderbird-and-seamonkey')
     version = Addon.objects.get(id=3615).current_version
     formset = forms.CompatFormSet(None,
                                   queryset=version.apps.all(),
                                   form_kwargs={'version': version})
     apps = [form.app for form in formset.forms]
     assert set(apps) == set(amo.APP_USAGE_FIREFOXES_ONLY)
Esempio n. 6
0
 def test_mozilla_app(self):
     moz = amo.MOZILLA
     appver = AppVersion.objects.create(application=moz.id)
     v = Addon.objects.get(id=3615).current_version
     ApplicationsVersions(application=moz.id, version=v,
                          min=appver, max=appver).save()
     fs = forms.CompatFormSet(None, queryset=v.apps.all())
     apps = [f.app for f in fs.forms]
     assert moz in apps
Esempio n. 7
0
    def test_static_theme(self):
        version = Addon.objects.get(id=3615).current_version
        version.addon.update(type=amo.ADDON_STATICTHEME)
        self._test_form_choices_expect_all_versions(version)

        formset = forms.CompatFormSet(None,
                                      queryset=version.apps.all(),
                                      form_kwargs={'version': version})
        assert formset.can_delete is False  # No deleting Firefox app plz.
        assert formset.extra == 0  # And lets not extra apps be added.
Esempio n. 8
0
 def test_form_initial(self):
     version = Addon.objects.get(id=3615).current_version
     current_min = version.apps.filter(application=amo.FIREFOX.id).get().min
     current_max = version.apps.filter(application=amo.FIREFOX.id).get().max
     formset = forms.CompatFormSet(None, queryset=version.apps.all(),
                                   form_kwargs={'version': version})
     form = formset.forms[0]
     assert form.app == amo.FIREFOX
     assert form.initial['application'] == amo.FIREFOX.id
     assert form.initial['min'] == current_min.pk
     assert form.initial['max'] == current_max.pk
Esempio n. 9
0
    def _test_form_choices_expect_all_versions(self, version):
        expected_min_choices = [('', '---------')] + list(
            AppVersion.objects.filter(application=amo.FIREFOX.id).exclude(
                version__contains='*').values_list(
                    'pk', 'version').order_by('version_int'))
        expected_max_choices = [('', '---------')] + list(
            AppVersion.objects.filter(application=amo.FIREFOX.id).values_list(
                'pk', 'version').order_by('version_int'))

        formset = forms.CompatFormSet(None,
                                      queryset=version.apps.all(),
                                      form_kwargs={'version': version})
        form = formset.forms[0]
        assert form.app == amo.FIREFOX
        assert list(form.fields['min'].choices) == expected_min_choices
        assert list(form.fields['max'].choices) == expected_max_choices
Esempio n. 10
0
    def test_form_choices_legacy(self):
        thunderbird_version = AppVersion.objects.create(
            application=amo.THUNDERBIRD.id, version='58.0')
        AppVersion.objects.create(application=amo.FIREFOX.id, version='56.0')
        AppVersion.objects.create(application=amo.FIREFOX.id, version='56.*')
        firefox_57 = AppVersion.objects.create(application=amo.FIREFOX.id,
                                               version='57.0')
        firefox_57_s = AppVersion.objects.create(application=amo.FIREFOX.id,
                                                 version='57.*')

        expected_min_choices = [(u'', u'---------')]
        expected_min_choices.extend(
            list(
                AppVersion.objects.filter(application=amo.FIREFOX.id).exclude(
                    version__contains='*').exclude(
                        pk__in=(firefox_57.pk, firefox_57_s.pk)).values_list(
                            'pk', 'version').order_by('version_int')))
        expected_max_choices = [(u'', u'---------')]
        expected_max_choices.extend(
            list(
                AppVersion.objects.filter(application=amo.FIREFOX.id).exclude(
                    pk__in=(firefox_57.pk, firefox_57_s.pk)).values_list(
                        'pk', 'version').order_by('version_int')))

        version = Addon.objects.get(id=3615).current_version
        version.files.all().update(is_webextension=False)
        del version.all_files
        formset = forms.CompatFormSet(None,
                                      queryset=version.apps.all(),
                                      form_kwargs={'version': version})
        form = formset.forms[0]
        assert form.app == amo.FIREFOX
        assert list(form.fields['min'].choices) == expected_min_choices
        assert list(form.fields['max'].choices) == expected_max_choices

        expected_tb_choices = [
            (u'', u'---------'),
            (thunderbird_version.pk, thunderbird_version.version),
        ]
        thunderbird_version
        form = formset.forms[1]
        assert form.app == amo.THUNDERBIRD
        assert list(form.fields['min'].choices) == expected_tb_choices
        assert list(form.fields['max'].choices) == expected_tb_choices