当前位置: 首页>>代码示例>>Python>>正文


Python Shortener.expand方法代码示例

本文整理汇总了Python中pyshorteners.shorteners.Shortener.expand方法的典型用法代码示例。如果您正苦于以下问题:Python Shortener.expand方法的具体用法?Python Shortener.expand怎么用?Python Shortener.expand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyshorteners.shorteners.Shortener的用法示例。


在下文中一共展示了Shortener.expand方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_google_bad_params

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
def test_google_bad_params():
    s = Shortener('GoogleShortener')

    with pytest.raises(TypeError):
        s.short(expanded)

    with pytest.raises(TypeError):
        s.expand(expanded)
开发者ID:Rudddi,项目名称:pyshorteners,代码行数:10,代码来源:test_googl.py

示例2: test_bitly_shortener

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
    def test_bitly_shortener(self):
        engine = 'BitlyShortener'
        short = Shortener(engine, bitly_api_key='abc', bitly_login='123x')
        url = 'http://www.google.com/'
        short_url = 'http://bit.ly/xxx'
        short.short = MagicMock(return_value='http://bit.ly/SsdA')
        short.short(url)
        short.short.assert_called_with(url)

        #expanding
        short.expand = MagicMock(return_value=url)
        short.expand(short_url)
        short.expand.assert_called_with(short_url)
开发者ID:praveenkishor123,项目名称:pyshorteners,代码行数:15,代码来源:test_shorteners.py

示例3: test_tinyurl_shortener

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
    def test_tinyurl_shortener(self):
        engine = 'TinyurlShortener'
        short = Shortener(engine)
        url = 'http://tinyurl.com/nc9m936'
        shorten = short.short(self.test_url)
        self.assertEqual(shorten, url)

        self.assertEqual(short.expand(), self.test_url)
        self.assertEqual(short.expand(url), self.test_url)

        self.assertEqual(short.expanded, self.test_url)
        self.assertEqual(short.shorten, url)
        self.assertEqual(short.qrcode(), 'http://chart.apis.google.com/'
                         'chart?cht=qr&chl={}&chs=120x120'.format(shorten))
开发者ID:praveenkishor123,项目名称:pyshorteners,代码行数:16,代码来源:test_shorteners.py

示例4: test_readability_shortener

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
    def test_readability_shortener(self):
        engine = 'ReadabilityShortener'
        short = Shortener(engine)
        url = 'http://blog.arc90.com/2010/11/30/silence-is-golden/'
        short_url = 'http://rdd.me/tg8if9uj'
        readbility_url = 'http://readability.com/articles/tg8if9uj'
        shorten = short.short(url)
        self.assertEqual(shorten, short_url)

        expand = short.expand(shorten)
        self.assertEqual(expand, readbility_url)

        # Test wrong url_id
        short = Shortener(engine)
        with self.assertRaises(ExpandingErrorException):
            expand = short.expand('http://www.wqe.cc')
开发者ID:RandomStuffs22,项目名称:pyshorteners,代码行数:18,代码来源:test_shorteners.py

示例5: test_googl_shortener

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
    def test_googl_shortener(self):
        engine = 'GoogleShortener'
        short = Shortener(engine)
        url = 'http://goo.gl/rjf0oI'
        shorten = short.short(self.test_url)
        self.assertEqual(shorten, url)

        self.assertEqual(short.expand(), self.test_url)
        self.assertEqual(short.expanded, self.test_url)

        self.assertEqual(short.shorten, url)
        self.assertEqual(short.qrcode(), 'http://chart.apis.google.com/'
                         'chart?cht=qr&chl={}&chs=120x120'.format(shorten))

        #test exceptions
        with self.assertRaises(ExpandingErrorException):
            short.expand('http://www.a.co')
开发者ID:praveenkishor123,项目名称:pyshorteners,代码行数:19,代码来源:test_shorteners.py

示例6: test_tinyurl_shortener

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
    def test_tinyurl_shortener(self):
        engine = 'TinyurlShortener'
        short = Shortener(engine)
        self.assertEqual(short.short('http://www.google.com'),
                         'http://tinyurl.com/1c2')

        self.assertEqual(short.expand('http://tinyurl.com/ycus76'),
                         'https://www.facebook.com')
开发者ID:relsi,项目名称:pyshorteners,代码行数:10,代码来源:test_shorteners.py

示例7: test_googl_shortener

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
    def test_googl_shortener(self):
        engine = 'GoogleShortener'
        short = Shortener(engine)
        self.assertEqual(short.short('http://www.google.com'),
                         'http://goo.gl/fbsS')

        self.assertEqual(short.expand('http://goo.gl/fbsS'),
                         'http://www.google.com/')
