Ejemplo n.º 1
0
    def setUp(self):
        self.dsn = 'user={} password={} dbname={} host=localhost port={}'\
            .format(self.DB_USER, self.DB_PASSWORD, self.DB_NAME, self.DB_PORT)
        try:
            self.pg_client = PostgresClient(dsn=self.dsn,
                                            pool_size=self.POOL_SIZE)
        except psycopg2.OperationalError as err:
            print('Check that postgres docker container is started. '
                  'Check README for more information')
            raise psycopg2.OperationalError(err.message)

        try:
            self._create_table()
        except (psycopg2.Error, pg_client_exc.PgClientError):
            self._drop_table()
            self._create_table()

        # Insert 100 entries
        with self.pg_client.get_cursor() as cursor:
            for _ in range(100):
                insert_str = "INSERT INTO {} (username) VALUES (%s)".format(
                    self.TABLE_NAME)
                cursor.execute(insert_str, (random.choice(NAMES), ))
Ejemplo n.º 2
0
 def test_create_with_wrong_pool_value(self):
     with self.assertRaises(ValueError) as err:
         pg_client = PostgresClient(dsn=self.dsn, pool_size=0)
         self.assertIsNone(pg_client)
         self.assertIn('Wrong pool_size value', err)