예제 #1
0
 def test_make_bundle_path(self):
     url = 'https://somewhere.else/mpsycho/hello.git'
     r = Repository(url)
     treetop = '/home/maria/repos'
     self.assertEqual(
         r.make_bundle_path(treetop),
         os.path.join(treetop, 'somewhere.else/mpsycho/hello.git.bundle'))
예제 #2
0
 def test_bundle_required(self):
     source_bundle_path = tests.get_data_dir('sample-repo-branched.bundle')
     source_bundle_uri = pathlib.PurePath(source_bundle_path).as_uri()
     original_bundle_path = tests.get_data_dir('sample-repo.bundle')
     original_hash = tests.hash_file(original_bundle_path)
     with tests.TemporaryDirectory() as tmpdir:
         repo = Repository(source_bundle_uri)
         dest_bundle_path = repo.make_bundle_path(tmpdir)
         os.makedirs(os.path.dirname(dest_bundle_path))
         shutil.copyfile(original_bundle_path, dest_bundle_path)
         old_metadata = os.stat(dest_bundle_path)
         bundler = bundle_repos.Bundler(tmpdir, tmpdir)
         old_latest_commit = bundle_repos.read_git_latest_commit_from_bundle(
             dest_bundle_path, tmpdir, bundler.git_runner)
         assert old_latest_commit == KNOWN_SAMPLE_REPO_LATEST_COMMIT_HASH
         new_bundle_path = bundler.bundle(repo)
         self.assertEqual(new_bundle_path, dest_bundle_path)
         new_latest_commit = bundle_repos.read_git_latest_commit_from_bundle(
             new_bundle_path, tmpdir, bundler.git_runner)
         self.assertEqual(
             new_latest_commit,
             KNOWN_SAMPLE_REPO_BRANCHED_LATEST_COMMIT_HASH,
             "latest commit hash from sample-repo-branched is incorrect")
         new_hash = tests.hash_file(new_bundle_path)
         new_metadata = os.stat(new_bundle_path)
         self.assertNotEqual(new_metadata, old_metadata,
                             "metadata should have changed")
         self.assertNotEqual(new_hash, original_hash,
                             "hash should have changed")
예제 #3
0
 def test_good_without_dot_git_suffix(self):
     url = 'https://somewhere.else/users/mike10004/test-child-repo-1'
     r = Repository(url)
     self.assertEqual(r.url, url)
     self.assertEqual(r.get_repository_argument(), url)
     self.assertEqual(r.scheme, 'https')
     self.assertEqual(r.host, 'somewhere.else')
     self.assertEqual(r.path_prefix, 'users/mike10004')
     self.assertEqual(r.repo_name, 'test-child-repo-1')
예제 #4
0
 def test_good(self):
     url = 'https://github.com/mike10004/test-child-repo-1.git'
     r = Repository(url)
     self.assertEqual(r.url, url)
     self.assertEqual(r.get_repository_argument(), url)
     self.assertEqual(r.scheme, 'https')
     self.assertEqual(r.host, 'github.com')
     self.assertEqual(r.path_prefix, 'mike10004')
     self.assertEqual(r.repo_name, 'test-child-repo-1.git')
예제 #5
0
 def test_good_escapes(self):
     url = 'https://unscrupulous.com/Username%20With%20Spaces/good%40example.com.git'
     r = Repository(url)
     self.assertEqual(r.url, url)
     self.assertEqual(r.get_repository_argument(), url)
     self.assertEqual(r.scheme, 'https')
     self.assertEqual(r.host, 'unscrupulous.com')
     self.assertEqual(r.decoded_path_prefix(), 'Username With Spaces')
     self.assertEqual(r.decoded_repo_name(), '*****@*****.**')
