Exemple #1
0
 def test_run_task_latest_beta(self, commit_dir, download, get_tag):
     responses.add(
         method=responses.GET,
         url=self.repo_api_url,
         json=self._get_expected_repo(owner=self.repo_owner, name=self.repo_name),
     )
     responses.add(
         method=responses.GET,
         url=self.public_repo_url,
         json=self._get_expected_repo(
             owner=self.public_owner, name=self.public_name
         ),
     )
     task_config = TaskConfig(
         {
             "options": {
                 "branch": "master",
                 "version": "latest_beta",
                 "repo_url": self.public_repo_url,
                 "includes": ["tasks/foo.py", "unpackaged/pre/foo/package.xml"],
             }
         }
     )
     get_tag.return_value = "beta/1.0_Beta_1"
     commit_dir.return_value = None
     task = PublishSubtree(self.project_config, task_config)
     task()
     get_tag.assert_called_once_with(True)
Exemple #2
0
 def test_ref_nor_version_error(self):
     task_config = TaskConfig({
         "options": {
             "branch": "master",
             "repo_url": self.public_repo_url,
             "includes": ["tasks/foo.py", "unpackaged/pre/foo/package.xml"],
         }
     })
     with pytest.raises(TaskOptionsError) as exc:
         PublishSubtree(self.project_config, task_config)
     assert "Either `ref` or `version` option is required" == str(exc.value)
Exemple #3
0
 def test_release_not_found(self, commit_dir, extract_github):
     responses.add(
         method=responses.GET,
         url=self.repo_api_url,
         json=self._get_expected_repo(owner=self.repo_owner, name=self.repo_name),
     )
     responses.add(
         responses.GET,
         self.repo_api_url + "/releases/latest",
         json=self._get_expected_release("release/1.0"),
     )
     responses.add(
         method=responses.GET,
         url=self.public_repo_url,
         json=self._get_expected_repo(
             owner=self.public_owner, name=self.public_name
         ),
     )
     responses.add(
         method=responses.GET,
         url=self.repo_api_url + "/git/refs/tags/release/1.0",
         status=200,
         json=self._get_expected_tag_ref("release/1.0", "SHA"),
     )
     responses.add(
         method=responses.GET,
         url=self.repo_api_url + "/git/tags/SHA",
         json=self._get_expected_tag("release/1.0", "SHA"),
         status=200,
     )
     responses.add(
         responses.GET, self.repo_api_url + "/releases/tags/release/1.0", status=404
     )
     task_config = TaskConfig(
         {
             "options": {
                 "branch": "master",
                 "version": "latest",
                 "repo_url": self.public_repo_url,
                 "includes": ["tasks/foo.py", "unpackaged/pre/foo/package.xml"],
             }
         }
     )
     extract_github.return_value.namelist.return_value = [
         "tasks/foo.py",
         "unpackaged/pre/foo/package.xml",
         "force-app",
     ]
     task = PublishSubtree(self.project_config, task_config)
     with pytest.raises(GithubException) as exc:
         task()
     assert "Release for release/1.0 not found" == str(exc.value)
Exemple #4
0
 def test_renames_not_list_error(self):
     task_config = TaskConfig({
         "options": {
             "branch": "master",
             "repo_url": self.public_repo_url,
             "includes": ["tasks/foo.py", "unpackaged/pre/foo/package.xml"],
             "renames": ["tasks/foo.py", "unpackaged/pre/foo/package.xml"],
         }
     })
     with pytest.raises(TaskOptionsError) as exc:
         PublishSubtree(self.project_config, task_config)
     assert (
         "Renamed paths must be a list of dicts with `local:` and `target:` keys."
         == str(exc.value))
Exemple #5
0
    def test_run_task_ref(self, commit_dir, extract_github):
        with responses.RequestsMock() as rsps:
            rsps.add(
                method=responses.GET,
                url=self.repo_api_url,
                json=self._get_expected_repo(
                    owner=self.repo_owner, name=self.repo_name
                ),
            )
            rsps.add(
                method=responses.GET,
                url=self.public_repo_url,
                json=self._get_expected_repo(
                    owner=self.public_owner, name=self.public_name
                ),
            )
            task_config = TaskConfig(
                {
                    "options": {
                        "branch": "master",
                        "ref": "feature/publish",
                        "create_release": False,
                        "repo_url": self.public_repo_url,
                        "includes": ["tasks/foo.py", "unpackaged/pre/foo/package.xml"],
                    }
                }
            )
            extract_github.return_value.namelist.return_value = [
                "tasks/foo.py",
                "unpackaged/pre/foo/package.xml",
                "force-app",
            ]

            task = PublishSubtree(self.project_config, task_config)
            task()

            extract_github.assert_called_once()
            assert "feature/publish" == extract_github.call_args[1]["ref"]
            commit_dir.assert_called_once()
            expected_commit_message = "Published content from ref feature/publish"
            assert commit_dir.call_args[1]["commit_message"] == expected_commit_message
