예제 #1
0
    def test_shorten_url_with_stats(self):
        service = Vgd()
        generated_short_url = service.shorten_url(self.test_long_url, logstats=True)

        # When logstats is enabled, a new url will be generated for the long url
        # so we cannot assertEqual(). Hence, we just check if we got a short url.
        if not generated_short_url.startswith('http://v.gd/'):
            raise AssertionError('Failed to generate short url with logstats enabled.')
예제 #2
0
    def test_shorten_url_with_stats(self):
        service = Vgd()
        generated_short_url = service.shorten_url(self.test_long_url,
                                                  logstats=True)

        # When logstats is enabled, a new url will be generated for the long url
        # so we cannot assertEqual(). Hence, we just check if we got a short url.
        if not generated_short_url.startswith('http://v.gd/'):
            raise AssertionError(
                'Failed to generate short url with logstats enabled.')
예제 #3
0
    # Now, instantiate the service object based upon user preference.
    service = None
    if 'goo.gl' == options.service:
        service = Googl(options.svc_api_key)
    elif 'bit.ly' == options.service:
        # bit.ly requires a login account and api key.
        if not options.login or not options.svc_api_key:
            print 'bit.ly requires a valid account and API key.'
            sys.exit(-1)
        service = Bitly(options.login, options.svc_api_key)
    if 'git.io' == options.service:
        service = Gitio()
    elif 'tinyurl.com' == options.service:
        service = TinyUrlcom()
    elif 'v.gd' == options.service:
        service = Vgd()
    elif 'is.gd' == options.service:
        service = Isgd()

    # Get QR code.
    if options.qr_img_path:
        if not options.short_url:
            print 'You need to specify a short url to get qr code.'
            print 'Usage: python %s -s <short_url> -q <image_path>' % (
                sys.argv[0])
            sys.exit(-1)

        try:
            service.write_qr_image(options.short_url, options.qr_img_path)
        except ShortenerServiceError, e:
            print e
예제 #4
0
    def test_expand_url(self):
        service = Vgd()
        generated_long_url = service.expand_url(self.test_short_url)

        self.assertEqual(self.test_long_url, generated_long_url)
예제 #5
0
    def test_expand_url(self):
        service = Vgd()
        generated_long_url = service.expand_url(self.test_short_url)

        self.assertEqual(self.test_long_url, generated_long_url)