def test_slumber_local_url_with_services_but_no_service_specified(self): with patch( "slumber.server.get_slumber_directory", lambda: {"pizzas": "http://localhost:8000:/slumber/pizzas/", "takeaway": "http://localhost:8002:/slumber/"}, ): with self.assertRaises(NoServiceSpecified): self.assertEqual(get_slumber_local_url_prefix(), "http://localhost:8000:/")
def test_slumber_local_url_with_services(self): with patch('slumber.server.get_slumber_directory', lambda: { 'pizzas': 'http://localhost:8000:/slumber/pizzas/', 'takeaway': 'http://localhost:8002:/slumber/'}): with patch('slumber.server.get_slumber_service', lambda: 'pizzas'): self.assertEqual(get_slumber_local_url_prefix(), 'http://localhost:8000:/')
def test_slumber_local_url_with_services(self): with patch( "slumber.server.get_slumber_directory", lambda: {"pizzas": "http://localhost:8000:/slumber/pizzas/", "takeaway": "http://localhost:8002:/slumber/"}, ): with patch("slumber.server.get_slumber_service", lambda: "pizzas"): self.assertEqual(get_slumber_local_url_prefix(), "http://localhost:8000:/")
def test_slumber_local_url_with_services_but_no_service_specified(self): with patch('slumber.server.get_slumber_directory', lambda: { 'pizzas': 'http://localhost:8000:/slumber/pizzas/', 'takeaway': 'http://localhost:8002:/slumber/'}): with self.assertRaises(NoServiceSpecified): self.assertEqual(get_slumber_local_url_prefix(), 'http://localhost:8000:/')
def test_slumber_local_url_with_services_but_relative_self_service_url(self): with patch( "slumber.server.get_slumber_directory", lambda: {"pizzas": "/slumber/pizzas/", "takeaway": "http://localhost:8002:/slumber/"}, ): with patch("slumber.server.get_slumber_service", lambda: "pizzas"): with self.assertRaises(AbsoluteURIRequired): self.assertEqual(get_slumber_local_url_prefix(), "http://localhost:8000:/")
def test_slumber_local_url_with_services_but_relative_self_service_url(self): with patch('slumber.server.get_slumber_directory', lambda: { 'pizzas': '/slumber/pizzas/', 'takeaway': 'http://localhost:8002:/slumber/'}): with patch('slumber.server.get_slumber_service', lambda: 'pizzas'): with self.assertRaises(AbsoluteURIRequired): self.assertEqual(get_slumber_local_url_prefix(), 'http://localhost:8000:/')
def _use_fake(url): """Return the local URL fragment if the request should use the Fake HTTP client as it is local, otherwise return None """ slumber_local = get_slumber_local_url_prefix() if url.startswith(slumber_local): logging.debug("Using local fake HTTP due to %s starting with %s", url, slumber_local) return url[len(slumber_local) - 1 :] elif url.startswith("/"): logging.debug("Using local fake HTTP due to %s starting with /", url) return url logging.debug("Using real HTTP for %s", url)
def _use_fake(url): """Return the local URL fragment if the request should use the Fake HTTP client as it is local, otherwise return None """ slumber_local = get_slumber_local_url_prefix() if url.startswith(slumber_local): logging.debug("Using local fake HTTP due to %s starting with %s", url, slumber_local) return url[len(slumber_local) - 1:] elif url.startswith('/'): logging.debug("Using local fake HTTP due to %s starting with /", url) return url logging.debug("Using real HTTP for %s", url)
def test_slumber_local_url_https(self): with patch('slumber.server.get_slumber_directory', lambda: 'https://example.com/somewhere/slumber/'): self.assertEqual(get_slumber_local_url_prefix(), 'https://example.com/')
def test_slumber_local_url_dev_server(self): with patch('slumber.server.get_slumber_directory', lambda: 'http://localhost:8008/somewhere/slumber/'): self.assertEqual(get_slumber_local_url_prefix(), 'http://localhost:8008/')
def test_slumber_local_url_https(self): with patch("slumber.server.get_slumber_directory", lambda: "https://example.com/somewhere/slumber/"): self.assertEqual(get_slumber_local_url_prefix(), "https://example.com/")
def test_slumber_local_url_dev_server(self): with patch("slumber.server.get_slumber_directory", lambda: "http://localhost:8008/somewhere/slumber/"): self.assertEqual(get_slumber_local_url_prefix(), "http://localhost:8008/")
def test_slumber_local_url(self): with patch('slumber.server.get_slumber_directory', lambda: 'http://example.com/somewhere/slumber/'): self.assertEqual(get_slumber_local_url_prefix(), 'http://example.com/')