def testFullServerURL(self):
        """
        Whole server URL understanding.
        """
        def test(host, port, protocol=None):
            url = ''.join(
                [protocol + "://" if protocol else "", host, ":",
                 str(port)])

            sprotocol, shost, sport = split_server_url(url)
            self.assertEqual(sprotocol, expected_protocol(protocol, port))
            self.assertEqual(shost, host)
            self.assertEqual(sport, expected_port(protocol, port))

        test("localhost", 8001)
        test("localhost", 8002)
        test("1hostname.can.begin.with.digits", 9999)
        test("another.server", 80, "http")
        test("very-secure.another.server", 443, 'https')

        sprotocol, shost, sport = \
            split_server_url('https://someserver:1234/Product')
        self.assertEqual(sprotocol, 'https')
        self.assertEqual(shost, 'someserver')
        self.assertEqual(sport, 1234)

        sprotocol, shost, sport = \
            split_server_url('http://[::1]:1234/Product')
        self.assertEqual(sprotocol, 'http')
        self.assertEqual(shost, '[::1]')
        self.assertEqual(sport, 1234)
        def test(host, protocol=None):
            url = ''.join([protocol + "://" if protocol else "", host])

            sprotocol, shost, sport = split_server_url(url)
            self.assertEqual(sprotocol, expected_protocol(protocol, None))
            self.assertEqual(shost, host)
            self.assertEqual(sport, expected_port(protocol, None))
    def testBadServerURLs(self):
        """
        Parser throws on bad server URLs?
        """

        with self.assertRaises(ValueError):
            split_server_url("in:valid:format")

        with self.assertRaises(ValueError):
            split_server_url("localhost:12PortIsANumber34")

        with self.assertRaises(ValueError):
            split_server_url("whatever://whatev.er")

        with self.assertRaises(ValueError):
            split_server_url("http://::1:8081")