Esempio n. 1
0
    def test_encode_path(self):
        self.assertEqual(
            encode_url_path('/ws/init',
                            query_args=OrderedDict([
                                ('base_path', '/home/norman/workpaces'),
                                ('description', 'Hi there!')
                            ])),
            '/ws/init?base_path=%2Fhome%2Fnorman%2Fworkpaces&description=Hi+there%21'
        )
        self.assertEqual(
            encode_url_path('/ws/init',
                            query_args=OrderedDict([
                                ('base_path', 'C:\\Users\\Norman\\workpaces'),
                                ('description', 'Hi there!')
                            ])),
            '/ws/init?base_path=C%3A%5CUsers%5CNorman%5Cworkpaces&description=Hi+there%21'
        )

        self.assertEqual(
            encode_url_path(
                '/ws/get/{base_path}',
                path_args=dict(base_path='/home/norman/workpaces')),
            '/ws/get/%2Fhome%2Fnorman%2Fworkpaces')
        self.assertEqual(
            encode_url_path(
                '/ws/get/{base_path}',
                path_args=dict(base_path='C:\\Users\\Norman\\workpaces')),
            '/ws/get/C%3A%5CUsers%5CNorman%5Cworkpaces')
Esempio n. 2
0
    def test_encode_path(self):
        self.assertEqual(encode_url_path('/ws/init',
                                         query_args=OrderedDict([('base_path', '/home/norman/workpaces'),
                                                                 ('description', 'Hi there!')])),
                         '/ws/init?base_path=%2Fhome%2Fnorman%2Fworkpaces&description=Hi+there%21')
        self.assertEqual(encode_url_path('/ws/init',
                                         query_args=OrderedDict([('base_path', 'C:\\Users\\Norman\\workpaces'),
                                                                 ('description', 'Hi there!')])),
                         '/ws/init?base_path=C%3A%5CUsers%5CNorman%5Cworkpaces&description=Hi+there%21')

        self.assertEqual(encode_url_path('/ws/get/{base_path}',
                                         path_args=dict(base_path='/home/norman/workpaces')),
                         '/ws/get/%2Fhome%2Fnorman%2Fworkpaces')
        self.assertEqual(encode_url_path('/ws/get/{base_path}',
                                         path_args=dict(base_path='C:\\Users\\Norman\\workpaces')),
                         '/ws/get/C%3A%5CUsers%5CNorman%5Cworkpaces')
Esempio n. 3
0
 def _url(self, path_pattern: str, path_args: dict = None, query_args: dict = None) -> str:
     return self.base_url + encode_url_path(path_pattern, path_args=path_args, query_args=query_args)
Esempio n. 4
0
    def test_workspace_session(self):
        base_dir = os.path.abspath('TEST_WORKSPACE')

        if os.path.exists(base_dir):
            shutil.rmtree(base_dir)

        response = self.fetch(
            encode_url_path('/ws/new',
                            query_args=dict(
                                base_dir=os.path.abspath('TEST_WORKSPACE'),
                                description='Wow!')))
        self.assertEqual(response.code, 200)
        json_dict = json.loads(response.body.decode('utf-8'))
        self.assertIn('status', json_dict, msg=json_dict)
        self.assertIn('content', json_dict, msg=json_dict)
        self.assertIn('base_dir', json_dict['content'], msg=json_dict)
        self.assertIn('workflow', json_dict['content'], msg=json_dict)

        response = self.fetch(
            encode_url_path(
                '/ws/save/{base_dir}',
                path_args=dict(base_dir=os.path.abspath('TEST_WORKSPACE'))))

        self.assertEqual(response.code, 200)
        json_dict = json.loads(response.body.decode('utf-8'))
        self.assertIn('status', json_dict)
        self.assertEqual(json_dict['status'], 'ok', msg=json_dict)

        res_name = 'ds'

        file_path = NETCDF_TEST_FILE
        op_args = ["file='%s'" % file_path.replace('\\', '\\\\')]
        data = dict(op_name='cate.ops.io.read_netcdf',
                    op_args=json.dumps(op_args))
        body = urllib.parse.urlencode(data)
        url = encode_url_path('/ws/res/set/{base_dir}/{res_name}',
                              path_args=dict(
                                  base_dir=os.path.abspath(base_dir),
                                  res_name=res_name))
        response = self.fetch(url, method='POST', body=body)

        self.assertEqual(response.code, 200)
        json_dict = json.loads(response.body.decode('utf-8'))
        self.assertIn('status', json_dict)
        self.assertEqual(json_dict['status'], 'ok', msg=json_dict)

        file_path = os.path.abspath(
            os.path.join('TEST_WORKSPACE', 'precip_and_temp_copy.nc'))
        url = encode_url_path('/ws/res/write/{base_dir}/{res_name}',
                              path_args=dict(
                                  base_dir=os.path.abspath(base_dir),
                                  res_name=res_name),
                              query_args=dict(file_path=file_path))
        response = self.fetch(url, method='GET')

        self.assertEqual(response.code, 200)
        json_dict = json.loads(response.body.decode('utf-8'))
        self.assertIn('status', json_dict)
        self.assertEqual(json_dict['status'], 'ok', msg=json_dict)

        self.assertTrue(os.path.isfile(file_path))

        if os.path.exists(base_dir):
            shutil.rmtree(base_dir)
Esempio n. 5
0
 def _url(self, path_pattern: str, path_args: dict = None, query_args: dict = None) -> str:
     return self.base_url + encode_url_path(path_pattern, path_args=path_args, query_args=query_args)