Skip to content

Commit

Permalink
Merge pull request #1690 from dmach/sync-ScmsyncObsinfo-with-obs-scm-…
Browse files Browse the repository at this point in the history
…bridge

Sync ScmsyncObsinfo with obs-scm-bridge
  • Loading branch information
dmach authored Jan 7, 2025
2 parents d2ed088 + a5ef057 commit 31600b4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
9 changes: 6 additions & 3 deletions osc/obs_api/scmsync_obsinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ class ScmsyncObsinfo(BaseModel):
Class for handling _scmsync.obsinfo files
"""

# the fields are defined in obs_scm_bridge in ObsGit.write_obsinfo()
# https://github.com/openSUSE/obs-scm-bridge/blob/main/obs_scm_bridge
mtime: int = Field()
commit: str = Field()
url: str = Field()
revision: str = Field()
projectscmsync: str = Field()
url: Optional[str] = Field()
revision: Optional[str] = Field()
subdir: Optional[str] = Field()
projectscmsync: Optional[str] = Field()

@classmethod
def from_string(cls, data: str) -> "ScmsyncObsinfo":
Expand Down
39 changes: 39 additions & 0 deletions tests/test_scmsync_obsinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import unittest

from osc.obs_api.scmsync_obsinfo import ScmsyncObsinfo


class TestScmsyncObsinfo(unittest.TestCase):
def test_empty(self):
self.assertRaises(TypeError, ScmsyncObsinfo.from_string, "")

def test_mandatory(self):
data = """
mtime: 123
commit: abcdef
"""
info = ScmsyncObsinfo.from_string(data)
self.assertEqual(info.mtime, 123)
self.assertEqual(info.commit, "abcdef")
self.assertEqual(info.url, None)

def test_all(self):
data = """
mtime: 123
commit: abcdef
url: https://example.com
revision: 1
subdir: dirname
projectscmsync: project
"""
info = ScmsyncObsinfo.from_string(data)
self.assertEqual(info.mtime, 123)
self.assertEqual(info.commit, "abcdef")
self.assertEqual(info.url, "https://example.com")
self.assertEqual(info.revision, "1")
self.assertEqual(info.subdir, "dirname")
self.assertEqual(info.projectscmsync, "project")


if __name__ == "__main__":
unittest.main()

0 comments on commit 31600b4

Please sign in to comment.