Esempio n. 1
0
 def setUp(self):
     self.workspaces = Workspaces(os.getenv('KBC_TEST_API_URL'),
                                  os.getenv('KBC_TEST_TOKEN'))
     self.buckets = Buckets(os.getenv('KBC_TEST_API_URL'),
                            os.getenv('KBC_TEST_TOKEN'))
     self.jobs = Jobs(os.getenv('KBC_TEST_API_URL'),
                      os.getenv('KBC_TEST_TOKEN'))
     self.tables = Tables(os.getenv('KBC_TEST_API_URL'),
                          os.getenv('KBC_TEST_TOKEN'))
     self.files = Files(os.getenv('KBC_TEST_API_URL'),
                        os.getenv('KBC_TEST_TOKEN'))
     try:
         file_list = self.files.list(tags=['sapi-client-python-tests'])
         for file in file_list:
             self.files.delete(file['id'])
     except exceptions.HTTPError as e:
         if e.response.status_code != 404:
             raise
     try:
         self.buckets.delete('in.c-py-test-buckets', force=True)
     except exceptions.HTTPError as e:
         if e.response.status_code != 404:
             raise
     # https://github.com/boto/boto3/issues/454
     warnings.simplefilter("ignore", ResourceWarning)
Esempio n. 2
0
 def setUp(self):
     self.tables = Tables(os.getenv('KBC_TEST_API_URL'),
                          os.getenv('KBC_TEST_TOKEN'))
     self.buckets = Buckets(os.getenv('KBC_TEST_API_URL'),
                            os.getenv('KBC_TEST_TOKEN'))
     try:
         self.buckets.delete('in.c-py-test-tables', force=True)
     except exceptions.HTTPError as e:
         if e.response.status_code != 404:
             raise
     self.buckets.create(name='py-test-tables', stage='in')
     # https://github.com/boto/boto3/issues/454
     warnings.simplefilter("ignore", ResourceWarning)
Esempio n. 3
0
    def __init__(self, api_domain, token):
        """
        Initialise a client.

        Args:
            api_domain (str): The domain on which the API sits. eg.
                "https://connection.keboola.com".
            token (str): A storage API key.
        """
        self.root_url = api_domain
        self._token = token

        self.buckets = Buckets(self.root_url, self.token)
        self.files = Files(self.root_url, self.token)
        self.jobs = Jobs(self.root_url, self.token)
        self.tables = Tables(self.root_url, self.token)
        self.workspaces = Workspaces(self.root_url, self.token)
Esempio n. 4
0
    def test_download_file_sliced(self):
        buckets = Buckets(os.getenv('KBC_TEST_API_URL'),
                          os.getenv('KBC_TEST_TOKEN'))
        try:
            buckets.delete('in.c-py-test-files', force=True)
        except exceptions.HTTPError as e:
            if e.response.status_code != 404:
                raise
        buckets.create(name='py-test-files', stage='in')

        tables = Tables(os.getenv('KBC_TEST_API_URL'),
                        os.getenv('KBC_TEST_TOKEN'))
        file, path = tempfile.mkstemp(prefix='sapi-test')
        with open(path, 'w') as csv_file:
            writer = csv.DictWriter(csv_file,
                                    fieldnames=['col1', 'col2'],
                                    lineterminator='\n',
                                    delimiter=',',
                                    quotechar='"')
            writer.writeheader()
            writer.writerow({'col1': 'ping', 'col2': 'pong'})
        os.close(file)
        table_id = tables.create(name='some-table',
                                 file_path=path,
                                 bucket_id='in.c-py-test-files')
        file, path = tempfile.mkstemp(prefix='sapi-test')
        with open(path, 'w') as csv_file:
            writer = csv.DictWriter(csv_file,
                                    fieldnames=['col1', 'col2'],
                                    lineterminator='\n',
                                    delimiter=',',
                                    quotechar='"')
            writer.writeheader()
            writer.writerow({'col1': 'foo', 'col2': 'bar'})
        os.close(file)
        tables.load(table_id=table_id, file_path=path, is_incremental=True)
        file_id = tables.export(table_id=table_id)
        temp_path = tempfile.TemporaryDirectory()
        local_path = self.files.download(file_id, temp_path.name)
        with open(local_path, mode='rt') as file:
            lines = file.readlines()
        self.assertEqual(['"foo","bar"\n', '"ping","pong"\n'], sorted(lines))
Esempio n. 5
0
 def setUp(self):
     token = 'dummy_token'
     base_url = 'https://connection.keboola.com/'
     self.tables = Tables(base_url, token)