Ticket #2093: test_paths.3.diff

File test_paths.3.diff, 3.4 KB (added by oubiwann, 10 years ago)

a little more coverage on the netloc parsing tests

  • twisted/test/test_paths.py

    old new  
    425425        self.assertEquals(str(self.path.here()), 'http://example.com/foo/')
    426426        self.assertEquals(str(self.path.child('').here()), 'http://example.com/foo/bar/')
    427427
     428class URLPathAuthTestCase(unittest.TestCase):
     429    def setUp(self):
     430        self.path = urlpath.URLPath.fromString("http://alice:asecret@example.com/foo/bar?yes=no&no=yes#footer")
     431
     432    def testStringConversion(self):
     433        self.assertEquals(str(self.path), "http://alice:asecret@example.com/foo/bar?yes=no&no=yes#footer")
     434       
     435    def testChildString(self):
     436        self.assertEquals(str(self.path.child('hello')), "http://alice:asecret@example.com/foo/bar/hello")
     437        self.assertEquals(str(self.path.child('hello').child('')), "http://alice:asecret@example.com/foo/bar/hello/")
     438       
     439    def testSiblingString(self):
     440        self.assertEquals(str(self.path.sibling('baz')), 'http://alice:asecret@example.com/foo/baz')
     441
     442        # The sibling of http://example.com/foo/bar/
     443        #     is http://example.comf/foo/bar/baz
     444        # because really we are constructing a sibling of
     445        # http://example.com/foo/bar/index.html
     446        self.assertEquals(str(self.path.child('').sibling('baz')), 'http://alice:asecret@example.com/foo/bar/baz')
     447       
     448    def testParentString(self):
     449        # parent should be equivalent to '..'
     450        # 'foo' is the current directory, '/' is the parent directory
     451        self.assertEquals(str(self.path.parent()), 'http://alice:asecret@example.com/')
     452        self.assertEquals(str(self.path.child('').parent()), 'http://alice:asecret@example.com/foo/')
     453        self.assertEquals(str(self.path.child('baz').parent()), 'http://alice:asecret@example.com/foo/')
     454        self.assertEquals(str(self.path.parent().parent().parent().parent().parent()), 'http://alice:asecret@example.com/')
     455
     456    def testHereString(self):
     457        # here should be equivalent to '.'
     458        self.assertEquals(str(self.path.here()), 'http://alice:asecret@example.com/foo/')
     459        self.assertEquals(str(self.path.child('').here()), 'http://alice:asecret@example.com/foo/bar/')
     460
     461    def testAuthString(self):
     462        self.assertEquals(str(self.path.user), 'alice')
     463        self.assertEquals(str(self.path.password), 'asecret')
     464        self.assertEquals(str(self.path.host), 'example.com')
     465        self.assertEquals(self.path.port, 0)
     466
     467class URLPathAuthPartialNoPassword(unittest.TestCase):
     468    def setUp(self):
     469        self.path = urlpath.URLPath.fromString("http://bob@example.com:8080")
     470
     471    def testAuthString(self):
     472        self.assertEquals(str(self.path.user), 'bob')
     473        self.assertEquals(str(self.path.password), '')
     474        self.assertEquals(str(self.path.host), 'example.com')
     475        self.assertEquals(self.path.port, 8080)
     476
     477
     478class URLPathAuthPartialNoUser(unittest.TestCase):
     479    def setUp(self):
     480        # not really sure of a use case for this one, but oh well...
     481        self.path = urlpath.URLPath.fromString("http://:asecret@example.com:8080")
     482
     483    def testAuthString(self):
     484        self.assertEquals(str(self.path.user), '')
     485        self.assertEquals(str(self.path.password), 'asecret')
     486        self.assertEquals(str(self.path.host), 'example.com')
     487        self.assertEquals(self.path.port, 8080)