Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2 from bryanchriswhite/mrosa
Browse files Browse the repository at this point in the history
add get_bucket_id tests
  • Loading branch information
marcorosa authored Mar 23, 2018
2 parents 21640ed + 526a779 commit 05dec36
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
10 changes: 0 additions & 10 deletions lib/ext/python_libstorj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@ void get_bucket_id_cb(uv_work_t *work_req, int status) {
PyDict_SetItemString(bucket_dict, "name", PyString_FromString(req->bucket_name));
PyDict_SetItemString(bucket_dict, "id", PyString_FromString(req->bucket_id));
// TODO: manage encrypted bucket name

//bucket_list = PyList_New(req->total_buckets);
//for (uint8_t i=0; i<req->total_buckets; i++) {
// PyObject *bucket_dict = PyDict_New();
// PyDict_SetItemString(bucket_dict,"name", PyString_FromString(req->buckets[i].name));
// PyDict_SetItemString(bucket_dict,"id", PyString_FromString(req->buckets[i].id));
// PyDict_SetItemString(bucket_dict,"decrypted", PyBool_FromLong((long)req->buckets[i].decrypted));
// PyDict_SetItemString(bucket_dict,"created", PyString_FromString(req->buckets[i].created));
// PyList_SetItem(bucket_list, i, bucket_dict);
//}
} else {
error = PyString_FromString(error_str);
}
Expand Down
50 changes: 50 additions & 0 deletions tests/test_storj_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,56 @@ def callback(error):
self.fail('Callback not called!')


class TestGetBucketIdSuccess(TestStorjEnv):
def setUp(self):
super(TestGetBucketIdSuccess, self).setUp()
self.bucket_name = 'python_libstorj-test3'
self.bucket = self.env.create_bucket(self.bucket_name)

def tearDown(self):
self.env.delete_bucket(self.bucket['id'])
super(TestGetBucketIdSuccess, self).tearDown()

def test_get_bucket_id_without_callback(self):
bucket = self.env.get_bucket_id(self.bucket_name)
self.assertEqual(bucket['id'], self.bucket['id'])

def test_get_bucket_id_with_callback(self):
results = {}

def callback(error, bucket):
results['error'] = error
results['bucket'] = bucket

self.env.get_bucket_id(self.bucket_name, callback)
bucket, error = [results[key] for key in ('bucket', 'error')]
self.assertEqual(error, None)
self.assertEqual(bucket['id'], self.bucket['id'])


class TestGetBucketIdFailure(TestStorjEnvBadHost):
def test_get_bucket_id_without_callback_failure(self):
bucket_name = 'python_libstorj-test2'
self.assertRaisesWithBadHost(self.env.get_bucket_id, bucket_name)

def test_get_bucket_id_with_callback_failure(self):
bucket_name = 'python_libstorj-test'
results = {}

def callback(error, bucket):
results['error'] = error
results['bucket'] = bucket

self.assertRaisesWithBadHost(self.env.get_bucket_id, bucket_name, callback)
try:
error = results['error']

self.assertBadHostError(error)
except KeyError:
self.fail('Callback not called!')



class TestListBucketsSuccess(TestStorjEnv):
def setUp(self):
super(TestListBucketsSuccess, self).setUp()
Expand Down

0 comments on commit 05dec36

Please sign in to comment.