开发者ID:relsi,项目名称:pyshorteners,代码行数:10,代码来源:test_shorteners.py

示例8: test_sentala_shortener

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
    def test_sentala_shortener(self):
        engine = 'SentalaShortener'
        short = Shortener(engine)
        url = 'http://www.pilgrims.com'

        shorten = short.short(url)
        expand = short.expand(shorten)
        self.assertEqual(expand, url)
        self.assertEqual(short.qrcode(), 'http://chart.apis.google.com/'
                         'chart?cht=qr&chl={}&chs=120x120'.format(shorten))
开发者ID:praveenkishor123,项目名称:pyshorteners,代码行数:12,代码来源:test_shorteners.py

示例9: test_generic_expander

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
    def test_generic_expander(self):
        # testing new generic expander. Uses another shortener to test
        short = Shortener("TinyurlShortener")
        shorten = short.short(self.test_url)

        engine = "GenericExpander"
        expander = Shortener(engine)
        result_url = expander.expand(shorten)
        # A valid url result is enough for answer
        self.assertEqual(result_url, self.test_url)
开发者ID:MaximilianoRios,项目名称:pyshorteners,代码行数:12,代码来源:test_shorteners.py

示例10: test_qrcx_shortener

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
    def test_qrcx_shortener(self):
        engine = 'QrCxShortener'
        short = Shortener(engine)
        url = 'https://www.facebook.com/'

        shorten = short.short(url)
        expand = short.expand(shorten)
        self.assertEqual(expand, url)
        self.assertEqual(short.qrcode(), 'http://chart.apis.google.com/'
                         'chart?cht=qr&chl={}&chs=120x120'.format(shorten))
开发者ID:RandomStuffs22,项目名称:pyshorteners,代码行数:12,代码来源:test_shorteners.py

示例11: test_adfly_shortener

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
    def test_adfly_shortener(self):
        engine = 'AdflyShortener'
        short = Shortener(engine, key='abcd', uid='123')
        url = 'http://www.google.com/'

        short.short = MagicMock(return_value='http://adf.ly/test')
        short.short(url)
        short.short.assert_called_with(url)

        expand = short.expand('http://adf.ly/test')
        self.assertEqual(expand, 'http://adf.ly/test')
开发者ID:praveenkishor123,项目名称:pyshorteners,代码行数:13,代码来源:test_shorteners.py

示例12: test_dottk_shortener

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
    def test_dottk_shortener(self):
        engine = 'DottkShortener'
        short = Shortener(engine)
        url = 'http://www.google.com/'

        short.short = MagicMock(return_value='http://3vzpu.tk')
        short.short(url)
        short.short.assert_called_with(url)

        expand = short.expand('http://adf.ly/test')
        self.assertEqual(expand, 'http://adf.ly/test')
开发者ID:relsi,项目名称:pyshorteners,代码行数:13,代码来源:test_shorteners.py

示例13: test_bitly_shortener

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
    def test_bitly_shortener(self):
        engine = 'BitlyShortener'
        short = Shortener(engine, bitly_api_key='abc', bitly_login='123x')
        url = 'http://www.google.com/'
        short_url = 'http://bit.ly/xxx'

        # test with no mock
        with self.assertRaises(ShorteningErrorException):
            short = short.short(url)

        # mocking the results
        short.expand = MagicMock(return_value=url)
        short.short = MagicMock(return_value='http://bit.ly/SsdA')

        short.short(url)
        short.short.assert_called_with(url)
        short.expand(short_url)
        short.expand.assert_called_with(short_url)

        # test with no key params
        with self.assertRaises(TypeError):
            short = Shortener(engine).short('http://www.google.com')
开发者ID:RandomStuffs22,项目名称:pyshorteners,代码行数:24,代码来源:test_shorteners.py

示例14: test_generic_expander

# 需要导入模块: from pyshorteners.shorteners import Shortener [as 别名]
# 或者: from pyshorteners.shorteners.Shortener import expand [as 别名]
    def test_generic_expander(self):
        # testing new generic expander. Uses another shortener to test
        short = Shortener("TinyurlShortener")
        shorten = short.short(self.test_url)

        engine = "GenericExpander"
        expander = Shortener(engine)

        with self.assertRaises(NotImplementedError):
            expander.short('http://www.test.com')

        result_url = expander.expand(shorten)
        # A valid url result is enough for answer
        self.assertEqual(result_url, self.test_url)
开发者ID:RandomStuffs22,项目名称:pyshorteners,代码行数:16,代码来源:test_shorteners.py


注:本文中的pyshorteners.shorteners.Shortener.expand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。