def verify_app_domain(manifest_url): if waffle.switch_is_active('webapps-unique-by-domain'): domain = Webapp.domain_from_url(manifest_url) if Addon.objects.filter(app_domain=domain).exists(): raise forms.ValidationError( _('An app already exists on this domain, ' 'only one app per domain is allowed.'))
def verify_app_domain(manifest_url, exclude=None, packaged=False): if packaged or waffle.switch_is_active('webapps-unique-by-domain'): domain = Webapp.domain_from_url(manifest_url) qs = Webapp.objects.filter(app_domain=domain) if exclude: qs = qs.exclude(pk=exclude.pk) if qs.exists(): raise forms.ValidationError( _('An app already exists on this domain; ' 'only one app per domain is allowed.'))
def verify_app_domain(manifest_url, exclude=None): if waffle.switch_is_active('webapps-unique-by-domain'): domain = Webapp.domain_from_url(manifest_url) qs = Webapp.objects.filter(app_domain=domain) if exclude: qs = qs.exclude(pk=exclude.pk) if qs.exists(): raise forms.ValidationError( _('An app already exists on this domain; ' 'only one app per domain is allowed.'))
def test_normalize_case(self): eq_(Webapp.domain_from_url('httP://mOzIllA.com/'), 'http://mozilla.com')
def test_none(self): Webapp.domain_from_url(None)
def test_normalize_www(self): eq_(Webapp.domain_from_url("http://www.mozilla.com/super/rad.webapp"), "mozilla.com")
def test_https(self): eq_(Webapp.domain_from_url('https://mozilla.com/'), 'https://mozilla.com')
def test_empty_or_none(self): eq_(Webapp.domain_from_url(None, allow_none=True), None)
def test_with_port(self): eq_(Webapp.domain_from_url('http://mozilla.com:9000/'), 'http://mozilla.com:9000')
def test_long_path(self): eq_(Webapp.domain_from_url("http://mozilla.com/super/rad.webapp"), "http://mozilla.com")
def test_long_path(self): eq_(Webapp.domain_from_url('http://mozilla.com/super/rad.webapp'), 'http://mozilla.com')
def test_https(self): eq_(Webapp.domain_from_url("https://mozilla.com/"), "https://mozilla.com")
def test_subdomains(self): eq_(Webapp.domain_from_url("http://apps.mozilla.com/"), "http://apps.mozilla.com")
def test_with_port(self): eq_(Webapp.domain_from_url("http://mozilla.com:9000/"), "http://mozilla.com:9000")
def test_empty(self): Webapp.domain_from_url('')
def test_simple(self): eq_(Webapp.domain_from_url('http://mozilla.com/'), 'http://mozilla.com')
def test_simple(self): eq_(Webapp.domain_from_url("http://mozilla.com/"), "http://mozilla.com")
def test_no_normalize_www(self): eq_(Webapp.domain_from_url('http://www.mozilla.com/super/rad.webapp'), 'http://www.mozilla.com')
def test_subdomains(self): eq_(Webapp.domain_from_url('http://apps.mozilla.com/'), 'http://apps.mozilla.com')
def run(): for app in Webapp.objects.all(): if app.manifest_url: app.update(app_domain=Webapp.domain_from_url(app.manifest_url))