Пример #1
0
    def test_execute_no_duplicates(self, mock_request):
        mock_request.return_value.status_code = 200

        mock_request.return_value.text = self.execute.toxml(bds=cwt.bds)

        client = cwt.WPSClient('http://idontexist/wps')

        process = cwt.Process.from_identifier('CDAT.subset')

        process.description = mock.MagicMock()

        client.execute(process, [cwt.Variable('file:///test.nc', 'tas')],
                       cwt.Domain([cwt.Dimension('time', 0, 365)]),
                       axes=['time'])

        self.assertEqual(len(process.parameters), 0)
        self.assertIsNone(process.domain)
        self.assertEqual(len(process.inputs), 0)
        self.assertIsNotNone(process.response)
Пример #2
0
    def test_ssl_verify(self, mock_request):
        mock_request.return_value.status_code = 200

        mock_request.return_value.text = self.capabilities.toxml(bds=cwt.bds)

        client = cwt.WPSClient('http://idontexist/wps')

        client.get_capabilities()

        mock_request.assert_called_with('GET',
                                        'http://idontexist/wps',
                                        timeout=None,
                                        params={
                                            'request': 'GetCapabilities',
                                            'service': 'WPS'
                                        },
                                        data=None,
                                        headers={},
                                        verify=True)
Пример #3
0
    def test_describe_process(self, mock_request):
        mock_request.return_value.status_code = 200

        mock_request.return_value.text = self.process_descriptions.toxml(
            bds=cwt.bds)

        client = cwt.WPSClient('http://idontexist/wps')

        process = cwt.Process.from_identifier('CDAT.subset')

        description = client.describe_process(process)

        self.assertIsInstance(description, list)

        subset = description[0]

        self.assertIsInstance(subset, cwt.ProcessDescriptionWrapper)
        self.assertEqual(subset.identifier, 'CDAT.subset')
        self.assertEqual(subset.title, 'CDAT.subset')
        self.assertEqual(subset.abstract, 'abstract text')
        self.assertEqual(subset.metadata, {'inputs': '1'})
Пример #4
0
    def test_prepare_data_inputs(self):
        variable = cwt.Variable('file:///test.nc', 'tas', name='v0')

        domain = cwt.Domain([
            cwt.Dimension('time', 0, 365),
        ], name='d0')

        process = cwt.Process('CDAT.subset', name='subset')

        process.description = mock.MagicMock()

        process.description.metadata.return_value = {}

        client = cwt.WPSClient('http://idontexist/wps')

        data_inputs = client.prepare_data_inputs_str(process, [variable],
                                                     domain)

        self.assertIn('"id": "tas|v0"', data_inputs)
        self.assertIn('"id": "d0"', data_inputs)
        self.assertIn('"name": "CDAT.subset"', data_inputs)
Пример #5
0
    def get_client_token(self):
        client = cwt.WPSClient(self.host, api_key=self.token, verify=False)

        return client
Пример #6
0
    def get_client(self):
        client = cwt.WPSClient(self.host, verify=False)

        return client
Пример #7
0
    proc.wait()

    return proc.output


def validate_output(variable, shape):
    with cdms2.open(variable.uri) as infile:
        v = infile[variable.var_name]

        if v.shape == shape:
            print 'VERIFIED {!r} matches {!r}'.format(v.shape, shape)
        else:
            print 'FAILED {!r} does not match {!r}'.format(v.shape, shape)


client = cwt.WPSClient(args.url, api_key=args.api_key, verify=False)

for x in client.processes():
    print x.identifier

domain = cwt.Domain(time=(50, 150), lat=(0, 90))

gridder = cwt.Gridder(grid='gaussian~32')

validate_output(test_operation(client, 'CDAT.aggregate', variables, domain),
                (801, 95, 384))

validate_output(test_operation(client, 'CDAT.subset', variables[:1], domain),
                (89, 95, 384))

domain2 = cwt.Domain(time=(45, 50))
Пример #8
0
def test_api_key():
    client = cwt.WPSClient('https://127.0.0.1/wps', api_key='test')

    assert client.headers['COMPUTE-TOKEN'] == 'test'
Пример #9
0
def test_api_key_not_present():
    client = cwt.WPSClient('https://127.0.0.1/wps')

    assert 'COMPUTE-TOKEN' not in client.headers
Пример #10
0
def test_compute_token():
    client = cwt.WPSClient('https://127.0.0.1/wps', compute_token='test')

    assert client.headers['COMPUTE-TOKEN'] == 'test'
Пример #11
0
def test_compute_token_env(mocker):
    mocker.patch.dict(os.environ, {'COMPUTE_TOKEN': 'test'})

    client = cwt.WPSClient('https://127.0.0.1/wps')

    assert client.headers['COMPUTE-TOKEN'] == 'test'
Пример #12
0
 def test_logging(self):
     client = cwt.WPSClient('http://idontexist/wps',
                            log=True,
                            log_file='./wps.log')