From c534fb028e260cbea371bdea09999a3fa52f6cc8 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Mon, 17 Oct 2022 20:52:05 +0200 Subject: [PATCH] Add a small test case --- Makefile | 3 +++ lib/db.py | 5 +++-- tests/db_import_test.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 tests/db_import_test.py diff --git a/Makefile b/Makefile index b27934e..11ba711 100644 --- a/Makefile +++ b/Makefile @@ -2,3 +2,6 @@ all: isort -rc . autoflake -r --in-place --remove-unused-variables . black . + +test: + python3 -m unittest -v tests/*.py diff --git a/lib/db.py b/lib/db.py index 040737d..4150b7b 100644 --- a/lib/db.py +++ b/lib/db.py @@ -4,14 +4,15 @@ from lib.config import config class DB: - def __init__(self): + def __init__(self, section="production"): + self.config_section = section self.connect() self.create_tables() def connect(self): try: # read the connection parameters - params = config() + params = config(section=self.config_section) # connect to the PostgreSQL server self.conn = psycopg2.connect(**params) diff --git a/tests/db_import_test.py b/tests/db_import_test.py new file mode 100644 index 0000000..b52d11e --- /dev/null +++ b/tests/db_import_test.py @@ -0,0 +1,34 @@ +import unittest +import xml.etree.ElementTree as ET + +from lib.db import DB +from lib.history import History +from lib.obs import OBS +from lib.revision import Revision + + +class TestDBMethods(unittest.TestCase): + def setUp(self): + self.db = DB(section="test") + self.obs = OBS() + self.history = History(self.obs, "xz") + + def test_import(self): + test_rev = Revision(self.obs, self.history, "openSUSE:Factory", "xz") + test_rev.parse( + ET.fromstring( + """ + 37a33785d29ac57cdd5f2cbd7b0d6588 + 5.2.7 + + RBrownFactory + + 1008136 + """ + ) + ) + self.db.import_rev(test_rev) + + +if __name__ == "__main__": + unittest.main()