tests.test_postgres¶
Tests related to PostgresQueryBuilder
, ExamplePostgresWrapper
and PostgresWrapper
Classes
|
Shared base class for Postgres tests. |
|
A wrapper around |
|
|
|
-
class
tests.test_postgres.
BasePostgresTest
(methodName='runTest')[source]¶ Shared base class for Postgres tests.
Sets up
ExamplePostgresWrapper
into the attributewrp
Before each test (
setUp()
) it deletes and recreates the tables to avoid leftover tables/rowsAfter 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
-
classmethod
setUpClass
()[source]¶ Sets up a
ExamplePostgresWrapper
instance underwrp
for use by tests
-
wrp
= None¶ Holds a
ExamplePostgresWrapper
instance for use by test cases
-
class
tests.test_postgres.
ExamplePostgresWrapper
(*args, **kwargs)[source]¶ A wrapper around
PostgresWrapper
andTestWrapperMixin
for use in Postgres tests.Sets the default database to
privex_py_db
Creates the table
users
Includes two helper query methods
insert_user()
andfind_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 usingPostgresQueryBuilder
-
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 onPostgresQueryBuilder
-