|
| 1 | +import csv |
| 2 | +import os |
| 3 | +import tempfile |
| 4 | +import unittest |
| 5 | +import warnings |
| 6 | + |
| 7 | +from requests import exceptions |
| 8 | +from kbcstorage.client import Client |
| 9 | + |
| 10 | + |
| 11 | +class TestFunctionalBuckets(unittest.TestCase): |
| 12 | + def setUp(self): |
| 13 | + self.client = Client(os.getenv('KBC_TEST_API_URL'), |
| 14 | + os.getenv('KBC_TEST_TOKEN')) |
| 15 | + try: |
| 16 | + self.client.buckets.delete('in.c-py-test', force=True) |
| 17 | + except exceptions.HTTPError as e: |
| 18 | + if e.response.status_code != 404: |
| 19 | + raise |
| 20 | + # https://github.com/boto/boto3/issues/454 |
| 21 | + warnings.simplefilter("ignore", ResourceWarning) |
| 22 | + |
| 23 | + def tearDown(self): |
| 24 | + try: |
| 25 | + self.client.buckets.delete('in.c-py-test', force=True) |
| 26 | + except exceptions.HTTPError as e: |
| 27 | + if e.response.status_code != 404: |
| 28 | + raise |
| 29 | + |
| 30 | + def test_client(self): |
| 31 | + bucket_id = self.client.buckets.create(name='py-test', |
| 32 | + stage='in', |
| 33 | + description='Test bucket')['id'] |
| 34 | + file, path = tempfile.mkstemp(prefix='sapi-test') |
| 35 | + with open(path, 'w') as csv_file: |
| 36 | + writer = csv.DictWriter(csv_file, fieldnames=['col1', 'col2'], |
| 37 | + lineterminator='\n', delimiter=',', |
| 38 | + quotechar='"') |
| 39 | + writer.writeheader() |
| 40 | + writer.writerow({'col1': 'ping', 'col2': 'pong'}) |
| 41 | + os.close(file) |
| 42 | + self.assertEqual(bucket_id, |
| 43 | + self.client.buckets.detail(bucket_id)['id']) |
| 44 | + table_id = self.client.tables.create(name='some-table', file_path=path, |
| 45 | + bucket_id='in.c-py-test') |
| 46 | + table_info = self.client.tables.detail(table_id) |
| 47 | + self.assertEqual(table_id, table_info['id']) |
| 48 | + self.assertEqual('in.c-py-test', table_info['bucket']['id']) |
| 49 | + self.assertTrue(len(self.client.jobs.list()) > 2) |
| 50 | + self.assertEqual(1, len(self.client.files.list(limit=1))) |
0 commit comments