예제 #1
0
 def test_uri_with_several_subdomains(self):
     url = 'http://my.very.long.hostname.co.uk'
     u = Uri(url)
     self.assertEqual('http', u.scheme)
     self.assertEqual('my.very.long.hostname.co.uk', u.hostname)
     self.assertEqual('uk', u.getTLD())
예제 #2
0
    def test_custom_uri_object(self):
        u = Uri()
        u.scheme = 'asdf'
        self.assertEqual('', u.scheme)
        u.scheme = 'http'
        self.assertEqual('http', u.scheme)

        u.hostname = 'random'
        self.assertEqual('', u.hostname)
        u.hostname = 'random.site.com:80'
        self.assertEqual('random.site.com:80', u.hostname)

        u.path = 'mybadpath'
        self.assertEqual('', u.path)
        u.path = '/my/good/path'
        self.assertEqual('/my/good/path', u.path)

        u.urlFragment = 'anythingiwant'
        self.assertEqual('anythingiwant', u.urlFragment)

        u.addOrUpdateParam('k', 'v')
        self.assertIn('k', u.params.keys())
        myParams = {'p1': 'val1', 'paramTwo': 'Value2'}
        u.addOrUpdateParams(myParams)
        self.assertIn('p1', u.params.keys())
        self.assertIn('paramTwo', u.params.keys())
        self.assertEqual(u.params['p1'], 'val1')
        self.assertEqual(u.params['paramTwo'], 'Value2')
        u.params = myParams
        self.assertNotIn('k', u.params.keys())