Exemple #1
0
 def test_is_shortened(self):
     # Test URLs that have been shortened.
     self.assertTrue(Short.already('http://tinyurl.com/foo'))
     self.assertTrue(Short.already('http://is.gd/foo'))
     self.assertTrue(Short.already('http://linkee.com/foo'))
     self.assertTrue(Short.already('http://ou.gd/foo'))
     self.assertTrue(Short.already('http://durl.me/foo'))
Exemple #2
0
 def test_missing_or_disabled_lookup(self):
     # Looking up a non-existent or disabled shortener gives you one that
     # returns the original url back unchanged.
     self.assertEqual(
         Short('nonexistant').make('http://www.python.org'),
         'http://www.python.org')
     self.assertEqual(Short().make('http://www.python.org'),
                      'http://www.python.org')
Exemple #3
0
 def test_find_all_in_string(self):
     shorter = Short()
     shorter.make = lambda url: 'zombo.com'
     self.assertEqual(
         'Welcome to zombo.com, anything is possible. '
         'You can do anything at zombo.com!',
         shorter.sub(
             'Welcome to http://example.com/really/really/long/url, '
             'anything is possible. You can do anything at '
             'http://example.com!'))
Exemple #4
0
 def test_durlme_quoted_properly(self, dl_mock):
     dl_mock().get_string().strip.return_value = ''
     dl_mock.reset_mock()
     Short('durl.me').make('http://example.com/~user/stuff/+things')
     dl_mock.assert_called_once_with(
         'http://durl.me/api/Create.do?type=json&longurl='
         'http%3A%2F%2Fexample.com%2F%7Euser%2Fstuff%2F%2Bthings')
Exemple #5
0
    def URLShorten(self, message):
        """Shorten all the URLs in a message.

        Takes a message as a string, and returns the message with all
        it's URLs shortened.

        example:
            import dbus
            url = 'http://www.example.com/this/is/a/long/url'
            obj = dbus.SessionBus().get_object(DBUS_INTERFACE,
                '/com/canonical/friends/Dispatcher')
            service = dbus.Interface(obj, DBUS_INTERFACE)
            short_url = service.URLShorten(url)
        """
        service_name = self.settings.get_string('urlshorter')
        log.info('Shortening with {}'.format(service_name))
        if not self.settings.get_boolean('shorten-urls'):
            return message
        return Short(service_name).sub(message)
Exemple #6
0
 def test_linkeecom_quoted_properly(self, dl_mock):
     Short('linkee.com').make('http://example.com/~user/stuff/+things')
     dl_mock.assert_called_once_with(
         'http://api.linkee.com/1.0/shorten?format=text&input='
         'http%3A%2F%2Fexample.com%2F%7Euser%2Fstuff%2F%2Bthings')
Exemple #7
0
 def test_ougd_quoted_properly(self, dl_mock):
     Short('ou.gd').make('http://example.com/~user/stuff/+things')
     dl_mock.assert_called_once_with(
         'http://ou.gd/api.php?format=simple&action=shorturl&url='
         'http%3A%2F%2Fexample.com%2F%7Euser%2Fstuff%2F%2Bthings')
Exemple #8
0
 def test_isgd_quoted_properly(self, dl_mock):
     Short('is.gd').make('http://example.com/~user/stuff/+things')
     dl_mock.assert_called_once_with(
         'http://is.gd/api.php?longurl=http%3A%2F%2Fexample.com'
         '%2F%7Euser%2Fstuff%2F%2Bthings')
Exemple #9
0
 def test_is_not_shortened(self):
     # Test a URL that has not been shortened.
     self.assertFalse(Short.already('http://www.python.org/bar'))
Exemple #10
0
 def test_durlme(self):
     self.assertEqual(
         Short('durl.me').make('http://www.python.org'),
         'http://durl.me/5o')
Exemple #11
0
 def test_tinyurlcom(self):
     self.assertEqual(
         Short('tinyurl.com').make('http://www.python.org'),
         'http://sho.rt/')
Exemple #12
0
 def test_linkeecom(self):
     self.assertEqual(
         Short('linkee.com').make('http://www.python.org'),
         'http://sho.rt/')
Exemple #13
0
 def test_ougd(self):
     self.assertEqual(
         Short('ou.gd').make('http://www.python.org'), 'http://sho.rt/')
Exemple #14
0
 def test_dont_over_shorten(self, dl_mock):
     Short('tinyurl.com').make('http://tinyurl.com/page_id')
     Short('linkee.com').make('http://ou.gd/page_id')
     Short('is.gd').make('http://is.gd/page_id')
     Short('ou.gd').make('http://linkee.com/page_id')
     self.assertEqual(dl_mock.call_count, 0)
Exemple #15
0
 def test_tinyurl_quoted_properly(self, dl_mock):
     Short('tinyurl.com').make('http://example.com/~user/stuff/+things')
     dl_mock.assert_called_once_with(
         'http://tinyurl.com/api-create.php?url=http%3A%2F%2Fexample.com'
         '%2F%7Euser%2Fstuff%2F%2Bthings')