예제 #6
0
 def test_good_bundle_file(self):
     filepath = '/home/josephine/Developer/bundles/my-project.bundle'
     url = pathlib.PurePath(filepath).as_uri()
     r = Repository(url)
     self.assertEqual(r.url, url)
     self.assertEqual(r.get_repository_argument(), filepath)
     self.assertEqual(r.scheme, 'file')
     self.assertEqual(r.host, '_filesystem')
     self.assertEqual(r.path_prefix, os.path.dirname(filepath).lstrip('/'))
     self.assertEqual(r.repo_name, 'my-project.bundle')
예제 #7
0
 def test_good_bundle_file_escapes(self):
     filepath = '/home/josephine/My Projects/my-project.bundle'
     url = pathlib.PurePath(filepath).as_uri()
     r = Repository(url)
     self.assertEqual(r.url, url)
     self.assertEqual(r.get_repository_argument(), filepath)
     self.assertEqual(r.scheme, 'file')
     self.assertEqual(r.host, '_filesystem')
     self.assertEqual(r.decoded_path_prefix(),
                      os.path.dirname(filepath).lstrip('/'), "path_prefix")
     self.assertEqual(r.decoded_repo_name(), 'my-project.bundle')
예제 #8
0
 def test_bad(self):
     with self.assertRaises(AssertionError):
         Repository('https://github.com:443/foo/bar.git')
     with self.assertRaises(AssertionError):
         Repository('https://github.com:58671/foo/bar.git')
     with self.assertRaises(AssertionError):
         Repository('http://github.com/foo/bar.git')
     with self.assertRaises(AssertionError):
         Repository('git+ssh://[email protected]/foo/bar.git')
     with self.assertRaises(AssertionError):
         Repository('https://github.com/bar.git')
예제 #9
0
 def test_make_bundle_path_file_uri(self):
     filepath = '/path/to/bundles/hello.git.bundle'
     url = pathlib.Path(filepath).as_uri()
     r = Repository(url)
     treetop = '/home/maria/repos'
     expected = os.path.join(treetop, bundle_repos.FILESYSTEM_DIR_BASENAME,
                             filepath.lstrip('/') + '.bundle')
     actual = r.make_bundle_path(treetop)
     self.assertEqual(
         actual, expected,
         "expected {} but actual is {}".format(expected, actual))
예제 #10
0
 def test_bundle_not_required_force(self):
     source_bundle_path = tests.get_data_dir('sample-repo.bundle')
     source_bundle_uri = pathlib.PurePath(source_bundle_path).as_uri()
     original_bundle_path = tests.get_data_dir('sample-repo.bundle')
     with tests.TemporaryDirectory() as tmpdir:
         repo = Repository(source_bundle_uri)
         dest_bundle_path = repo.make_bundle_path(tmpdir)
         os.makedirs(os.path.dirname(dest_bundle_path))
         shutil.copyfile(original_bundle_path, dest_bundle_path)
         original_metadata = os.stat(dest_bundle_path)
         config = bundle_repos.BundleConfig(ignore_rev=True)
         new_bundle_path = bundle_repos.Bundler(tmpdir,
                                                tmpdir,
                                                config=config).bundle(repo)
         self.assertEqual(new_bundle_path, dest_bundle_path)
         new_metadata = os.stat(new_bundle_path)
         self.assertNotEqual(new_metadata, original_metadata,
                             "file metadata should have changed")
예제 #11
0
 def test_bundle_one(self):
     print("\ntest_bundle_one")
     with tests.TemporaryDirectory() as tmpdir:
         bundles_dir = os.path.join(tmpdir, 'repositories')
         os.mkdir(bundles_dir)
         bundle_path = bundle_repos.Bundler(bundles_dir, tmpdir).bundle(
             Repository("https://github.com/octocat/Hello-World.git"))
         self.assertIsNotNone(bundle_path, "bundle returned None")
         self.assertBundleVerifies(bundle_path)
