def test_key_error(self): self.args = [ "command_dummy", "--host", TESTSERVER_URL + "/service?request=GetCapabilities", ] with open(CAPABILITIES111_FILE, "rb") as fp: capabilities_doc = fp.read() capabilities_doc = capabilities_doc.replace(b"minx", b"foo") with mock_httpd( TESTSERVER_ADDRESS, [( { "path": "/service?request=GetCapabilities&version=1.1.1&service=WMS", "method": "GET", }, { "status": "200", "body": capabilities_doc }, )], ): with capture() as (out, err): with pytest.raises(SystemExit): wms_capabilities_command(self.args) assert err.getvalue().startswith( "XML-Element has no such attribute")
def test_service_exception(self): self.args = [ "command_dummy", "--host", TESTSERVER_URL + "/service?request=GetCapabilities", ] with open(SERVICE_EXCEPTION_FILE, "rb") as fp: capabilities_doc = fp.read() with mock_httpd( TESTSERVER_ADDRESS, [( { "path": "/service?request=GetCapabilities&version=1.1.1&service=WMS", "method": "GET", }, { "status": "200", "body": capabilities_doc }, )], ): with capture() as (out, err): with pytest.raises(SystemExit): wms_capabilities_command(self.args) error_msg = err.getvalue().rsplit("-" * 80, 1)[1].strip() assert "Not a capabilities document" in error_msg
def test_parse_130capabilities(self): self.args = [ "command_dummy", "--host", TESTSERVER_URL + "/service?request=GetCapabilities", "--version", "1.3.0", ] with open(CAPABILITIES130_FILE, "rb") as fp: capabilities_doc = fp.read() with mock_httpd( TESTSERVER_ADDRESS, [( { "path": "/service?request=GetCapabilities&version=1.3.0&service=WMS", "method": "GET", }, { "status": "200", "body": capabilities_doc }, )], ): with capture() as (out, err): wms_capabilities_command(self.args) lines = out.getvalue().split("\n") assert lines[1].startswith( "Capabilities Document Version 1.3.0")
def test_parse_capabilities(self): self.args = ['command_dummy', '--host', TESTSERVER_URL + '/service?request=GetCapabilities'] with open(CAPABILITIES_FILE, 'r') as fp: capabilities_doc = fp.read() with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/service?request=GetCapabilities', 'method': 'GET'}, {'status': '200', 'body': capabilities_doc})]): with capture_out() as (out,err): wms_capabilities_command(self.args) lines = out.getvalue().split('\n') assert lines[1].startswith('Root-Layer:')
def test_parse_130capabilities(self): self.args = ['command_dummy', '--host', TESTSERVER_URL + '/service?request=GetCapabilities', '--version', '1.3.0'] with open(CAPABILITIES130_FILE, 'rb') as fp: capabilities_doc = fp.read() with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/service?request=GetCapabilities&version=1.3.0&service=WMS', 'method': 'GET'}, {'status': '200', 'body': capabilities_doc})]): with capture() as (out,err): wms_capabilities_command(self.args) lines = out.getvalue().split('\n') assert lines[1].startswith('Capabilities Document Version 1.3.0')
def test_http_error(self): self.args = ["command_dummy", "--host", "http://foo.doesnotexist"] with capture() as (out, err): with pytest.raises(SystemExit): wms_capabilities_command(self.args) assert err.getvalue().startswith("ERROR:") self.args[2] = "/no/valid/url" with capture() as (out, err): with pytest.raises(SystemExit): wms_capabilities_command(self.args) assert err.getvalue().startswith("ERROR:")
def test_parse_capabilities(self): self.args = [ 'command_dummy', '--host', TESTSERVER_URL + '/service?request=GetCapabilities' ] with open(CAPABILITIES_FILE, 'r') as fp: capabilities_doc = fp.read() with mock_httpd(TESTSERVER_ADDRESS, [({ 'path': '/service?request=GetCapabilities', 'method': 'GET' }, { 'status': '200', 'body': capabilities_doc })]): with capture_out() as (out, err): wms_capabilities_command(self.args) lines = out.getvalue().split('\n') assert lines[1].startswith('Root-Layer:')
def test_request_not_parsable(self): with mock_httpd( TESTSERVER_ADDRESS, [( { "path": "/service?request=GetCapabilities&version=1.1.1&service=WMS", "method": "GET", }, { "status": "200", "body": "" }, )], ): with capture() as (out, err): with pytest.raises(SystemExit): wms_capabilities_command(self.args) error_msg = err.getvalue().rsplit("-" * 80, 1)[1].strip() assert error_msg.startswith("Could not parse the document")