def test_sample_data_vt_dispute_status_update_passes_validation(self): sample_data = self.get_sample_data( 'python/common/tests/sample_data/etk/vt_dispute_status_update.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_fails_validation_with_null_section_desc( self): sample_data = self.get_sample_data( 'python/tests/sample_data/etk/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_sample_data_event_issuance_passes_validation_with_empty_section_desc( self): sample_data = self.get_sample_data( 'python/common/tests/sample_data/etk/event_issuance.json') assert type(sample_data) is dict sample_data['evt_issuance']['counts'][0]['section_desc'] = '' validate_class = Validate(Config()) assert validate_class.validate(sample_data)['isSuccess'] is True
def test_message_that_breaks_validation_rule_returns_problematic_attribute_name( self): sample_data = self.get_sample_data( 'python/tests/sample_data/etk/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']
:return: """ self.listener.consume(self.config.WATCH_QUEUE, self.callback) def callback(self, ch, method, properties, body): logging.info('message received; callback invoked') message_dict = decode_message(body, self.config.ENCRYPT_KEY) result = self.validator.validate(message_dict) logging.info("write to: " + result['queue']) if result['isSuccess']: # Validation SUCCESSFUL if self.writer.publish( result['queue'], encode_message(message_dict, self.config.ENCRYPT_KEY)): ch.basic_ack(delivery_tag=method.delivery_tag) else: # Validation FAILED message_with_errors = add_error_to_message(message_dict, result) if self.writer.publish( result['queue'], encode_message(message_with_errors, self.config.ENCRYPT_KEY)): ch.basic_ack(delivery_tag=method.delivery_tag) if __name__ == "__main__": Listener(Config(), Validate(Config()), RabbitMQ(Config()), RabbitMQ(Config())).main()
def test_message_without_an_event_type_fails_validation(self): sample_data = self.get_sample_data( 'python/tests/sample_data/etk/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/etk/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_event_issuance_passes_validation(self): sample_data = self.get_sample_data( 'python/tests/sample_data/etk/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