예제 #12
0
 def test_bundle_from_bundle_source(self):
     source_bundle_path = tests.get_data_dir('sample-repo.bundle')
     assert os.path.isfile(source_bundle_path)
     repo = Repository(pathlib.Path(source_bundle_path).as_uri())
     with tests.TemporaryDirectory() as tmpdir:
         bundler = bundle_repos.Bundler(tmpdir, tmpdir)
         bundle_path = bundler.bundle(repo)
         # not sure of an independent way to check that this bundle is correct
         self.assertIsNotNone(bundle_path, "bundle path is None")
         self.assertBundleVerifies(bundle_path)
예제 #13
0
 def test_bundle_not_required_skip(self):
     source_bundle_path = tests.get_data_dir('sample-repo.bundle')
     source_bundle_uri = pathlib.PurePath(source_bundle_path).as_uri()
     original_bundle_path = tests.get_data_dir('sample-repo.bundle')
     original_hash = tests.hash_file(original_bundle_path)
     with tests.TemporaryDirectory() as tmpdir:
         repo = Repository(source_bundle_uri)
         dest_bundle_path = repo.make_bundle_path(tmpdir)
         os.makedirs(os.path.dirname(dest_bundle_path))
         shutil.copyfile(original_bundle_path, dest_bundle_path)
         original_metadata = os.stat(dest_bundle_path)
         new_bundle_path = bundle_repos.Bundler(tmpdir, tmpdir).bundle(repo)
         self.assertEqual(new_bundle_path, dest_bundle_path)
         new_hash = tests.hash_file(new_bundle_path)
         self.assertEqual(new_hash, original_hash,
                          "hash should NOT have changed")
         new_metadata = os.stat(new_bundle_path)
         self.assertEqual(new_metadata, original_metadata,
                          "file metadata should NOT have changed")
예제 #14
0
 def test_bundle(self):
     repo = Repository("https://localhost/hsolo/falcon.git")
     with tests.TemporaryDirectory() as treetop:
         bundle_name = self.make_bundler(treetop).bundle(repo)
         print("created {}".format(bundle_name))
         expected = os.path.join(treetop, 'localhost', 'hsolo',
                                 'falcon.git.bundle')
         self.assertEqual(bundle_name, expected)
         if not os.path.isfile(bundle_name):
             print("contents of directory {}".format(treetop),
                   file=sys.stderr)
             for f in tests.list_files_recursively(treetop):
                 print("  '{}'".format(f), file=sys.stderr)
         self.assertTrue(os.path.isfile(bundle_name),
                         "expected file to exist at " + bundle_name)
예제 #15
0
 def test_bundle_fail(self):
     """Tests bundling a repository that does not exist, causing a failure"""
     print("\ntest_bundle_fail")
     repo_urls = ["file:///path/to/nowhere.bundle"]
     with tests.TemporaryDirectory() as tmpdir:
         bundles_dir = os.path.join(tmpdir, "repositories")
         os.mkdir(bundles_dir)
         num_ok = bundle_repos.Bundler(bundles_dir,
                                       tmpdir).bundle_all(repo_urls)
         self.assertEqual(0, num_ok, "num_ok")
         for url in repo_urls:
             potential_bundle_path = Repository(url).make_bundle_path(
                 bundles_dir)
             self.assertFalse(
                 os.path.exists(potential_bundle_path),
                 "file exists at {} but shouldn't".format(
                     potential_bundle_path))
예제 #16
0
 def test_decoded_path_prefix(self):
     url = 'https://somewhere.else/hello%40world/test-child-repo-1.git'
     r = Repository(url)
     self.assertEqual(r.decoded_path_prefix(), "hello@world")
예제 #17
0
 def test_bad_url_has_separator_chars(self):
     with self.assertRaises(ValueError):
         Repository('https://unconscionable.com/User%2Fname/project.git')
     with self.assertRaises(ValueError):
         Repository('https://unconscionable.com/Username/My%2FProject.git')
예제 #18
0
 def test_bad_bundle_file(self):
     filepath = '/home/josephine/Developer/bundles/my-project.bundle'
     with self.assertRaises(AssertionError):
         Repository(filepath)  # because you must make the path a URI