def test_cart_int_delete(self): """Testing the cart interface delete.""" sample_cart = Cart() sample_cart.cart_uid = 123 sample_cart.bundle_path = mkdtemp('', os.environ['VOLUME_PATH']) sample_cart.status = 'ready' sample_cart.save(force_insert=True) sample_cart.reload() req = requests.delete('{}/123'.format(self.url)) self.assertEqual(req.status_code, 200)
def test_fixit_cart(self, cart_id='40'): """Test the deletion of a cart.""" self.test_status_cart(cart_id) Cart.database_connect() break_file = Cart.get(cart_uid=cart_id).files[0] break_file.status = 'error' break_file.save() Cart.database_close() hit_exception = False try: fixit(Namespace(cartids=['40'])) # pylint: disable=broad-except except Exception: hit_exception = True # pylint: enable=broad-except self.assertFalse(hit_exception)
def test_lru_cart_delete(self): """Test that trys to delete a cart.""" test_cart = self.create_sample_cart() test_cart2 = Cart.create(cart_uid='2', status='staging', bundle_path=os.path.join( os.getenv('VOLUME_PATH'), '2/'), updated_date=1) cart_utils = Cartutils() os.makedirs(test_cart2.bundle_path, 0o777) retval = cart_utils.lru_cart_delete(test_cart) self.assertEqual(retval, True) test_c2 = Cart.get(Cart.id == test_cart2.id) self.assertEqual(test_c2.status, 'deleted') # also hit error block when nothing to delete retval = cart_utils.lru_cart_delete(test_cart) self.assertEqual(retval, False)
def test_bad_file_ids(self, mock_update): """Test a error return from a file not ready to pull.""" test_cart = self.create_sample_cart() test_file = self.create_sample_file(test_cart) mock_update.return_value = 'I am a error' file_id = test_file.id stage_files(file_id, test_cart.id) cart_after = Cart.get(Cart.id == test_cart.id) status = cart_after.status self.assertEqual(status, 'error')
def test_cart_int_get(self): """Testing the cart interface get method w/o file_wrapper.""" sample_cart = Cart() sample_cart.cart_uid = 123 sample_cart.bundle_path = mkdtemp('', os.environ['VOLUME_PATH']) sample_cart.status = 'ready' sample_cart.save(force_insert=True) req = requests.get('{}/123'.format(self.url)) self.assertEqual(req.status_code, 200)
def test_bad_pull_value(self, mock_pull): """Test a error return from a file not ready to pull.""" test_cart = self.create_sample_cart() test_file = self.create_sample_file(test_cart) mock_pull.side_effect = ValueError('Error with hash pulling file') file_id = test_file.id pull_file(file_id, os.path.join(os.getenv('VOLUME_PATH'), '1', '1.txt'), '9999999', False) cart_after = Cart.get(Cart.id == test_cart.id) status = cart_after.status self.assertEqual(status, 'error')
def test_status_cart_deleted(self): """Test a error return from a file not ready to pull.""" test_cart = Cart.create(cart_uid='1', status='staging', deleted_date='2017-05-03 00:00:00') test_file = File.create(cart=test_cart, file_name='1.txt', bundle_path=os.path.join( os.getenv('VOLUME_PATH'), '1', '1.txt')) file_id = test_file.id status_file_task(file_id) self.assertEqual(True, True)
def test_not_valid_cart(self): """Testing the cart interface get against not ready cart.""" sample_cart = Cart() sample_cart.cart_uid = 123 sample_cart.status = 'ready' sample_cart.save(force_insert=True) req = requests.get('{}/123'.format(self.url)) self.assertEqual(req.status_code, 404)
def test_bad_stage(self, mock_delete_cart): """Test the bad stage of a archive file.""" test_cart = Cart.create(cart_uid='1', status='staging') def fake_database_connect(cls_name): # pragma: no cover testing code """No error.""" return cls_name def fake_database_close(cls_name): # pragma: no cover testing code """No error.""" return cls_name pacifica.cartd.orm.CartBase.database_close = MethodType( fake_database_close, pacifica.cartd.orm.CartBase) pacifica.cartd.orm.CartBase.database_connect = MethodType( fake_database_connect, pacifica.cartd.orm.CartBase) pacifica.cartd.orm.CartBase.throw_error = False mock_delete_cart.return_value = False cart_util = Cartutils() return_val = cart_util.remove_cart(test_cart.id, lambda x, terminate: x) self.assertEqual(return_val, None)
def test_not_ready_cart(self): """Testing the cart interface get against not ready cart.""" sample_cart = Cart() sample_cart.cart_uid = 123 sample_cart.bundle_path = mkdtemp('', os.environ['VOLUME_PATH']) sample_cart.save(force_insert=True) req = requests.head('{}/123'.format(self.url)) self.assertEqual(req.status_code, 204) req = requests.get('{}/123'.format(self.url)) self.assertEqual(req.status_code, 202) self.assertEqual( req.text, 'The cart is not ready for download.', 'the right text came out.' )
def test_cart_orm_db_setup(self): """Call database_setup.""" dbsync('blah') self.assertTrue(Cart.table_exists()) self.assertTrue(File.table_exists())
def create_sample_cart(cart_uid='1', status='staging', bundle_path='1'): """Create a sample cart.""" return Cart.create(cart_uid=cart_uid, status=status, bundle_path=os.path.join(os.getenv('VOLUME_PATH'), bundle_path))