tests.test_postgres

Tests related to PostgresQueryBuilder, ExamplePostgresWrapper and PostgresWrapper

Classes

BasePostgresTest([methodName])

Shared base class for Postgres tests.

ExamplePostgresWrapper(*args, **kwargs)

A wrapper around PostgresWrapper and TestWrapperMixin for use in Postgres tests.

TestPostgresBuilder([methodName])

TestPostgresWrapper([methodName])

class tests.test_postgres.BasePostgresTest(methodName='runTest')[source]

Shared base class for Postgres tests.

  • Sets up ExamplePostgresWrapper into the attribute wrp

  • Before each test (setUp()) it deletes and recreates the tables to avoid leftover tables/rows

  • After each test (tearDown()) it drops all tables to ensure no leftover tables once the tests are done.

conn = None

Holds the module’s Postgres connection

setUp() → None[source]

Deletes and recreates all tables to avoid leftover tables/rows

classmethod setUpClass()[source]

Sets up a ExamplePostgresWrapper instance under wrp for use by tests

tearDown() → None[source]

Deletes all tables after each test finises to avoid leftover tables/rows

wrp = None

Holds a ExamplePostgresWrapper instance for use by test cases

class tests.test_postgres.ExamplePostgresWrapper(*args, **kwargs)[source]

A wrapper around PostgresWrapper and TestWrapperMixin for use in Postgres tests.

  • Sets the default database to privex_py_db

  • Creates the table users

  • Includes two helper query methods insert_user() and find_user()

class tests.test_postgres.TestPostgresBuilder(methodName='runTest')[source]
test_all_call()[source]

Insert two users, then verify they’re returned from an .all() call using PostgresQueryBuilder

test_generator_builder()[source]

Test obtaining PostgresBuilder results by calling next() on the builder object (like a generator)

test_group_call()[source]

Insert 5 users with 3 “John”s, then run a select+where+group_by query and confirm COUNT returns 3 johns

test_index_builder()[source]

Test obtaining PostgresBuilder results by accessing an index of the builder object

test_iterate_builder()[source]

Test obtaining PostgresBuilder results by iterating over the builder object itself with a for loop

test_query_all()[source]

Build a select all query using PostgresQueryBuilder and confirm the built query looks correct

test_query_select_col_where()[source]

Build a query selecting specific columns plus a ‘where AND’ clause using PostgresQueryBuilder and confirm the built query looks correct

test_query_select_col_where_group()[source]

Build a complex select+where+group_by query using PostgresQueryBuilder and confirm the built query looks correct

test_query_select_col_where_order()[source]

Build a query selecting specific columns, a ‘where AND’ clause, and an ‘ORDER BY’ clause using PostgresQueryBuilder and confirm the built query looks correct

test_query_where_first_name_last_name()[source]

Build a ‘where AND’ query using PostgresQueryBuilder and confirm the built query looks correct

test_where_call()[source]

Insert three users, then retrieve Dave using .where() + .fetch() call on PostgresQueryBuilder

class tests.test_postgres.TestPostgresWrapper(methodName='runTest')[source]