def test_server_path(self): rsp = RsParameters(url_prefix="http://example.com/bla/foo/bar") self.assertEquals("http://example.com/bla/foo/bar/", rsp.url_prefix) self.assertEquals("/bla/foo/bar/", rsp.server_path()) rsp.url_prefix = "http://www.example.com" self.assertEquals("http://www.example.com/", rsp.url_prefix) self.assertEquals("/", rsp.server_path())
def test_server_root(self): rsp = RsParameters(url_prefix="http://example.com/bla/foo/bar") self.assertEquals(rsp.server_root(), "http://example.com") rsp.url_prefix = "http://www.example.com" self.assertEquals(rsp.server_root(), "http://www.example.com")
def test_url_prefix(self): # defaults to configuration defaults Configuration().core_clear() rsp = RsParameters() self.assertEquals(rsp.url_prefix, "http://www.example.com/") rsp = RsParameters(url_prefix="http://foo.bar.com") self.assertEquals(rsp.url_prefix, "http://foo.bar.com/") # contamination test rsp2 = RsParameters(**rsp.__dict__) self.assertEquals(rsp2.url_prefix, "http://foo.bar.com/") with self.assertRaises(Exception) as context: rsp.url_prefix = "nix://foo.bar.com" #print(context.exception) self.assertEquals( "URL schemes allowed are 'http' or 'https'. Given: 'nix://foo.bar.com'", context.exception.args[0]) self.assertIsInstance(context.exception, ValueError) with self.assertRaises(Exception) as context: rsp.url_prefix = "https://.nl" #print(context.exception) self.assertEquals( "URL has invalid domain name: '.nl'. Given: 'https://.nl'", context.exception.args[0]) self.assertIsInstance(context.exception, ValueError) with self.assertRaises(Exception) as context: rsp.url_prefix = "https://foo.bar.com#foo" #print(context.exception) self.assertEquals( "URL should not have a fragment. Given: 'https://foo.bar.com#foo'", context.exception.args[0]) self.assertIsInstance(context.exception, ValueError) with self.assertRaises(Exception) as context: rsp.url_prefix = "http://foo.bar.com?what=this" #print(context.exception) self.assertEquals( "URL should not have a query string. Given: 'http://foo.bar.com?what=this'", context.exception.args[0]) self.assertIsInstance(context.exception, ValueError) with self.assertRaises(Exception) as context: rsp.url_prefix = "http://foo.bar.com/fragment#is" #print(context.exception) self.assertEquals( "URL should not have a fragment. Given: 'http://foo.bar.com/fragment#is'", context.exception.args[0]) self.assertIsInstance(context.exception, ValueError) with self.assertRaises(Exception) as context: rsp.url_prefix = "http://foo.bar.com/ uhr.isrong" #print(context.exception) self.assertEquals( "URL is invalid. Given: 'http://foo.bar.com/ uhr.isrong'", context.exception.args[0]) self.assertIsInstance(context.exception, ValueError) self.save_configuration_test(rsp)