async def asyncSetUp(self): self.obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") with unittest.mock.patch.object(self.obs, "files_md5_revision", return_value=[(), None]): self.storage = await obsgit.Storage(self.obs, "project/package") self.git = obsgit.Git("/tmp/git") self.exporter = obsgit.Exporter(self.obs, self.git, self.storage)
async def test_packages(self): with tempfile.TemporaryDirectory() as tmp: tmp = pathlib.Path(tmp) git = obsgit.Git(tmp) for package in ("mypackage1", "mypackage2", ".git", ".obs"): (tmp / package).mkdir() self.assertEqual(git.packages(), ["mypackage1", "mypackage2"])
async def test_delete_package(self): with tempfile.TemporaryDirectory() as tmp: tmp = pathlib.Path(tmp) git = obsgit.Git(tmp) package_path = tmp / "mypackage" package_path.mkdir() self.assertTrue(package_path.exists()) await git.delete("mypackage") self.assertFalse(package_path.exists())
async def test_files_md5(self): with tempfile.TemporaryDirectory() as tmp: tmp = pathlib.Path(tmp) git = obsgit.Git(tmp) package_path = tmp / "mypackage" package_path.mkdir() for filename in ("myfile1", "myfile2"): with (package_path / filename).open("w") as f: f.write(filename) self.assertEqual( list(await git.files_md5("mypackage")), [ ("myfile1", "52a082e3940c1bda8306223103eaab28"), ("myfile2", "549d8b648caf7cce417751c0fbe15c7a"), ], )
def test_exists_and_create(self): with tempfile.TemporaryDirectory() as tmp: git = obsgit.Git(tmp) self.assertFalse(git.exists()) git.create() self.assertTrue(git.exists())