git-importer/tests/db_import_test.py

42 lines
1.2 KiB
Python
Raw Normal View History

2022-10-17 20:52:05 +02:00
import unittest
import xml.etree.ElementTree as ET
from lib.db import DB
2022-10-18 13:13:52 +02:00
from lib.db_revision import DBRevision
2022-10-17 20:52:05 +02:00
from lib.obs import OBS
2022-10-18 12:17:43 +02:00
from lib.obs_revision import OBSRevision
2022-10-17 20:52:05 +02:00
# needs to exist in local oscrc (little tricky)
API_URL = "https://api.opensuse.org"
2022-10-17 20:52:05 +02:00
class TestDBMethods(unittest.TestCase):
def setUp(self):
self.db = DB(section="test")
self.obs = OBS(API_URL)
2022-10-17 20:52:05 +02:00
def test_import(self):
2022-11-01 11:34:10 +01:00
test_rev = OBSRevision(self.obs, "openSUSE:Factory", "xz")
2022-10-17 20:52:05 +02:00
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>"""
)
)
2022-10-18 13:13:52 +02:00
DBRevision.import_obs_rev(self.db, test_rev)
2022-10-18 17:57:49 +02:00
db_rev = DBRevision.fetch_revision(
self.db, project="openSUSE:Factory", package="xz", rev="70"
)
self.assertEqual(db_rev.api_url, API_URL)
2022-10-18 17:57:49 +02:00
self.assertEqual(str(test_rev), str(db_rev))
2022-10-17 20:52:05 +02:00
if __name__ == "__main__":
unittest.main()