def test_100_storage_repodata(self): # a simple test to check that repodata is available. util.extract_archive(self.testdir) repodata = DummyItem(join(self.testdir, 'repodata')) storage = GitStorage(repodata) pathinfo = storage.pathinfo('1') self.assertEqual(pathinfo, { 'basename': '1', 'date': '', 'size': 0, 'type': 'folder', }) pathinfo = storage.pathinfo('1/f1') self.assertEqual(pathinfo, { 'date': '2013-07-22 16:40:20', 'basename': 'f1', 'type': 'file', 'size': 5 }) storage.datefmt = 'rfc3339.local' pathinfo = storage.pathinfo('1/f1') self.assertEqual(pathinfo, { 'date': '2013-07-22T16:40:20+1200', 'basename': 'f1', 'type': 'file', 'size': 5 })
def test_sync_conflict(self): util.extract_archive(self.testdir) simple1_path = join(self.testdir, 'simple1') simple3_path = join(self.testdir, 'simple3') results = self.backend._sync_identifier(simple3_path, simple1_path) self.assertEqual(results, [ ('refs/heads/master', (False, 'Branch will diverge.')), ])
def test_900_storage_branches(self): # a simple test to check that repodata is available. util.extract_archive(self.testdir) repodata = DummyItem(join(self.testdir, 'repodata')) storage = GitStorage(repodata) branches = storage.branches() self.assertEqual(branches, ( ('master', 'eab05fccc349fbeb57ade09a197ddc72cd9e4388'), ))
def test_sync_with_older_version(self): util.extract_archive(self.testdir) simple1_path = join(self.testdir, 'simple1') simple2_path = join(self.testdir, 'simple2') # simple2 acts as an older version of simple1 DummyItem(simple1_path) results = self.backend._sync_identifier(simple1_path, simple2_path) self.assertEqual(results, [ ('refs/heads/master', (True, 'No new changes found.')), ])
def test_sync_off_new(self): # trying to sync with a new repo should not fail. new_path = join(self.testdir, 'new') item = DummyItem(new_path) self.backend.install(item) util.extract_archive(self.testdir) simple1_path = join(self.testdir, 'simple1') self.backend._sync_identifier(simple1_path, new_path) new_storage = self.backend.acquire(item) self.assertEqual(new_storage.files(), [])
def test_sync_to_new(self): new_path = join(self.testdir, 'new') item = DummyItem(new_path) self.backend.install(item) util.extract_archive(self.testdir) simple1_path = join(self.testdir, 'simple1') self.backend._sync_identifier(new_path, simple1_path) new_storage = self.backend.acquire(item) self.assertEqual(new_storage.files(), [ 'README', 'test1', 'test2', 'test3'])
def test_901_storage_tags(self): # a simple test to check that repodata is available. util.extract_archive(self.testdir) repodata = DummyItem(join(self.testdir, 'repodata')) storage = GitStorage(repodata) storage.repo.create_tag( 'dummy', util.ARCHIVE_REVS[1], GIT_OBJ_COMMIT, Signature('User', '*****@*****.**', 0, 0), 'dummy tag', ) branches = storage.tags() self.assertEqual(branches, ( ('dummy', '5c3f6bbf4aaf429ea5cb0850eae5697551397f7d'), ))
def test_sync_to_new_over_http(self): new_path = join(self.testdir, 'new') item = DummyItem(new_path) self.backend.install(item) util.extract_archive(self.testdir) simple1_path = join(self.testdir, 'simple1') self._httpd = HTTPGitServer(("localhost", 0), simple1_path) self.addCleanup(self._httpd.shutdown) threading.Thread(target=self._httpd.serve_forever).start() self.backend._sync_identifier(new_path, self._httpd.get_url()) new_storage = self.backend.acquire(item) self.assertEqual(new_storage.files(), [ 'README', 'test1', 'test2', 'test3'])
def test_sync_http_identifier(self): util.extract_archive(self.testdir) simple1_path = join(self.testdir, 'simple1') simple2_path = join(self.testdir, 'simple2') simple2 = DummyItem(simple2_path) storage2 = self.backend.acquire(simple2) self.assertEqual(storage2.files(), ['test1', 'test2', 'test3']) self._httpd = HTTPGitServer(("localhost", 0), simple1_path) self.addCleanup(self._httpd.shutdown) threading.Thread(target=self._httpd.serve_forever).start() self.backend._sync_identifier(simple2_path, self._httpd.get_url()) storage2 = self.backend.acquire(simple2) self.assertEqual(storage2.files(), [ 'README', 'test1', 'test2', 'test3'])
def test_sync_identifier(self): util.extract_archive(self.testdir) simple1_path = join(self.testdir, 'simple1') simple2_path = join(self.testdir, 'simple2') simple1 = DummyItem(simple1_path) simple2 = DummyItem(simple2_path) storage1 = self.backend.acquire(simple1) storage2 = self.backend.acquire(simple2) self.assertEqual(storage1.files(), [ 'README', 'test1', 'test2', 'test3']) self.assertEqual(storage2.files(), [ 'test1', 'test2', 'test3']) self.backend._sync_identifier(simple2_path, simple1_path) storage2 = self.backend.acquire(simple2) self.assertEqual(storage2.files(), [ 'README', 'test1', 'test2', 'test3'])
def test_110_storage_subrepo_alt_revision(self): # a simple test to check that repodata is available. util.extract_archive(self.testdir) repodata = DummyItem(join(self.testdir, 'repodata')) storage = GitStorage(repodata) # checkout a specific rev storage.checkout(util.ARCHIVE_REVS[1]) pathinfo = storage.pathinfo('ext/import1') self.assertEqual(pathinfo, { 'basename': 'import1', 'date': '', 'size': 0, 'type': 'subrepo', 'obj': { '': '_subrepo', 'location': 'http://models.example.com/w/import1', 'path': '', 'rev': '00cf337ef94f882f2585684c1c5c601285312f85', }, })
def test_sync_failures(self): util.extract_archive(self.testdir) target = join(self.testdir, 'simple2') with self.assertRaises(ValueError) as e: self.backend._sync_identifier( target, 'git://localhost/baduri') self.assertTrue( e.exception.args[0].endswith('git://localhost/baduri')) with self.assertRaises(ValueError) as e: self.backend._sync_identifier( target, 'http://localhost:10/baduri') self.assertTrue( e.exception.args[0].endswith('http://localhost:10/baduri')) with self.assertRaises(ValueError) as e: self.backend._sync_identifier( target, 'badproto://remote') self.assertEqual( e.exception.args[0], 'remote not supported: badproto://remote')
def test_sync_more_branch(self): util.extract_archive(self.testdir) simple1_path = join(self.testdir, 'simple1') simple4_path = join(self.testdir, 'simple4') simple1 = DummyItem(simple1_path) storage1 = self.backend.acquire(simple1) # Local path, not really representative. # self.backend._sync_identifier(simple1_path, simple4_path) # Something is broken with the following code at the dulwich # level... probably something simple http left out. # self._httpd = HTTPGitServer(("localhost", 0), simple4_path) # self.addCleanup(self._httpd.shutdown) # threading.Thread(target=self._httpd.serve_forever).start() # self.backend._sync_identifier(simple1_path, self._httpd.get_url()) dulwich_repo = Repo(simple4_path) dulwich_backend = DictBackend({b'/': dulwich_repo}) dulwich_server = TCPGitServer(dulwich_backend, b'localhost', 0) self.addCleanup(dulwich_server.shutdown) self.addCleanup(dulwich_server.server_close) threading.Thread(target=dulwich_server.serve).start() _, port = dulwich_server.socket.getsockname() self.backend._sync_identifier( simple1_path, 'git://localhost:%d' % port) storage1 = self.backend.acquire(simple1) self.assertEqual(storage1.files(), [ 'README', 'test1', 'test2', 'test3']) storage1.checkout('refs/heads/test4') self.assertEqual(storage1.files(), [ 'test1', 'test2', 'test3', 'test4'])
def test_sync_git_server(self): util.extract_archive(self.testdir) simple1_path = join(self.testdir, 'simple1') simple2_path = join(self.testdir, 'simple2') simple2 = DummyItem(simple2_path) dulwich_repo = Repo(simple1_path) dulwich_backend = DictBackend({b'/': dulwich_repo}) dulwich_server = TCPGitServer(dulwich_backend, b'localhost', 0) self.addCleanup(dulwich_server.shutdown) self.addCleanup(dulwich_server.server_close) threading.Thread(target=dulwich_server.serve).start() _, port = dulwich_server.socket.getsockname() self.backend._sync_identifier( simple2_path, 'git://localhost:%d' % port) storage2 = self.backend.acquire(simple2) self.assertEqual(storage2.files(), [ 'README', 'test1', 'test2', 'test3']) with self.assertRaises(ValueError): self.backend._sync_identifier( simple2_path, 'git://localhost/baduri')
def test_110_storage_subrepo_default(self): # a simple test to check that repodata is available. util.extract_archive(self.testdir) repodata = DummyItem(join(self.testdir, 'repodata')) storage = GitStorage(repodata) pathinfo = storage.pathinfo('ext/import1') self.assertEqual(pathinfo, { 'basename': 'import1', 'date': '', 'size': 0, 'type': 'subrepo', 'obj': { '': '_subrepo', 'location': 'http://models.example.com/w/import1', 'path': '', 'rev': '466b6256bd9a1588256558a8e644f04b13bc04f3', }, }) with self.assertRaises(PathNotFileError): storage.file('ext/import1') with self.assertRaises(PathNotDirError): storage.listdir('ext/import1')