From 298d8cb9c2df0287c5a5e820e0ddf469d67b8cad Mon Sep 17 00:00:00 2001 From: quimnuss Date: Sun, 8 Jan 2023 23:14:31 +0100 Subject: [PATCH] use database creation database --- config/test_db_config.txt | 0 federation/database.py | 12 ++++++------ requirements-dev.txt | 10 ++++++++++ tests/__init__.py | 1 + tests/test_database.py | 8 ++++++++ 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 config/test_db_config.txt create mode 100644 requirements-dev.txt create mode 100644 tests/__init__.py diff --git a/config/test_db_config.txt b/config/test_db_config.txt new file mode 100644 index 0000000..e69de29 diff --git a/federation/database.py b/federation/database.py index 1f9863e..e18aca9 100644 --- a/federation/database.py +++ b/federation/database.py @@ -16,10 +16,10 @@ class Database(): def __init__(self, config_file=None, fediverse_db=None, fediverse_db_user=None, fediverse_db_user_password=None): - self.config_file = "config/db_config.txt" - self.fediverse_db = self.__get_parameter("fediverse_db", self.config_file) - self.fediverse_db_user = self.__get_parameter("fediverse_db_user", self.config_file) - self.fediverse_db_user_password = self.__get_parameter("fediverse_db_user_password", self.config_file) + self.config_file = config_file or "config/db_config.txt" + self.fediverse_db = fediverse_db or self.__get_parameter("fediverse_db", self.config_file) + self.fediverse_db_user = fediverse_db_user or self.__get_parameter("fediverse_db_user", self.config_file) + self.fediverse_db_user_password = fediverse_db_user_password or self.__get_parameter("fediverse_db_user_password", self.config_file) db_setup = self.__check_dbsetup(self) @@ -29,7 +29,7 @@ class Database(): self.fediverse_db_user = input("\nFediverse database user: ") self.fediverse_db_user_password = input("\nFediverse database user password: ") - self.__createdb(self) + self.__createdb(self) self.__create_config(self) self.__write_config(self) @@ -844,7 +844,7 @@ class Database(): conn.close() def get_uptime(self): - + try: conn = None diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..06b4971 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,10 @@ +requests +psycopg2-binary +pytz +ray +Mastodon.py +matplotlib +pandas +humanfriendly +pytest +ipdb \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e5a0d9b --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +#!/usr/bin/env python3 diff --git a/tests/test_database.py b/tests/test_database.py index e69de29..9eb8288 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -0,0 +1,8 @@ +from federation import Database + +def test__database_connection(): + db = Database(config_file='config/test_db_config.txt') + + checked_server = db.get_last_checked_servers() + + assert checked_server \ No newline at end of file