def test_table_auto_create(self, topic_name='biometrics_test'): ''' Tests whether a postgreSQL table is auto-created when the producer publishes a new topic. Topic name must match the regex: biometrics_(.*) Note: New tables may take some time to be created by the JDBC connector to postgres, therefore this test may fail on newly created tables. Args: topic_name (str): The name of the topic (default: 'biometrics_test') ''' produce(topic_name, Patient()) self.cursor.execute( f"SELECT EXISTS (SELECT 1 AS result FROM pg_tables WHERE schemaname = 'public' AND tablename = '{topic_name}');") table_created = self.cursor.fetchone()[0] self.assertEqual(table_created, True)
def test_topic_delivery(self, topic_name='biometrics_default'): ''' Tests if the topic is delivered succesfully to Kafka. Args: topic_name (str): The name of the topic (default: 'biometrics_test') ''' delivery_status = produce(topic_name, Patient()) self.assertEqual(delivery_status, True)
def medrical(): parser = SafeConfigParser() config_file = str(pathlib.Path( __file__).parent.parent.absolute()) + '/config/pipeline.cfg' parser.read(config_file) f''' Medrical cli tool {USAGE_STRING} ''' args = sys.argv sys.argv = [sys.argv[0]] # Clear args, not to be passed in tests if len(args[1:]) < 1: print(USAGE_STRING) elif args[1] == 'produce': print("Launcing the producer...") try: while(True): produce('biometrics_default', Patient()) time.sleep(1) # Unreliable, but works for the example's sake except KeyboardInterrupt: sys.exit(0) elif args[1] == 'test': if args[2] == 'producer': suite = unittest.TestLoader().loadTestsFromTestCase(TestProducer) unittest.TextTestRunner(verbosity=2).run(suite) elif args[2] == 'connector': suite = unittest.TestLoader().loadTestsFromTestCase(TestConnector) unittest.TextTestRunner(verbosity=2).run(suite) else: print(f'Error: Unit does not exist\n{USAGE_STRING}') elif args[1] == 'configure': if args[2] == 'ssl': ssl_configure() else: configure() else: print(USAGE_STRING)