def test_incorrect_user(self): self.file.user = user_factory() self.file.save() form = forms.NewWebappForm({'upload': self.file.uuid}, request=self.request) assert not form.is_valid() eq_(form.ERRORS['user'], form.errors['upload'])
def test_free(self): form = forms.NewWebappForm({ 'free_platforms': ['free-firefoxos'], 'upload': self.file.uuid }) assert form.is_valid() eq_(form.get_paid(), amo.ADDON_FREE)
def test_multiple(self): form = forms.NewWebappForm({ 'free_platforms': ['free-firefoxos', 'free-desktop'], 'upload': self.file.uuid }) assert form.is_valid()
def test_not_packaged(self): form = forms.NewWebappForm({ 'free_platforms': ['free-firefoxos'], 'upload': self.file.uuid }) assert form.is_valid(), form.errors assert not form.is_packaged()
def test_incorrect_user(self): self.file.user = UserProfile.objects.create(pk=2, username='******') self.file.save() form = forms.NewWebappForm({'upload': self.file.uuid}, request=self.request) assert not form.is_valid() eq_(form.ERRORS['user'], form.errors['free_platforms']) eq_(form.ERRORS['user'], form.errors['paid_platforms'])
def test_packaged_allowed_desktop(self): form = forms.NewWebappForm({ 'free_platforms': ['free-desktop'], 'upload': self.file.uuid, 'packaged': True }) assert form.is_valid(), form.errors assert form.is_packaged()
def test_free(self): self.create_flag('allow-b2g-paid-submission') form = forms.NewWebappForm({ 'free_platforms': ['free-firefoxos'], 'upload': self.file.uuid }) assert form.is_valid() eq_(form.get_paid(), amo.ADDON_FREE)
def test_packaged_wrong_device(self): form = forms.NewWebappForm({ 'free_platforms': ['free-desktop'], 'upload': self.file.uuid, 'packaged': True }) assert not form.is_valid(), form.errors eq_(form.ERRORS['packaged'], form.errors['paid_platforms'])
def test_correct_user(self): form = forms.NewWebappForm( { 'free_platforms': ['free-firefoxos'], 'upload': self.file.uuid }, request=self.request) assert form.is_valid(), form.errors
def test_packaged_allowed_android(self, parse_addon): form = forms.NewWebappForm({ 'free_platforms': ['free-android-mobile'], 'upload': self.file.uuid, 'packaged': True }) assert form.is_valid(), form.errors assert form.is_packaged()
def test_paid(self): self.create_switch('allow-b2g-paid-submission') form = forms.NewWebappForm({ 'paid_platforms': ['paid-firefoxos'], 'upload': self.file.uuid }) assert form.is_valid() eq_(form.get_paid(), amo.ADDON_PREMIUM)
def test_homescreen_device(self): form = forms.NewWebappForm( { 'upload': self.file.uuid, 'free_platforms': ['free-firefoxos'], 'packaged': True }, request=self.request) assert form.is_valid()
def test_packaged_allowed(self, parse_addon): parse_addon.return_value = {} form = forms.NewWebappForm({ 'free_platforms': ['free-firefoxos'], 'upload': self.file.uuid, 'packaged': True }) assert form.is_valid(), form.errors assert form.is_packaged()
def test_both(self): self.create_switch('allow-b2g-paid-submission') form = forms.NewWebappForm({ 'paid_platforms': ['paid-firefoxos'], 'free_platforms': ['free-firefoxos'] }) assert not form.is_valid() eq_(form.ERRORS['both'], form.errors['free_platforms']) eq_(form.ERRORS['both'], form.errors['paid_platforms'])
def test_paid(self): form = forms.NewWebappForm( { 'paid_platforms': ['paid-firefoxos'], 'upload': self.file.uuid }, request=self.request) assert form.is_valid() eq_(form.get_paid(), amo.ADDON_PREMIUM)
def test_packaged_disallowed_behind_flag(self): for device in ('free-desktop', 'free-android-mobile', 'free-android-tablet'): form = forms.NewWebappForm({ 'free_platforms': [device], 'upload': self.file.uuid, 'packaged': True }) assert not form.is_valid(), form.errors eq_(form.ERRORS['packaged'], form.errors['paid_platforms'])
def test_both(self): form = forms.NewWebappForm( { 'paid_platforms': ['paid-firefoxos'], 'free_platforms': ['free-firefoxos'] }, request=self.request) assert not form.is_valid() eq_(form.ERRORS['both'], form.errors['free_platforms']) eq_(form.ERRORS['both'], form.errors['paid_platforms'])
def test_no_user(self): self.file.user = None self.file.save() form = forms.NewWebappForm( { 'free_platforms': ['free-firefoxos'], 'upload': self.file.uuid }, request=self.request) assert not form.is_valid() eq_(form.ERRORS['user'], form.errors['upload'])
def test_homescreen_wrong_device(self): form = forms.NewWebappForm( { 'upload': self.file.uuid, 'free_platforms': ['free-firefoxos', 'free-desktop'], 'packaged': True }, request=self.request) assert not form.is_valid() eq_(form.ERRORS['homescreen'], form.errors['free_platforms']) eq_(form.ERRORS['homescreen'], form.errors['paid_platforms'])
def test_packaged_allowed_everywhere(self): for device in ('free-firefoxos', 'free-desktop', 'free-android-tablet', 'free-android-mobile'): form = forms.NewWebappForm( { 'free_platforms': [device], 'upload': self.file.uuid, 'packaged': True }, request=self.request) assert form.is_valid(), form.errors assert form.is_packaged()
def test_platform(self): mappings = ( ({ 'free_platforms': ['free-firefoxos'] }, [amo.DEVICE_GAIA]), ({ 'paid_platforms': ['paid-firefoxos'] }, [amo.DEVICE_GAIA]), ({ 'free_platforms': ['free-firefoxos', 'free-android-mobile'] }, [amo.DEVICE_GAIA, amo.DEVICE_MOBILE]), ({ 'free_platforms': ['free-android-mobile', 'free-android-tablet'] }, [amo.DEVICE_MOBILE, amo.DEVICE_TABLET]), ) for data, res in mappings: data['upload'] = self.file.uuid form = forms.NewWebappForm(data) assert form.is_valid(), form.errors self.assertSetEqual(res, form.get_devices())
def test_not_paid(self): form = forms.NewWebappForm({'paid_platforms': ['paid-firefoxos']}) assert not form.is_valid() eq_(form.ERRORS['none'], form.errors['free_platforms']) eq_(form.ERRORS['none'], form.errors['paid_platforms'])