Exemple #6
0
    def test_run_task_version(self, commit_dir, extract_github):
        with responses.RequestsMock() as rsps:
            rsps.add(
                method=responses.GET,
                url=self.repo_api_url,
                json=self._get_expected_repo(
                    owner=self.repo_owner, name=self.repo_name
                ),
            )
            rsps.add(
                responses.GET,
                self.repo_api_url + "/releases/latest",
                json=self._get_expected_release("release/1.0"),
            )
            rsps.add(
                method=responses.GET,
                url=self.public_repo_url,
                json=self._get_expected_repo(
                    owner=self.public_owner, name=self.public_name
                ),
            )
            rsps.add(
                method=responses.GET,
                url=self.repo_api_url + "/git/refs/tags/release/1.0",
                status=200,
                json=self._get_expected_tag_ref("release/1.0", "SHA"),
            )
            rsps.add(
                method=responses.GET,
                url=self.repo_api_url + "/git/tags/SHA",
                json=self._get_expected_tag("release/1.0", "SHA"),
                status=200,
            )
            rsps.add(
                responses.GET,
                self.repo_api_url + "/releases/tags/release/1.0",
                json=self._get_expected_release("release/1.0"),
            )
            rsps.add(
                responses.GET,
                self.public_repo_url + "/git/refs/tags/release/1.0",
                status=404,
            )
            rsps.add(
                responses.POST,
                self.public_repo_url + "/releases",
                json=self._get_expected_release("release"),
            )
            task_config = TaskConfig(
                {
                    "options": {
                        "branch": "master",
                        "version": "latest",
                        "repo_url": self.public_repo_url,
                        "includes": ["tasks/foo.py", "unpackaged/pre/foo/package.xml"],
                    }
                }
            )
            extract_github.return_value.namelist.return_value = [
                "tasks/foo.py",
                "unpackaged/pre/foo/package.xml",
                "force-app",
            ]

            task = PublishSubtree(self.project_config, task_config)
            task()

            expected_release_body = json.dumps(
                {
                    "tag_name": "release/1.0",
                    "name": "1.0",
                    "body": "",
                    "draft": False,
                    "prerelease": False,
                }
            )
            create_release_call = rsps.calls[9]
            assert create_release_call.request.url == self.public_repo_url + "/releases"
            assert create_release_call.request.method == responses.POST
            assert create_release_call.request.body == expected_release_body
Exemple #7
0
    def test_path_renames_option(self):
        test_includes = [
            "scripts/anon.cls",
            "scripts/more_anon.cls",
            "tasks/unmoved.py",
            "tasks/move_me.py",
            "public/public_readme.md",
        ]
        test_renames = [
            {
                "local": "scripts",
                "target": "apex"
            },
            {
                "local": "tasks/move_me.py",
                "target": "sample_tasks/was_moved.py"
            },
            {
                "local": "public/public_readme.md",
                "target": "README.md"
            },
            {
                "local": "missing_path",
                "target": "should_not_exist"
            },
        ]
        task_config = TaskConfig({
            "options": {
                "branch": "master",
                "ref": "some-branch-name",
                "repo_url": self.public_repo_url,
                "include": test_includes,
                "renames": test_renames,
            }
        })
        task = PublishSubtree(self.project_config, task_config)
        with tempfile.TemporaryDirectory() as target:
            included_paths = [
                Path(target, local_name) for local_name in test_includes
            ]
            [
                include.parent.mkdir(parents=True, exist_ok=True)
                for include in included_paths
            ]

            assert all([
                include.write_text("12345") == 5 for include in included_paths
            ])
            assert all([include.exists() for include in included_paths])

            # Renames without a local shouldn't exist
            missing_rename = test_renames.pop()
            missing_local = Path(target, missing_rename["local"])
            assert missing_local not in included_paths

            task._rename_files(target)

            assert not Path(target, missing_rename["target"]).exists()
            unmoved_path = Path(target, "tasks/unmoved.py")
            assert unmoved_path.exists()

            # All of the paths with renames should be gone
            included_paths.remove(unmoved_path)
            assert all([not include.exists() for include in included_paths])

            # All of the renamed paths should exist
            new_paths = [
                Path(target, rename["target"]) for rename in test_renames
            ]
            assert all([rename.exists() for rename in new_paths])

            # Directory renames should work
            assert Path(target, "apex/anon.cls").exists()
            assert Path(target, "apex/more_anon.cls").exists()