git-importer/tests/tree_test.py

41 lines
1.3 KiB
Python
Raw Normal View History

import os
import unittest
import yaml
from lib.db import DB
from lib.db_revision import DBRevision
from lib.request import Request
class TestTreeMethods(unittest.TestCase):
def setUp(self):
self.db = DB(section="test")
path = os.path.join(os.path.dirname(__file__), "fixtures/zsh-data.yaml")
with open(path, "r") as f:
zsh_data = yaml.safe_load(f)
for rev in zsh_data["revisions"]:
DBRevision.import_fixture_dict(self.db, rev)
def test_create_tree(self):
factory_revisions = DBRevision.all_revisions(self.db, "openSUSE:Factory", "zsh")
source_revisions = dict()
for rev in sorted(factory_revisions):
print(rev, rev.fileshash(self.db))
if rev.request_id:
req = Request.find(self.db, rev.request_id)
print(" ", req)
key = f"{req.source_project}/{req.source_package}"
if key not in source_revisions:
source_revisions[key] = sorted(
DBRevision.all_revisions(
self.db, req.source_project, req.source_package
)
)
for rev2 in source_revisions.get(key):
print(rev2, rev2.fileshash(self.db))
if __name__ == "__main__":
unittest.main()