def test_prep_bundle_staging(self): """test getting bundle ready with a file in staging state""" data = json.loads(cart_json_helper()) file_ids = data['fileids'] Cart.database_connect() mycart = Cart(cart_uid=343, status='staging') mycart.save() cart_utils = Cartutils() cart_utils.update_cart_files(mycart, file_ids) get_files_locally(mycart.id) for cart_file in File.select().where(File.cart == mycart.id): cart_file.status = 'staging' cart_file.save() cart_utils.prepare_bundle( mycart.id) #hitting more coverage, set files to staged for cart_file in File.select().where(File.cart == mycart.id): cart_file.status = 'staged' cart_file.save() cart_utils.prepare_bundle(mycart.id) #call again after file update status = mycart.status cartid = mycart.id while status == 'staging': mycart = Cart.get(Cart.id == cartid) status = mycart.status Cart.database_close() self.assertEqual(status, 'ready')
def stage_files(file_ids, uid): """Tell the files to be staged on the backend system """ Cart.database_connect() mycart = Cart(cart_uid=uid, status="staging") mycart.save() #with update or new, need to add in files cart_utils = Cartutils() cart_utils.update_cart_files(mycart, file_ids) get_files_locally.delay(mycart.id) prepare_bundle.delay(mycart.id) Cart.database_close()
def test_stage_files(self): """test getting bundle files ready""" data = json.loads(cart_json_helper()) file_ids = data['fileids'] Cart.database_connect() mycart = Cart(cart_uid=747, status='staging') mycart.save() cart_utils = Cartutils() cart_utils.update_cart_files(mycart, file_ids) stage_files(file_ids, mycart.id) cart_utils.prepare_bundle(mycart.id) status = mycart.status cartid = mycart.id while status == 'staging': mycart = Cart.get(Cart.id == cartid) status = mycart.status Cart.database_close() self.assertEqual(status, 'ready')
def test_cart_deleted_date(self): """test getting bundle ready with a file in staging state""" data = json.loads(cart_json_helper()) file_ids = data['fileids'] Cart.database_connect() mycart = Cart(cart_uid=444, status='staging') mycart.save() cart_utils = Cartutils() cart_utils.update_cart_files(mycart, file_ids) get_files_locally(mycart.id) mycart.status = 'deleted' mycart.deleted_date = datetime.datetime.now() mycart.save() status = mycart.status for cart_file in File.select().where(File.cart == mycart.id): pull_file(cart_file.id, '/tmp/some/Path', '1111', False) Cart.database_close() self.assertEqual(status, 'deleted')
def test_prep_bundle_error(self): """test getting bundle ready with a file in error state""" data = json.loads(cart_json_helper()) file_ids = data['fileids'] Cart.database_connect() mycart = Cart(cart_uid=343, status='staging') mycart.save() cart_utils = Cartutils() cart_utils.update_cart_files(mycart, file_ids) get_files_locally(mycart.id) for cart_file in File.select().where(File.cart == mycart.id): cart_file.status = 'error' cart_file.save() cart_utils.prepare_bundle(mycart.id) status = mycart.status cartid = mycart.id while status == 'staging': mycart = Cart.get(Cart.id == cartid) status = mycart.status Cart.database_close() self.assertEqual(status, 'error')
def stage_files(file_ids, mycart_id): """Tell the files to be staged on the backend system """ Cart.database_connect() #with update or new, need to add in files mycart = Cart.get(Cart.id == mycart_id) cart_utils = Cartutils() file_id_error = cart_utils.update_cart_files(mycart, file_ids) if not file_id_error: get_files_locally.delay(mycart.id) else: mycart.status = 'error' mycart.error = 'Error parsing file Ids with error: ' + str( file_id_error) mycart.updated_date = datetime.datetime.now() mycart.save() Cart.database_close()
def test_cart_no_hash_passed(self): """test error with cart with no hash passed""" with test_database(SqliteDatabase(':memory:'), (Cart, File)): test_cart = Cart.create(cart_uid='1', status='staging', bundle_path='/tmp/1/') cart_utils = Cartutils() data = json.loads( '{"fileids": [{"id":"foo.txt", "path":"1/2/3/foo.txt", "hashtype":"md5"}]}' ) file_ids = data['fileids'] retval = cart_utils.update_cart_files(test_cart, file_ids) self.assertNotEqual(retval, None)