def test_sample_data_event_issuance_fails_validation_with_null_section_desc( self): sample_data = self.get_sample_data( 'python/tests/sample_data/event_issuance.json') assert type(sample_data) is dict sample_data['evt_issuance']['counts'][0]['section_desc'] = None validate_class = Validate(Config()) assert validate_class.validate(sample_data)['isSuccess'] is False
def test_message_that_breaks_validation_rule_returns_problematic_attribute_name( self): sample_data = self.get_sample_data( 'python/tests/sample_data/vt_payment.json') sample_data['event_id'] = "1234" # string instead of integer validate_class = Validate(Config()) assert validate_class.validate(sample_data)['isSuccess'] is False assert 'event_id' in validate_class.validate( sample_data)['description']
# convert body (in bytes) to string message = body.decode(self.config.RABBITMQ_MESSAGE_ENCODE) message_dict = json.loads(message) validation_result = self.validator.validate(message_dict) if validation_result['isSuccess']: # Validation was SUCCESSFUL logging.info("write to: " + self.config.VALID_QUEUE) if self.writer.publish(self.config.VALID_QUEUE, message): ch.basic_ack(delivery_tag=method.delivery_tag) else: # Validation FAILED message_with_errors_appended = Helper.add_error_to_message( message_dict, validation_result['description']) logging.info("write to: " + self.config.FAIL_QUEUE) if self.writer.publish(self.config.FAIL_QUEUE, json.dumps(message_with_errors_appended)): ch.basic_ack(delivery_tag=method.delivery_tag) if __name__ == "__main__": Listener( Config(), Validate(Config()), RabbitMQ(Config.VALIDATOR_USER, Config.VALIDATOR_PASS, Config.RABBITMQ_URL, Config.LOG_LEVEL, Config.MAX_CONNECTION_RETRIES, Config.RETRY_DELAY), RabbitMQ(Config.VALIDATOR_USER, Config.VALIDATOR_PASS, Config.RABBITMQ_URL, Config.LOG_LEVEL, Config.MAX_CONNECTION_RETRIES, Config.RETRY_DELAY)).main()
def test_message_without_an_event_type_fails_validation(self): sample_data = self.get_sample_data( 'python/tests/sample_data/vt_payment.json') del sample_data['event_type'] validate_class = Validate(Config()) assert validate_class.validate(sample_data)['isSuccess'] is False
def test_unknown_event_type_fails_validation(self): sample_data = self.get_sample_data( 'python/tests/sample_data/vt_payment.json') sample_data['event_type'] = 'unknown_event' validate_class = Validate(Config()) assert validate_class.validate(sample_data)['isSuccess'] is False
def test_sample_data_vt_dispute_finding_passes_validation(self): sample_data = self.get_sample_data( 'python/tests/sample_data/vt_dispute_finding.json') assert type(sample_data) is dict validate_class = Validate(Config()) assert validate_class.validate(sample_data)['isSuccess'] is True
def test_sample_data_event_issuance_passes_validation(self): sample_data = self.get_sample_data( 'python/tests/sample_data/event_issuance.json') assert type(sample_data) is dict validate_class = Validate(Config()) assert validate_class.validate(sample_data)['isSuccess'] is True
def test_instantiation(self): validate_class = Validate(Config()) assert type(validate_class) is Validate
def test_a_test_message_with_bad_json_fails_validation(): sample_data = 'some string that is not json or does not decode into a dictionary' validate_class = Validate(Config()) assert validate_class.validate(sample_data)['isSuccess'] is False
def test_a_null_test_message_fails_validation(): sample_data = None validate_class = Validate(Config()) assert validate_class.validate(sample_data)['isSuccess'] is False