Example #1
0
 def test_call__no_changes(self):
     with temporary_dir() as d:
         repo = mock.Mock(spec=Repository)
         repo.tree = mock.Mock(
             return_value=Tree(
                 {"url": "string", "sha": "tree-ish-hash", "tree": []}, None
             )
         )
         commit = CommitDir(repo)
         commit(d, "main", commit_message="msg")
     repo.create_commit.assert_not_called()
Example #2
0
 def test_call__error_creating_commit(self):
     with temporary_dir() as d:
         repo = mock.Mock(spec=Repository)
         repo.create_commit.return_value = None
         repo.tree = mock.Mock(
             return_value=Tree(
                 {"url": "string", "sha": "tree-ish-hash", "tree": []}, None
             )
         )
         with open("new", "w") as f:
             f.write("new")
         commit = CommitDir(repo)
         with self.assertRaises(GithubException):
             commit(d, "main", commit_message="msg")
Example #3
0
    def test_call(self):
        with temporary_dir() as d:
            repo = mock.Mock(spec=Repository)
            repo.owner = "SalesforceFoundation"
            repo.name = "TestRepo"
            repo.tree = mock.Mock()
            repo.tree.return_value = Tree(
                {
                    "url": "string",
                    "sha": "tree-ish-hash",
                    "tree": [
                        {
                            "type": "tree",
                            "mode": "100644",
                            "path": "dir",
                            "sha": "bogus1",
                        },
                        {
                            "type": "blob",
                            "mode": "100644",
                            "path": "file_outside_dir",
                            "sha": "bogus2",
                        },
                        {
                            "type": "blob",
                            "mode": "100644",
                            "path": "dir/deleteme",
                            "sha": "deletedfilesha",
                        },
                        {
                            "type": "blob",
                            "mode": "100644",
                            "path": "dir/unchanged",
                            "sha": hashlib.sha1(b"blob 0\0").hexdigest(),
                        },
                        {
                            "type": "blob",
                            "mode": "100644",
                            "path": "dir/modified",
                            "sha": "bogus3",
                        },
                    ],
                },
                None,
            )

            commit = CommitDir(repo)
            with open("unchanged", "w") as f:
                f.write("")
            with open("modified", "w") as f:
                f.write("modified")
            with open("new", "w") as f:
                f.write("new")
            with open(".hidden", "w") as f:
                pass
            commit(d, "main", "dir", dry_run=True)
            assert commit.new_tree_list == [
                {
                    "sha": "bogus2",
                    "mode": "100644",
                    "path": "file_outside_dir",
                    "size": None,
                    "type": "blob",
                },
                {
                    "sha": hashlib.sha1(b"blob 0\0").hexdigest(),
                    "mode": "100644",
                    "path": "dir/unchanged",
                    "size": None,
                    "type": "blob",
                },
                {
                    "sha": None,
                    "mode": "100644",
                    "path": "dir/modified",
                    "size": None,
                    "type": "blob",
                },
                {"path": "dir/new", "mode": "100644", "type": "blob", "sha": None},
            ]
            commit(d, "main", "dir", commit_message="msg")
        repo.create_commit.assert_called_once()