Skip to content

Commit

Permalink
testing-keys
Browse files Browse the repository at this point in the history
  • Loading branch information
CrispenGari committed Feb 3, 2024
1 parent 39f0d06 commit 2111f9d
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 42 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: 🔥 CI

on:
push:
branches:
Expand All @@ -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:
Expand All @@ -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
48 changes: 48 additions & 0 deletions dataloom.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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';
28 changes: 21 additions & 7 deletions dataloom/keys.py
Original file line number Diff line number Diff line change
@@ -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"
30 changes: 25 additions & 5 deletions dataloom/tests/mysql/test_connection_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
30 changes: 25 additions & 5 deletions dataloom/tests/mysql/test_create_tables_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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()

Expand Down
30 changes: 25 additions & 5 deletions dataloom/tests/postgres/test_connection_pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Loading

0 comments on commit 2111f9d

Please sign in to comment.