Esempio n. 1
0
def test_fetch_no_server():
    url = 'http://localhost:65534/something-silly.txt'
    try:
        fetch_config(url)
        assert False, 'The fetch should not have succeeded'
    except ConfigurationError as error:
        pass
Esempio n. 2
0
def test_fetch_from_url_404():
    url = None
    try:
        with TestHTTPServer(SimpleHandler) as server:
            url = f'http://localhost:{server.port}/bad_path.txt'
            fetch_config(url)
            assert False, 'The fetch should not have succeeded'
    except ConfigurationError as error:
        assert list(error.reasons) == [f'HTTP 404: {url}']
 def test_fetch_from_url_404(self):
     url = None
     try:
         with TestHTTPServer(SimpleHandler) as server:
             url = f'http://localhost:{server.port}/bad_path.txt'
             fetch_config(url)
             self.fail('The fetch should not have succeeded')
     except ConfigurationError as error:
         self.assertListEqual(error.reasons, [f'HTTP 404: {url}'])
Esempio n. 4
0
def test_fetch_from_file():
    with tempfile.NamedTemporaryFile() as buf:
        buf.file.write('TEST CONFIG'.encode('utf8'))
        buf.file.close()
        actual = fetch_config(buf.name)
    assert 'TEST CONFIG' == actual
Esempio n. 5
0
def test_fetch_from_url_200():
    with TestHTTPServer(SimpleHandler) as server:
        actual = fetch_config(f'http://localhost:{server.port}/good_path.txt')
    assert SimpleHandler.BODY == actual