Пример #1
0
 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:/")
Пример #2
0
 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:/')
Пример #3
0
 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:/")
Пример #4
0
 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:/')
Пример #5
0
 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:/')
Пример #6
0
 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:/')
Пример #7
0
 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:/")
Пример #8
0
 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:/')
Пример #9
0
 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:/')
Пример #10
0
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)
Пример #11
0
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)
Пример #12
0
 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/')
Пример #13
0
 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/')
Пример #14
0
 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/")
Пример #15
0
 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/")
Пример #16
0
 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/')