forked from importers/git-importer
Add a small test case
This commit is contained in:
parent
365696213b
commit
c534fb028e
3
Makefile
3
Makefile
@ -2,3 +2,6 @@ all:
|
|||||||
isort -rc .
|
isort -rc .
|
||||||
autoflake -r --in-place --remove-unused-variables .
|
autoflake -r --in-place --remove-unused-variables .
|
||||||
black .
|
black .
|
||||||
|
|
||||||
|
test:
|
||||||
|
python3 -m unittest -v tests/*.py
|
||||||
|
@ -4,14 +4,15 @@ from lib.config import config
|
|||||||
|
|
||||||
|
|
||||||
class DB:
|
class DB:
|
||||||
def __init__(self):
|
def __init__(self, section="production"):
|
||||||
|
self.config_section = section
|
||||||
self.connect()
|
self.connect()
|
||||||
self.create_tables()
|
self.create_tables()
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
try:
|
try:
|
||||||
# read the connection parameters
|
# read the connection parameters
|
||||||
params = config()
|
params = config(section=self.config_section)
|
||||||
# connect to the PostgreSQL server
|
# connect to the PostgreSQL server
|
||||||
self.conn = psycopg2.connect(**params)
|
self.conn = psycopg2.connect(**params)
|
||||||
|
|
||||||
|
34
tests/db_import_test.py
Normal file
34
tests/db_import_test.py
Normal file
@ -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(
|
||||||
|
"""<revision rev="70" vrev="1">
|
||||||
|
<srcmd5>37a33785d29ac57cdd5f2cbd7b0d6588</srcmd5>
|
||||||
|
<version>5.2.7</version>
|
||||||
|
<time>1665184962</time>
|
||||||
|
<user>RBrownFactory</user>
|
||||||
|
<comment></comment>
|
||||||
|
<requestid>1008136</requestid>
|
||||||
|
</revision>"""
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.db.import_rev(test_rev)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user