Skip to content

Commit

Permalink
Remove parameterized and use global database variable instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryp Toon committed Feb 5, 2024
1 parent 78a5599 commit b930fe1
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 78 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ coveralls>=3.0.1
psycopg2>=2.9.2
mysql-connector-python>=8.0.27
mysqlclient>=2.1.0
parameterized>=0.8.1
sphinx_rtd_theme>=1.0.0
Cython>=3.0.0
win-unicode-console;platform_system=="Windows"
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ dev =
psycopg2 >= 2.9.2
mysql-connector-python >= 8.0.27
mysqlclient >= 2.1.0
parameterized >= 0.8.1
sphinx_rtd_theme >= 1.0.0
Cython>=3.0.0
win-unicode-console;platform_system=="Windows"
Expand Down
1 change: 0 additions & 1 deletion tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import logging
try:
import mysql.connector
from parameterized import parameterized_class
import psycopg2
from psycopg2 import sql
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
Expand Down
76 changes: 1 addition & 75 deletions tests/test_wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# BitcoinLib - Python Cryptocurrency Library
# Unit Tests for Wallet Class
# © 2016 - 2023 May - 1200 Web Development <http://1200wd.com/>
# © 2016 - 2024 February - 1200 Web Development <http://1200wd.com/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -23,7 +23,6 @@

try:
import mysql.connector
from parameterized import parameterized_class
import psycopg2
from psycopg2 import sql
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
Expand All @@ -43,8 +42,6 @@
DATABASEFILE_UNITTESTS_2 = os.path.join(str(BCL_DATABASE_DIR), 'bitcoinlib.unittest2.sqlite')
DATABASE_NAME = 'bitcoinlib_test'
DATABASE_NAME_2 = 'bitcoinlib2_test'
# SQLITE_DATABASE_FILE = os.path.join(str(BCL_DATABASE_DIR), '%s.sqlite' % DATABASE_NAME)
# SQLITE_DATABASE_FILE2 = os.path.join(str(BCL_DATABASE_DIR), '%s.sqlite' % DATABASE_NAME_2)

db_uris = (
('sqlite', 'sqlite:///' + DATABASEFILE_UNITTESTS, 'sqlite:///' + DATABASEFILE_UNITTESTS_2),)
Expand All @@ -65,77 +62,6 @@
))


# class TestWalletMixin:
# SCHEMA = None
#
# @classmethod
# def create_db_if_needed(cls, db):
# if cls.SCHEMA == 'postgresql':
# con = psycopg2.connect(user='postgres', host='localhost', password='postgres')
# con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
# cur = con.cursor()
# try:
# cur.execute(sql.SQL("CREATE DATABASE {}").format(
# sql.Identifier(db))
# )
# except Exception:
# pass
# finally:
# cur.close()
# con.close()
# elif cls.SCHEMA == 'mysql':
# con = mysql.connector.connect(user='root', host='localhost')
# cur = con.cursor()
# cur.execute('CREATE DATABASE IF NOT EXISTS {}'.format(db))
# con.commit()
# cur.close()
# con.close()
#
# @classmethod
# def db_remove(cls):
# close_all_sessions()
# if cls.SCHEMA == 'sqlite':
# for db in [DATABASEFILE_UNITTESTS, DATABASEFILE_UNITTESTS_2]:
# if os.path.isfile(db):
# try:
# os.remove(db)
# except PermissionError:
# db_obj = Db(db)
# db_obj.drop_db(True)
# db_obj.session.close()
# db_obj.engine.dispose()
# elif cls.SCHEMA == 'postgresql':
# for db in [DATABASE_NAME, DATABASE_NAME_2]:
# cls.create_db_if_needed(db)
# con = psycopg2.connect(user='postgres', host='localhost', password='postgres', database=db)
# con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
# cur = con.cursor()
# try:
# # drop all tables
# cur.execute(sql.SQL("""
# DO $$ DECLARE
# r RECORD;
# BEGIN
# FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP
# EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE';
# END LOOP;
# END $$;"""))
# finally:
# cur.close()
# con.close()
# elif cls.SCHEMA == 'mysql':
# for db in [DATABASE_NAME, DATABASE_NAME_2]:
# cls.create_db_if_needed(db)
# con = mysql.connector.connect(user='root', host='localhost', database=db, autocommit=True)
# cur = con.cursor(buffered=True)
# try:
# cur.execute("DROP DATABASE {};".format(db))
# cur.execute("CREATE DATABASE {};".format(db))
# finally:
# cur.close()
# con.close()


def database_init(dbname=DATABASE_NAME):
close_all_sessions()
if os.getenv('UNITTEST_DATABASE') == 'postgresql':
Expand Down

0 comments on commit b930fe1

Please sign in to comment.