async def test_packages(self): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") with unittest.mock.patch.object(obs, "_xml") as xml: xml.return_value = ET.fromstring( '<directory count="2"><entry name="package1"/>' '<entry name="package2"/></directory>') packages = await obs.packages("myproject") self.assertEqual(packages, ["package1", "package2"]) await obs.close()
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_delete(self): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") with unittest.mock.patch.object(obs, "_delete") as delete: await obs.delete("myproject", "mypackage", "myfile") delete.assert_called_once_with( "source/myproject/mypackage/myfile", params=None, ) await obs.close()
async def test_create_existent_project(self): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") with unittest.mock.patch.object(obs, "authorized", return_value=True): with unittest.mock.patch.object(obs, "exists", return_value=True): with unittest.mock.patch.object( obs, "client", new_callable=unittest.mock.AsyncMock) as client: await obs.create("myproject") client.put.assert_not_called() await obs.close()
async def test_transfer(self): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") with unittest.mock.patch.object(obs, "_transfer") as transfer: await obs.transfer("myproject", "mypackage", "myfile", "to_myproject") transfer.assert_called_once_with( "source/myproject/mypackage/myfile", "source/to_myproject/mypackage/myfile", None, None, ) await obs.close()
async def test_files_md5_revision(self): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") with unittest.mock.patch.object(obs, "_xml") as xml: xml.return_value = ET.fromstring( '<directory name="mypackage" rev="5" vrev="5" srcmd5="srcmd5">' '<entry name="file1" md5="md51" size="1024" mtime="1234567890"/>' '<entry name="file2" md5="md52" size="1024" mtime="1234567890"/>' "</directory>") files_md5, revision = await obs.files_md5_revision( "myproject", "mypackage") self.assertEqual(files_md5, [("file1", "md51"), ("file2", "md52")]) self.assertEqual(revision, "5") await obs.close()
async def test_storage(self): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") with unittest.mock.patch.object( obs, "files_md5_revision") as obs_files_md5_revision: obs_files_md5_revision.return_value = ( [("md51", "md51"), ("md52", "md52")], None, ) storage = await obsgit.Storage(obs, "project/package") self.assertEqual(storage.project, "project") self.assertEqual(storage.package, "package") self.assertEqual(storage.index, {"md51", "md52"}) await obs.close()
async def test_upload(self): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") with unittest.mock.patch.object(obs, "_upload") as upload: await obs.upload( "myproject", "mypackage", "myfile", filename_path="filename", ) upload.assert_called_once_with( "source/myproject/mypackage/myfile", filename_path="filename", data=None, params=None, ) await obs.close()
async def test_download(self): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") with unittest.mock.patch.object(obs, "_download") as download: await obs.download( "myproject", "mypackage", "myfile", filename_path="filename", params=[("rev", "latest")], ) download.assert_called_once_with( "source/myproject/mypackage/myfile", "filename", params=[("rev", "latest")], ) await obs.close()
async def test_create_enabled_package(self): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") with unittest.mock.patch.object(obs, "authorized", return_value=True): with unittest.mock.patch.object(obs, "exists", side_effect=[True, False]): with unittest.mock.patch.object( obs, "client", new_callable=unittest.mock.AsyncMock) as client: await obs.create("myproject", "mypackage") client.put.assert_called_once_with( "https://api.example.local/source/myproject/mypackage/_meta", data=('<package name="mypackage" project="myproject">' "<title/><description/></package>"), ) await obs.close()
async def test_create_enabled_project(self): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") with unittest.mock.patch.object(obs, "authorized", return_value=True): with unittest.mock.patch.object(obs, "exists", return_value=False): with unittest.mock.patch.object( obs, "client", new_callable=unittest.mock.AsyncMock) as client: await obs.create("myproject") client.put.assert_called_once_with( "https://api.example.local/source/myproject/_meta", data= ('<project name="myproject"><title/><description/>' '<person userid="user" role="maintainer"/></project>' ), ) await obs.close()
async def test_transfer(self): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") with unittest.mock.patch.object( obs, "files_md5_revision") as obs_files_md5_revision: obs_files_md5_revision.return_value = ( [("md51", "md51"), ("md52", "md52")], None, ) storage = await obsgit.Storage(obs, "project/package") with unittest.mock.patch.object(obs, "transfer") as obs_transfer: await storage.transfer("md51", "myproject", "mypackage", "myfile", obs) obs_transfer.assert_called_once_with("project", "package", "md51", "myproject", "mypackage", "myfile", obs) await obs.close()
async def test_files_md5_revision_linkinfo(self): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") with unittest.mock.patch.object(obs, "_xml") as xml: xml.side_effect = [ ET.fromstring( '<directory name="mypackage" rev="4" vrev="4" srcmd5="srcmd51">' '<linkinfo project="myproject" package="mypackage" srcmd5="srcmd51"' ' baserev="baserev1" xsrcmd5="xsrcmd51" lsrcmd5="lsrcmd51"/>' '<entry name="_link" md5="md50" size="1024" mtime="1234567890"/>' '<entry name="file1" md5="md51" size="1024" mtime="1234567890"/>' "</directory>"), ET.fromstring( '<directory name="mypackage" rev="5" vrev="5" srcmd5="srcmd52">' '<linkinfo project="myproject" package="mypackage" srcmd5="srcmd52"' ' baserev="baserev2" xsrcmd5="xsrcmd52" lsrcmd5="lsrcmd52"/>' '<entry name="file1" md5="md51" size="1024" mtime="1234567890"/>' '<entry name="file2" md5="md52" size="1024" mtime="1234567890"/>' "</directory>"), ] files_md5, revision = await obs.files_md5_revision( "myproject", "mypackage") self.assertEqual(files_md5, [("file1", "md51"), ("file2", "md52")]) self.assertEqual(revision, "xsrcmd51") await obs.close()
async def test_close(self): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") await obs.close() self.assertEqual(obs.client, None)
def test_open(self, aiohttp): obs = obsgit.AsyncOBS("https://api.example.local", "user", "secret") self.assertEqual(obs.url, "https://api.example.local") self.assertEqual(obs.username, "user") aiohttp.BasicAuth.assert_called_once_with("user", "secret") self.assertNotEqual(obs.client, None)