def test_validate_init_recurrent(self): data = { 'rs': '1223', 'original_init_id': 2, 'merchant_transaction_id': 1, 'amount': '1000', 'description': 'Recurrent money'} validator = Validator('init_recurrent', data) self.assertEquals(validator.execute(), data)
def main(): # parser our command line arguments args = parser.parse_args() # initialize a validator object with the command line arguments v = Validator(workbooks=args.workbook, api_url=args.api_url, api_token=args.api_token) validated_rows = v.validate_workbook_rows() v.export_validated_rows(validated_rows)
def get(self, data): """ Pass string and return filtered result """ result = Validator(data).run() if result['message'] == 'Error': return result, 400 return result, 200
def test_validate_data_init_no_state(self): data = { 'rs': '1111', 'merchant_transaction_id': '12390', 'user_ip': '127.0.0.1', 'description': 'My description', 'amount': '1000', 'currency': 'USD', 'name_on_card': 'Vasyly Pupkin', 'street': 'Main street 1', 'zip': 'LV-0000', 'city': 'Riga', 'country': 'LV', 'email': '*****@*****.**', 'phone': '111', 'card_bin': '511111', 'bin_name': 'BANK', 'bin_phone': '+371 11111111', 'merchant_site_url': 'https://example.com'} validator = Validator('init', data) expected = dict(data.items() + {'state': 'NA'}.items()) self.assertEquals(validator.execute(), expected)
def test_validate_data_init_dms(self): data = { 'rs': '888', 'merchant_transaction_id': '121212121212', 'user_ip': '127.0.0.1', 'description': 'DMS transaction', 'amount': '1000', 'currency': 'USD', 'name_on_card': 'Vasyly Pupkin', 'street': 'Main street 1', 'zip': '41212213', 'city': 'Riga', 'state': 'MyState', 'country': 'LV', 'email': '*****@*****.**', 'phone': '+371 11111111', 'card_bin': '511111', 'bin_name': 'BANK', 'bin_phone': '+371 11111111', 'merchant_site_url': 'https://test.com'} validator = Validator('init_dms', data) self.assertEquals(validator.execute(), data)
def init_recurrent(self, data): validator = Validator('init_recurrent', data) request_data = self.__build_data(validator.execute()) req = Request(self.access_data['apiUrl'], self.access_data['verifySSL']) return req.executeRequest('init_recurrent', request_data)
def charge_hold(self, data): validator = Validator('charge_hold', data) request_data = self.__build_data(validator.execute()) req = Request(self.access_data['apiUrl'], self.access_data['verifySSL']) return req.executeRequest('charge_hold', request_data)
def add(self, key, value): v = Validator() if not v.is_valid(key, value): raise ValueError("Formatting for key {} is not valid.".format(key)) self.filters[key] = value return self.filters
def test_validate_status(self): data = {'init_transaction_id': '1212321323213213'} validator = Validator('status', data) data['request_type'] = 'transaction_status' data['f_extended'] = '5' self.assertEquals(validator.execute(), data)
def test_validate_charge_raise_mandatory_error(self): data = {'init_transaction_id': 1, 'cc': '1234123412341234', 'expire': '12/13'} validator = Validator('charge', data) self.assertRaises(MissingFieldException, validator.execute)
def __init__(self, args): Validator.__init__(self, args, '/tmp/validator.html')
db_path = os.path.join(backup_dir, datetime.now().strftime('%y-%m-%d_%H-%M-%S.db')) MakeDB(db_path, f.data) if latest_backup_symlink: os.remove(latest_backup_symlink) if os.path.exists( latest_backup_symlink) else None try: os.symlink(db_path, latest_backup_symlink) except OSError: print('[WARNING] Failed to create a latest_backup_symlink!') if report_path: print('Validating...') report_md = "%s\n===\n\n" % os.path.basename(db_path) report_md += Validator().validate(db_path) try: import markdown except ImportError: print( '[WARNING] Execute `pip install markdown` to generate true HTML !!!' ) report_html = '<pre>%s</pre>' % report_md else: print('Converting report to HTML...') report_html = markdown.markdown(report_md) report_html = '<!DOCTYPE html><html><head><meta charset="utf-8"></head>' \ '<body>%s</body></html>' % report_html print('Saving report...') with open(report_path, 'w', encoding='utf-8') as f: f.write(report_html)
class Runner(object): def __init__(self, configuration, tmp_dir): super().__init__() self._conf = configuration self._tmp_dir = tmp_dir self._ks_file = None self._shell = ShellLauncher(configuration, tmp_dir) self._result_formatter = ResultFormatter(self._conf.ks_test_name, host_id=self.host_id) # test prepare function can change place of the kickstart test # so the validator will be set later self._validator = None @property def host_id(self): """Return a show string identifying the host where the test is running. This is currently simply the hostname. :return: a test runner describing string :rtype: str """ return socket.gethostname() def _prepare_test(self): log.debug("Preparing test") self._copy_image_to_tmp() try: self._ks_file = self._shell.prepare() except subprocess.CalledProcessError: self._result_formatter.report_result(result=False, msg="Test prep failed") self._shell.cleanup() return False self._validator = KickstartValidator(self._conf.ks_test_name, self._ks_file) self._validator.check_ks_substitution() if not self._validator.result: self._validator.report_result() self._shell.cleanup() return False return True def _copy_image_to_tmp(self): log.debug("Copying image to temp directory {}".format(self._tmp_dir)) shutil.copy2(self._conf.boot_image_path, self._tmp_dir) def run_test(self): log_path = os.path.join(self._tmp_dir, "kstest.log") setup_logger(log_path) try: if not self._prepare_test(): return 99 v_conf = self._create_virtual_conf(log_path) virt_manager = VirtualManager(v_conf) try: virt_manager.run() except InstallError as e: self._result_formatter.report_result(False, str(e)) return 1 ret = self._validate_all(v_conf) self._cleanup() return ret.return_code finally: close_logger() @disable_on_dry_run def _cleanup(self): self._shell.cleanup() def _create_virtual_conf(self, log_path) -> VirtualConfiguration: img_path = self._shell.prepare_updates() self._conf.updates_img_path = img_path kernel_args = self._shell.kernel_args() if self._conf.updates_img_path: kernel_args += " inst.updates={}".format( self._conf.updates_img_path) if self._conf.hung_task_timeout_secs: kernel_args += " inst.kernel.hung_task_timeout_secs={}".format( self._conf.hung_task_timeout_secs) disk_args = self._shell.prepare_disks() nics_args = self._shell.prepare_network() boot_args = self._shell.boot_args() target_boot_iso = os.path.join(self._tmp_dir, self._conf.boot_image_name) ks = [] if self._shell.inject_ks_to_initrd(): ks.append(self._ks_file) v_conf = VirtualConfiguration(target_boot_iso, ks) v_conf.kernel_args = kernel_args v_conf.test_name = self._conf.ks_test_name v_conf.temp_dir = self._tmp_dir v_conf.log_path = log_path v_conf.vnc = "vnc,listen=0.0.0.0" v_conf.boot_image = boot_args v_conf.timeout = 60 v_conf.disk_paths = disk_args v_conf.networks = nics_args v_conf.runner_args = self._shell.additional_runner_args() return v_conf @disable_on_dry_run(returns=Validator("dry-run validator")) def _validate_all(self, v_conf): validator = self._validate_logs(v_conf) if validator and not validator.result: validator.report_result() return validator ret = self._validate_result() if ret.check_ret_code(): self._result_formatter.report_result(True, "test done") return ret def _validate_logs(self, virt_configuration): validator = LogValidator(self._conf.ks_test_name) validator.check_virt_errors(virt_configuration.log_path) return validator def _validate_result(self): output = self._shell.validate() if not output.check_ret_code(): msg = "Validation failed with return code {}".format( output.return_code) self._result_formatter.report_result(False, msg) return output
def status(self, data): validator = Validator('status', data) request_data = self.__build_data(validator.execute()) req = Request(self.access_data['apiUrl'], self.access_data['verifySSL']) return req.executeRequest('status_request', request_data)
def test_validate_data_charge_recurrent(self): data = { 'init_transaction_id': '2250fcc6fd097e7b9df02aa9b95bf46baa7f8fea'} validator = Validator('charge_recurrent', data) self.assertEquals(validator.execute(), data)
def test_validate_charge_option_arg_supplied(self): data = {'init_transaction_id': 1, 'cc': '1234123412341234', 'cvv': '666', 'expire': '12/13', 'f_extended': 3} validator = Validator('charge', data) self.assertEquals(validator.execute(), data)
def test_validate_data_refund(self): data = {'init_transaction_id': '1212321323213213', 'amount_to_refund': '40'} validator = Validator('refund', data) self.assertEquals(validator.execute(), data)
def test_validate_charge_success(self): data = {'init_transaction_id': 1, 'cc': '1234123412341234', 'cvv': '987', 'expire': '12/15'} validator = Validator('charge', data) expected = dict(data.items()) self.assertEquals(validator.execute(), expected)
def __init__(self, args): Validator.__init__(self, args, '/tmp/validator.css')
def test_validate_charge_hold(self): data = {'init_transaction_id': 1} validator = Validator('charge_hold', data) self.assertEquals(validator.execute(), data)