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_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_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)