From 2111f9d23aaa42b0b183a55b7448ab1cd0aead43 Mon Sep 17 00:00:00 2001 From: Crispen Gari Date: Sat, 3 Feb 2024 08:48:02 +0200 Subject: [PATCH] testing-keys --- .github/workflows/ci.yml | 22 ++++++-- dataloom.sql | 48 ++++++++++++++++++ dataloom/keys.py | 28 +++++++--- dataloom/tests/mysql/test_connection_mysql.py | 30 +++++++++-- .../tests/mysql/test_create_tables_mysql.py | 30 +++++++++-- dataloom/tests/postgres/test_connection_pg.py | 30 +++++++++-- .../tests/postgres/test_create_table_pg.py | 35 +++++++------ hi.db | Bin 28672 -> 28672 bytes 8 files changed, 181 insertions(+), 42 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38676d9..b2bdb89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,5 @@ name: 🔥 CI + on: push: branches: @@ -15,12 +16,23 @@ jobs: postgres: image: postgres env: - # POSTGRES_USER: postgres + POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - # POSTGRES_DB: postgres + POSTGRES_DB: postgres options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 5432:5432 + mysql: + image: mysql + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: test + MYSQL_USER: root + MYSQL_PASSWORD: root + options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 5 + ports: + - 3306:3306 + strategy: fail-fast: false matrix: @@ -43,6 +55,6 @@ jobs: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - # - name: 🚀 Test with pytest - # run: | - # pytest + - name: 🚀 Test with pytest + run: | + pytest diff --git a/dataloom.sql b/dataloom.sql index 0d62656..de4218a 100644 --- a/dataloom.sql +++ b/dataloom.sql @@ -174,3 +174,51 @@ [2024-02-02 21:32:59.542566] : Dataloom[sqlite]: DROP TABLE IF EXISTS posts; [2024-02-02 21:32:59.579507] : Dataloom[sqlite]: CREATE TABLE IF NOT EXISTS `posts` (`completed` BOOLEAN, `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL, `title` VARCHAR NOT NULL); [2024-02-02 21:32:59.615510] : Dataloom[sqlite]: SELECT name FROM sqlite_master WHERE type='table'; +[2024-02-03 08:47:12.440455] : Dataloom[mysql]: DROP TABLE IF EXISTS `users`; +[2024-02-03 08:47:12.652942] : Dataloom[mysql]: DROP TABLE IF EXISTS `users`; +[2024-02-03 08:47:12.724948] : Dataloom[mysql]: DROP TABLE IF EXISTS `users`; +[2024-02-03 08:47:12.757042] : Dataloom[mysql]: CREATE TABLE IF NOT EXISTS `users` (`id` INT PRIMARY KEY AUTO_INCREMENT UNIQUE NOT NULL, `name` VARCHAR(255), `username` TEXT NOT NULL); +[2024-02-03 08:47:12.852082] : Dataloom[mysql]: DROP TABLE IF EXISTS `posts`; +[2024-02-03 08:47:12.931445] : Dataloom[mysql]: CREATE TABLE IF NOT EXISTS `posts` (`id` INT PRIMARY KEY AUTO_INCREMENT UNIQUE NOT NULL, `title` TEXT NOT NULL); +[2024-02-03 08:47:13.061266] : Dataloom[mysql]: SHOW TABLES; +[2024-02-03 08:47:13.157245] : Dataloom[mysql]: DROP TABLE IF EXISTS `users`; +[2024-02-03 08:47:13.247468] : Dataloom[mysql]: CREATE TABLE IF NOT EXISTS `users` (`id` INT PRIMARY KEY AUTO_INCREMENT UNIQUE NOT NULL, `name` VARCHAR(255) UNIQUE, `username` VARCHAR(255) NOT NULL DEFAULT 'Hello there!!'); +[2024-02-03 08:47:13.380654] : Dataloom[mysql]: DROP TABLE IF EXISTS `posts`; +[2024-02-03 08:47:13.477440] : Dataloom[mysql]: CREATE TABLE IF NOT EXISTS `posts` (`completed` BOOLEAN, `id` INT PRIMARY KEY AUTO_INCREMENT UNIQUE NOT NULL, `title` VARCHAR(255) NOT NULL); +[2024-02-03 08:47:13.671918] : Dataloom[mysql]: SHOW TABLES; +[2024-02-03 08:47:14.289208] : Dataloom[postgres]: DROP TABLE IF EXISTS "users" CASCADE; +[2024-02-03 08:47:14.464773] : Dataloom[postgres]: DROP TABLE IF EXISTS "users" CASCADE; +[2024-02-03 08:47:14.654779] : Dataloom[postgres]: DROP TABLE IF EXISTS "users" CASCADE; +[2024-02-03 08:47:14.677777] : Dataloom[postgres]: CREATE TABLE IF NOT EXISTS "users" ("id" BIGSERIAL PRIMARY KEY UNIQUE NOT NULL, "name" VARCHAR(255), "username" TEXT NOT NULL); +[2024-02-03 08:47:14.772617] : Dataloom[postgres]: DROP TABLE IF EXISTS "posts" CASCADE; +[2024-02-03 08:47:14.829570] : Dataloom[postgres]: CREATE TABLE IF NOT EXISTS "posts" ("id" BIGSERIAL PRIMARY KEY UNIQUE NOT NULL, "title" TEXT NOT NULL DEFAULT 'Hello there!!'); +[2024-02-03 08:47:14.877112] : Dataloom[postgres]: SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public'; +[2024-02-03 08:47:15.101149] : Dataloom[postgres]: DROP TABLE IF EXISTS "users" CASCADE; +[2024-02-03 08:47:15.142274] : Dataloom[postgres]: CREATE TABLE IF NOT EXISTS "users" ("id" BIGSERIAL PRIMARY KEY UNIQUE NOT NULL, "name" VARCHAR(255) UNIQUE, "username" TEXT NOT NULL DEFAULT 'Hello there!!'); +[2024-02-03 08:47:15.214973] : Dataloom[postgres]: DROP TABLE IF EXISTS "posts" CASCADE; +[2024-02-03 08:47:15.269232] : Dataloom[postgres]: CREATE TABLE IF NOT EXISTS "posts" ("completed" BOOLEAN, "id" BIGSERIAL PRIMARY KEY UNIQUE NOT NULL, "title" VARCHAR(255) NOT NULL); +[2024-02-03 08:47:15.311224] : Dataloom[postgres]: SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public'; +[2024-02-03 08:47:15.350228] : Dataloom[sqlite]: DROP TABLE IF EXISTS users; +[2024-02-03 08:47:15.377397] : Dataloom[sqlite]: DROP TABLE IF EXISTS users; +[2024-02-03 08:47:15.402399] : Dataloom[sqlite]: DROP TABLE IF EXISTS users; +[2024-02-03 08:47:15.426402] : Dataloom[sqlite]: CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL, `name` VARCHAR, `username` TEXT NOT NULL); +[2024-02-03 08:47:15.448400] : Dataloom[sqlite]: DROP TABLE IF EXISTS posts; +[2024-02-03 08:47:15.472404] : Dataloom[sqlite]: CREATE TABLE IF NOT EXISTS `posts` (`id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL, `title` TEXT NOT NULL); +[2024-02-03 08:47:15.497449] : Dataloom[sqlite]: SELECT name FROM sqlite_master WHERE type='table'; +[2024-02-03 08:47:15.530410] : Dataloom[sqlite]: DROP TABLE IF EXISTS users; +[2024-02-03 08:47:15.579169] : Dataloom[sqlite]: CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL, `name` VARCHAR UNIQUE, `username` TEXT NOT NULL DEFAULT 'Hello there!!'); +[2024-02-03 08:47:15.620252] : Dataloom[sqlite]: DROP TABLE IF EXISTS posts; +[2024-02-03 08:47:15.659279] : Dataloom[sqlite]: CREATE TABLE IF NOT EXISTS `posts` (`completed` BOOLEAN, `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL, `title` VARCHAR NOT NULL); +[2024-02-03 08:47:15.698440] : Dataloom[sqlite]: SELECT name FROM sqlite_master WHERE type='table'; +[2024-02-03 08:47:46.699281] : Dataloom[sqlite]: DROP TABLE IF EXISTS users; +[2024-02-03 08:47:46.735980] : Dataloom[sqlite]: DROP TABLE IF EXISTS users; +[2024-02-03 08:47:46.771945] : Dataloom[sqlite]: DROP TABLE IF EXISTS users; +[2024-02-03 08:47:46.802946] : Dataloom[sqlite]: CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL, `name` VARCHAR, `username` TEXT NOT NULL); +[2024-02-03 08:47:46.831551] : Dataloom[sqlite]: DROP TABLE IF EXISTS posts; +[2024-02-03 08:47:46.860834] : Dataloom[sqlite]: CREATE TABLE IF NOT EXISTS `posts` (`id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL, `title` TEXT NOT NULL); +[2024-02-03 08:47:46.887913] : Dataloom[sqlite]: SELECT name FROM sqlite_master WHERE type='table'; +[2024-02-03 08:47:46.917822] : Dataloom[sqlite]: DROP TABLE IF EXISTS users; +[2024-02-03 08:47:46.947786] : Dataloom[sqlite]: CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL, `name` VARCHAR UNIQUE, `username` TEXT NOT NULL DEFAULT 'Hello there!!'); +[2024-02-03 08:47:46.984777] : Dataloom[sqlite]: DROP TABLE IF EXISTS posts; +[2024-02-03 08:47:47.014821] : Dataloom[sqlite]: CREATE TABLE IF NOT EXISTS `posts` (`completed` BOOLEAN, `id` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL, `title` VARCHAR NOT NULL); +[2024-02-03 08:47:47.041778] : Dataloom[sqlite]: SELECT name FROM sqlite_master WHERE type='table'; diff --git a/dataloom/keys.py b/dataloom/keys.py index 75f0def..7d254ef 100644 --- a/dataloom/keys.py +++ b/dataloom/keys.py @@ -1,9 +1,23 @@ -push = False +push = True -if push: - password = database = user = "postgres" -else: - database = "postgres" - user = "postgres" - password = "root" +class PgConfig: + if push: + password = "postgres" + database = "postgres" + user = "postgres" + else: + database = "postgres" + user = "postgres" + password = "root" + + +class MySQLConfig: + if push: + password = "root" + database = "test" + user = "root" + else: + database = "hi" + user = "root" + password = "root" diff --git a/dataloom/tests/mysql/test_connection_mysql.py b/dataloom/tests/mysql/test_connection_mysql.py index db2deed..441a2da 100644 --- a/dataloom/tests/mysql/test_connection_mysql.py +++ b/dataloom/tests/mysql/test_connection_mysql.py @@ -5,9 +5,13 @@ class TestConnectionMySQL: def test_connect_with_non_existing_database(self): from dataloom import Dataloom + from dataloom.keys import MySQLConfig mysql_loom = Dataloom( - dialect="mysql", database="non-exists", password="root", user="root" + dialect="mysql", + database="non-exists", + password=MySQLConfig.password, + user=MySQLConfig.user, ) with pytest.raises(connector.errors.ProgrammingError) as exc_info: conn = mysql_loom.connect() @@ -17,9 +21,13 @@ def test_connect_with_non_existing_database(self): def test_connect_with_wrong_password(self): from dataloom import Dataloom + from dataloom.keys import MySQLConfig mysql_loom = Dataloom( - dialect="mysql", database="hi", password="user", user="root" + dialect="mysql", + database=MySQLConfig.database, + password="user", + user=MySQLConfig.user, ) with pytest.raises(connector.errors.ProgrammingError) as exc_info: conn = mysql_loom.connect() @@ -32,9 +40,13 @@ def test_connect_with_wrong_password(self): def test_connect_with_wrong_user(self): from dataloom import Dataloom + from dataloom.keys import MySQLConfig mysql_loom = Dataloom( - dialect="mysql", database="hi", password="root", user="hey" + dialect="mysql", + database=MySQLConfig.database, + password=MySQLConfig.password, + user="hey", ) with pytest.raises(connector.errors.ProgrammingError) as exc_info: conn = mysql_loom.connect() @@ -47,10 +59,14 @@ def test_connect_with_wrong_user(self): def test_connect_with_wrong_dialect(self): from dataloom import Dataloom, UnsupportedDialectException + from dataloom.keys import MySQLConfig with pytest.raises(UnsupportedDialectException) as exc_info: mysql_loom = Dataloom( - dialect="peew", database="hi", password="user", user="root" + dialect="peew", + database=MySQLConfig.database, + password="user", + user=MySQLConfig.user, ) conn = mysql_loom.connect() conn.close() @@ -62,9 +78,13 @@ def test_connect_with_wrong_dialect(self): def test_connect_correct_connection(self): from dataloom import Dataloom + from dataloom.keys import MySQLConfig mysql_loom = Dataloom( - dialect="mysql", database="hi", password="root", user="root" + dialect="mysql", + database=MySQLConfig.database, + password=MySQLConfig.password, + user=MySQLConfig.user, ) conn = mysql_loom.connect() conn.close() diff --git a/dataloom/tests/mysql/test_create_tables_mysql.py b/dataloom/tests/mysql/test_create_tables_mysql.py index 21002cf..a873842 100644 --- a/dataloom/tests/mysql/test_create_tables_mysql.py +++ b/dataloom/tests/mysql/test_create_tables_mysql.py @@ -3,9 +3,13 @@ def test_2_pk_error(self): from dataloom import Column, PrimaryKeyColumn, Dataloom, TableColumn, Model import pytest from typing import Optional + from dataloom.keys import MySQLConfig mysql_loom = Dataloom( - dialect="mysql", database="hi", password="root", user="root" + dialect="mysql", + database=MySQLConfig.database, + password=MySQLConfig.password, + user=MySQLConfig.user, ) conn = mysql_loom.connect() @@ -28,9 +32,13 @@ def test_no_pk_error(self): import pytest from dataloom import Model, Dataloom, Column, TableColumn from typing import Optional + from dataloom.keys import MySQLConfig mysql_loom = Dataloom( - dialect="mysql", database="hi", password="root", user="root" + dialect="mysql", + database=MySQLConfig.database, + password=MySQLConfig.password, + user=MySQLConfig.user, ) conn = mysql_loom.connect() @@ -47,9 +55,13 @@ class User(Model): def test_table_name(self): from dataloom import Model, Dataloom, Column, PrimaryKeyColumn, TableColumn from typing import Optional + from dataloom.keys import MySQLConfig mysql_loom = Dataloom( - dialect="mysql", database="hi", password="root", user="root" + dialect="mysql", + database=MySQLConfig.database, + password=MySQLConfig.password, + user=MySQLConfig.user, ) conn = mysql_loom.connect() @@ -70,6 +82,7 @@ class User(Model): def test_connect_sync(self): from dataloom import Dataloom, Model, TableColumn, Column, PrimaryKeyColumn from typing import Optional + from dataloom.keys import MySQLConfig class User(Model): __tablename__: Optional[TableColumn] = TableColumn(name="users") @@ -84,7 +97,10 @@ class Post(Model): title = Column(type="text", nullable=False) mysql_loom = Dataloom( - dialect="mysql", database="hi", password="root", user="root" + dialect="mysql", + database=MySQLConfig.database, + password=MySQLConfig.password, + user=MySQLConfig.user, ) conn, tables = mysql_loom.connect_and_sync([User, Post], drop=True, force=True) assert len(tables) == 2 @@ -95,9 +111,13 @@ class Post(Model): def test_syncing_tables(self): from dataloom import Model, Dataloom, Column, PrimaryKeyColumn, TableColumn from typing import Optional + from dataloom.keys import MySQLConfig mysql_loom = Dataloom( - dialect="mysql", database="hi", password="root", user="root" + dialect="mysql", + database=MySQLConfig.database, + password=MySQLConfig.password, + user=MySQLConfig.user, ) conn = mysql_loom.connect() diff --git a/dataloom/tests/postgres/test_connection_pg.py b/dataloom/tests/postgres/test_connection_pg.py index f55908e..221448b 100644 --- a/dataloom/tests/postgres/test_connection_pg.py +++ b/dataloom/tests/postgres/test_connection_pg.py @@ -4,9 +4,13 @@ class TestConnectionPG: def test_connect_with_non_existing_database(self): from dataloom import Dataloom + from dataloom.keys import PgConfig pg_loom = Dataloom( - dialect="postgres", database="mew", password="root", user="postgres" + dialect="postgres", + database="mew", + password=PgConfig.password, + user=PgConfig.user, ) with pytest.raises(Exception) as exc_info: conn = pg_loom.connect() @@ -18,9 +22,13 @@ def test_connect_with_non_existing_database(self): def test_connect_with_wrong_password(self): from dataloom import Dataloom + from dataloom.keys import PgConfig pg_loom = Dataloom( - dialect="postgres", database="hi", password="root-", user="postgres" + dialect="postgres", + database=PgConfig.database, + password="root-", + user=PgConfig.user, ) with pytest.raises(Exception) as exc_info: conn = pg_loom.connect() @@ -33,9 +41,13 @@ def test_connect_with_wrong_password(self): def test_connect_with_wrong_user(self): from dataloom import Dataloom + from dataloom.keys import PgConfig pg_loom = Dataloom( - dialect="postgres", database="hi", password="root", user="postgre-u" + dialect="postgres", + database=PgConfig.database, + password=PgConfig.password, + user="postgre-u", ) with pytest.raises(Exception) as exc_info: conn = pg_loom.connect() @@ -48,10 +60,14 @@ def test_connect_with_wrong_user(self): def test_connect_with_wrong_dialect(self): from dataloom import Dataloom, UnsupportedDialectException + from dataloom.keys import PgConfig with pytest.raises(UnsupportedDialectException) as exc_info: pg_loom = Dataloom( - dialect="peew", database="hi", password="root", user="postgres" + dialect="peew", + database=PgConfig.database, + password=PgConfig.password, + user=PgConfig.user, ) conn = pg_loom.connect() conn.close() @@ -62,9 +78,13 @@ def test_connect_with_wrong_dialect(self): def test_connect_correct_connection(self): from dataloom import Dataloom + from dataloom.keys import PgConfig pg_loom = Dataloom( - dialect="postgres", database="hi", password="root", user="postgres" + dialect="postgres", + database=PgConfig.database, + password=PgConfig.password, + user=PgConfig.user, ) conn = pg_loom.connect() conn.close() diff --git a/dataloom/tests/postgres/test_create_table_pg.py b/dataloom/tests/postgres/test_create_table_pg.py index f888b9e..5f2fd68 100644 --- a/dataloom/tests/postgres/test_create_table_pg.py +++ b/dataloom/tests/postgres/test_create_table_pg.py @@ -1,14 +1,15 @@ class TestCreatingTablePG: def test_2_pk_error(self): from dataloom import Column, PrimaryKeyColumn, Dataloom, TableColumn, Model + from dataloom.keys import PgConfig import pytest from typing import Optional pg_loom = Dataloom( dialect="postgres", - database="hi", - password="root", - user="postgres", + database=PgConfig.database, + password=PgConfig.password, + user=PgConfig.user, logging=True, ) conn = pg_loom.connect() @@ -31,14 +32,15 @@ class User(Model): def test_no_pk_error(self): import pytest + from dataloom.keys import PgConfig from dataloom import Model, Dataloom, Column, TableColumn from typing import Optional pg_loom = Dataloom( dialect="postgres", - database="hi", - password="root", - user="postgres", + database=PgConfig.database, + password=PgConfig.password, + user=PgConfig.user, logging=True, ) conn = pg_loom.connect() @@ -56,12 +58,13 @@ class User(Model): def test_table_name(self): from dataloom import Model, Dataloom, Column, PrimaryKeyColumn, TableColumn from typing import Optional + from dataloom.keys import PgConfig pg_loom = Dataloom( dialect="postgres", - database="hi", - password="root", - user="postgres", + database=PgConfig.database, + password=PgConfig.password, + user=PgConfig.user, logging=True, ) conn = pg_loom.connect() @@ -83,6 +86,7 @@ class User(Model): def test_connect_sync(self): from dataloom import Dataloom, Model, TableColumn, Column, PrimaryKeyColumn from typing import Optional + from dataloom.keys import PgConfig class User(Model): __tablename__: Optional[TableColumn] = TableColumn(name="users") @@ -98,9 +102,9 @@ class Post(Model): pg_loom = Dataloom( dialect="postgres", - database="hi", - password="root", - user="postgres", + database=PgConfig.database, + password=PgConfig.password, + user=PgConfig.user, logging=True, ) conn, tables = pg_loom.connect_and_sync([User, Post], drop=True, force=True) @@ -113,12 +117,13 @@ class Post(Model): def test_syncing_tables(self): from dataloom import Model, Dataloom, Column, PrimaryKeyColumn, TableColumn from typing import Optional + from dataloom.keys import PgConfig pg_loom = Dataloom( dialect="postgres", - database="hi", - password="root", - user="postgres", + database=PgConfig.database, + password=PgConfig.password, + user=PgConfig.user, logging=True, ) conn = pg_loom.connect() diff --git a/hi.db b/hi.db index 177c8727504c8bfdd27ca4f149716a29ac631127..31f3f041a4adafff20f2a38dc49ea682796b7a18 100644 GIT binary patch delta 245 zcmZp8z}WDBae}m<9RmXcI}pQw-9#N@NjnC;tP8w+Ga1-;r!(-m^G@ei<@?2-#dmzO zpnxRz=84>FOk9n+PVD01;*3p}lV@|MiiSA`IeRz;DTMlY28O!oC?u2?rxs2A#VyP4 zk(!f}uTYYaT9m4&sIEELoi9k7?-PR_NOOy0Nn#S40~^?OP5a3Q`NWwt-GG!P7k>Z) z2S`}c1;~||%+ANh=nP^Rf($N>hfpAmQXo~;4q(SLh62sYNiE1PE@>2Yg}9G(@?xIu J&Hwos6958hJj?(9 delta 305 zcmZp8z}WDBae}m<9s>gdI}pQw-b5W^Nj(O=tP8w+_6%&?6B+p2d1mr`;hxAR!uxWw zpnxRz=84>FOd*~r2@0NmA+GMOK?;8UAqsw>K0XRTu5PYDu71w0!3qhb#i>Qb2^tBR zDG8bi{(cHBu0F0It_seM!Oo5@t{{=n02fDuh^D6bE;DM8PJ- z8-gh|zL^XhAjeL2=L^!{muH9;7Z+!2aV$wp%1JHAFD@wt6HLxQt{}5R9G!ezHT9uJ y3Go0mnu2s|>S~(61i66xhagj$r6(`sjpqZ|lb4vAnxGKk8WA#CpC@aPKmq_4K2V