Exemplo n.º 1
0
    def setUp(self):
        tmp_dir = tempfile.mkdtemp()
        data_format = get_data_format('application/json')
        self.complex_out = ComplexOutput(identifier="complexinput",
                                         workdir=tmp_dir,
                                         data_format=data_format,
                                         supported_formats=[data_format],
                                         mode=MODE.NONE)

        self.complex_out_nc = ComplexOutput(
            identifier="netcdf",
            workdir=tmp_dir,
            data_format=get_data_format('application/x-netcdf'),
            supported_formats=[get_data_format('application/x-netcdf')],
            mode=MODE.NONE)

        self.data = json.dumps({
            'a': 1,
            'unicodé': u'éîïç',
        })
        self.ncfile = os.path.join(DATA_DIR, 'netcdf', 'time.nc')

        self.test_fn = os.path.join(self.complex_out.workdir, 'test.json')
        with open(self.test_fn, 'w') as f:
            f.write(self.data)
Exemplo n.º 2
0
 def test_build_output_name(self):
     storage = FileStorageBuilder().build()
     output = ComplexOutput('testme',
                            'Test',
                            supported_formats=[FORMATS.TEXT],
                            workdir=self.tmp_dir)
     output.data = "Hello World!"
     output_name, suffix = _build_output_name(output)
     self.assertEqual(output.file, self.tmp_dir + '/input.txt')
     self.assertEqual(output_name, 'input.txt')
     self.assertEqual(suffix, '.txt')
Exemplo n.º 3
0
    def test_write(self):
        configuration.CONFIG.set('server', 'outputpath', self.tmp_dir)
        configuration.CONFIG.set('server', 'outputurl',
                                 'file://' + self.tmp_dir)
        storage = FileStorageBuilder().build()
        output = ComplexOutput('testme',
                               'Test',
                               supported_formats=[FORMATS.TEXT],
                               workdir=self.tmp_dir)
        output.data = "Hello World!"
        url = storage.write(output.data, 'foo.txt')

        self.assertEqual(url, 'file://' + self.tmp_dir + '/foo.txt')
        with open(self.tmp_dir + '/foo.txt') as f:
            self.assertEqual(f.read(), "Hello World!")
Exemplo n.º 4
0
    def test_store(self):
        configuration.CONFIG.set('server', 'outputpath', self.tmp_dir)
        storage = FileStorageBuilder().build()
        output = ComplexOutput('testme',
                               'Test',
                               supported_formats=[FORMATS.TEXT],
                               workdir=self.tmp_dir)
        output.data = "Hello World!"
        store_type, store_str, url = storage.store(output)

        self.assertEqual(store_type, STORE_TYPE.PATH)
        self.assertEqual(store_str, 'input.txt')

        with open(self.tmp_dir + '/' + store_str) as f:
            self.assertEqual(f.read(), "Hello World!")
Exemplo n.º 5
0
 def setUp(self):
     tmp_dir = tempfile.mkdtemp()
     data_format = get_data_format('application/json')
     self.complex_out = ComplexOutput(identifier="complexinput",
                                      workdir=tmp_dir,
                                      data_format=data_format,
                                      supported_formats=[data_format])
Exemplo n.º 6
0
class ComplexOutputTest(unittest.TestCase):
    """ComplexOutput test cases"""

    def setUp(self):
        tmp_dir = tempfile.mkdtemp()
        data_format = get_data_format('application/json')
        self.complex_out = ComplexOutput(identifier="complexinput", workdir=tmp_dir,
                                         data_format=data_format,
                                         supported_formats=[data_format],
                                         mode=MODE.NONE)
        self.data = json.dumps({'a': 1, 'unicodé': u'éîïç', })

        self.test_fn = os.path.join(self.complex_out.workdir, 'test.json')
        with open(self.test_fn, 'w') as f:
            f.write(self.data)

    def test_contruct(self):
        self.assertIsInstance(self.complex_out, ComplexOutput)

    def test_data_format(self):
        self.assertIsInstance(self.complex_out.data_format, Format)

    def test_storage(self):
        class Storage(object):
            pass
        storage = Storage()
        self.complex_out.store = storage
        self.assertEqual(self.complex_out.store, storage)

    def test_validator(self):
        self.assertEqual(self.complex_out.validator,
                         get_validator('application/json'))

    def test_file_handler(self):
        self.complex_out.file = self.test_fn
        self.assertEqual(self.complex_out.data, self.data)
        if PY2:
            self.assertEqual(self.complex_out.stream.read(), self.data)
        else:
            with self.complex_out.stream as s:
                self.assertEqual(s.read(), bytes(self.data, encoding='utf8'))

        with open(urlparse(self.complex_out.url).path) as f:
            self.assertEqual(f.read(), self.data)

    def test_data_handler(self):
        self.complex_out.data = self.data
        with open(self.complex_out.file) as f:
            self.assertEqual(f.read(), self.data)

    def test_url_handler(self):
        wfsResource = 'http://demo.mapserver.org/cgi-bin/wfs?' \
                      'service=WFS&version=1.1.0&' \
                      'request=GetFeature&' \
                      'typename=continents&maxfeatures=2'
        self.complex_out.url = wfsResource
        storage = FileStorage()
        self.complex_out.storage = storage
        url = self.complex_out.get_url()
        self.assertEqual('file', urlparse(url).scheme)
