def test_get_url_shortener(self): us_settings.URL_SHORTENER_BACKEND = 'mymodule.myclass' try: with warnings.catch_warnings(record=True) as w: self.assertEquals(get_url_shortener(), default_backend) self.assertTrue(issubclass(w[-1].Objecttype, RuntimeWarning)) self.assertEquals( str(w[-1].message), 'mymodule.myclass backend cannot be imported') except AttributeError: # Fail under Python2.5, because of'warnings.catch_warnings' pass us_settings.URL_SHORTENER_BACKEND = 'objectapp.tests.custom_url_shortener' try: with warnings.catch_warnings(record=True) as w: self.assertEquals(get_url_shortener(), default_backend) self.assertTrue(issubclass(w[-1].Objecttype, RuntimeWarning)) self.assertEquals( str(w[-1].message), 'This backend only exists for testing') except AttributeError: # Fail under Python2.5, because of'warnings.catch_warnings' pass us_settings.URL_SHORTENER_BACKEND = 'objectapp.url_shortener'\ '.backends.default' self.assertEquals(get_url_shortener(), default_backend)
def test_get_url_shortener(self): us_settings.URL_SHORTENER_BACKEND = 'mymodule.myclass' try: with warnings.catch_warnings(record=True) as w: self.assertEquals(get_url_shortener(), default_backend) self.assertTrue(issubclass(w[-1].Objecttype, RuntimeWarning)) self.assertEquals( str(w[-1].message), 'mymodule.myclass backend cannot be imported') except AttributeError: # Fail under Python2.5, because of'warnings.catch_warnings' pass us_settings.URL_SHORTENER_BACKEND = 'objectapp.tests.custom_url_shortener' try: with warnings.catch_warnings(record=True) as w: self.assertEquals(get_url_shortener(), default_backend) self.assertTrue(issubclass(w[-1].Objecttype, RuntimeWarning)) self.assertEquals(str(w[-1].message), 'This backend only exists for testing') except AttributeError: # Fail under Python2.5, because of'warnings.catch_warnings' pass us_settings.URL_SHORTENER_BACKEND = 'objectapp.url_shortener'\ '.backends.default' self.assertEquals(get_url_shortener(), default_backend)
def short_url(self): """Return the gbobject's short url""" return get_url_shortener()(self)