Exemplo n.º 7
0
    def test_store(self, uploadData):
        configuration.CONFIG.set('s3', 'bucket', 'notrealbucket')
        configuration.CONFIG.set('s3', 'prefix', 'wps')
        storage = S3StorageBuilder().build()
        output = ComplexOutput('testme', 'Test', supported_formats=[FORMATS.TEXT], workdir=self.tmp_dir)
        output.data = "Hello World!"

        store_type, filename, url = storage.store(output)

        called_args = uploadData.call_args[0]

        self.assertEqual(store_type, STORE_TYPE.S3)
        self.assertEqual(filename, 'wps/input.txt')

        self.assertEqual(uploadData.call_count, 1)
        self.assertEqual(called_args[1], 'wps/input.txt')
        self.assertEqual(called_args[2], {'ContentType': 'text/plain'})
Exemplo n.º 8
0
    def test_url(self):
        configuration.CONFIG.set('server', 'outputpath', self.tmp_dir)
        configuration.CONFIG.set('server', 'outputurl',
                                 'file://' + self.tmp_dir)
        storage = FileStorageBuilder().build()
        output = ComplexOutput('testme',
                               'Test',
                               supported_formats=[FORMATS.TEXT],
                               workdir=self.tmp_dir)
        output.data = "Hello World!"
        url = storage.url(output)

        self.assertEqual('file://' + self.tmp_dir + '/input.txt', url)

        file_name = 'test.txt'
        url = storage.url(file_name)

        self.assertEqual('file://' + self.tmp_dir + '/test.txt', url)
Exemplo n.º 9
0
    def setUp(self):
        tmp_dir = tempfile.mkdtemp()
        data_format = get_data_format('application/json')
        self.complex_out = ComplexOutput(identifier="complexinput", workdir=tmp_dir,
                                         data_format=data_format,
                                         supported_formats=[data_format],
                                         mode=MODE.NONE)

        self.complex_out_nc = ComplexOutput(identifier="netcdf", workdir=tmp_dir,
                                            data_format=get_data_format('application/x-netcdf'),
                                            supported_formats=[get_data_format('application/x-netcdf')],
                                            mode=MODE.NONE)

        self.data = json.dumps({'a': 1, 'unicodé': u'éîïç', })
        self.ncfile = os.path.join(DATA_DIR, 'netcdf', 'time.nc')

        self.test_fn = os.path.join(self.complex_out.workdir, 'test.json')
        with open(self.test_fn, 'w') as f:
            f.write(self.data)
Exemplo n.º 10
0
class ComplexOutputTest(unittest.TestCase):
    """ComplexOutput test cases"""

    def setUp(self):
        tmp_dir = tempfile.mkdtemp()
        data_format = get_data_format('application/json')
        self.complex_out = ComplexOutput(identifier="complexinput", workdir=tmp_dir,
                                         data_format=data_format,
                                         supported_formats=[data_format],
                                         mode=MODE.NONE)

        self.complex_out_nc = ComplexOutput(identifier="netcdf", workdir=tmp_dir,
                                            data_format=get_data_format('application/x-netcdf'),
                                            supported_formats=[get_data_format('application/x-netcdf')],
                                            mode=MODE.NONE)

        self.data = json.dumps({'a': 1, 'unicodé': u'éîïç', })
        self.ncfile = os.path.join(DATA_DIR, 'netcdf', 'time.nc')

        self.test_fn = os.path.join(self.complex_out.workdir, 'test.json')
        with open(self.test_fn, 'w') as f:
            f.write(self.data)

    def test_contruct(self):
        self.assertIsInstance(self.complex_out, ComplexOutput)

    def test_data_format(self):
        self.assertIsInstance(self.complex_out.data_format, Format)

    def test_storage(self):
        class Storage(object):
            pass
        storage = Storage()
        self.complex_out.store = storage
        self.assertEqual(self.complex_out.store, storage)

    def test_validator(self):
        self.assertEqual(self.complex_out.validator,
                         get_validator('application/json'))

        self.assertEqual(self.complex_out_nc.validator,
                         get_validator('application/x-netcdf'))

    def test_file_handler(self):
        self.complex_out.file = self.test_fn
        self.assertEqual(self.complex_out.data, self.data)
        if PY2:
            self.assertEqual(self.complex_out.stream.read(), self.data)
        else:
            with self.complex_out.stream as s:
                self.assertEqual(s.read(), bytes(self.data, encoding='utf8'))

        with open(urlparse(self.complex_out.url).path) as f:
            self.assertEqual(f.read(), self.data)

    def test_file_handler_netcdf(self):
        self.complex_out_nc.file = self.ncfile
        data = self.complex_out_nc.base64

    def test_data_handler(self):
        self.complex_out.data = self.data
        with open(self.complex_out.file) as f:
            self.assertEqual(f.read(), self.data)

    def test_base64(self):
        self.complex_out.data = self.data
        b = self.complex_out.base64
        if PY2:
            self.assertEqual(base64.b64decode(b), self.data)
        else:
            self.assertEqual(base64.b64decode(b).decode(), self.data)

    def test_url_handler(self):
        wfsResource = 'http://demo.mapserver.org/cgi-bin/wfs?' \
                      'service=WFS&version=1.1.0&' \
                      'request=GetFeature&' \
                      'typename=continents&maxfeatures=2'
        self.complex_out.url = wfsResource
        storage = FileStorage()
        self.complex_out.storage = storage
        url = self.complex_out.get_url()
        self.assertEqual('file', urlparse(url).scheme)