|
11 | 11 | BUILD_STATUS_FAILURE,
|
12 | 12 | BUILD_STATUS_SUCCESS,
|
13 | 13 | EXTERNAL,
|
| 14 | + TAG, |
14 | 15 | )
|
15 | 16 | from readthedocs.builds.models import Build
|
16 | 17 | from readthedocs.config import ALL, ConfigError
|
|
21 | 22 | from readthedocs.projects.models import EnvironmentVariable, Project, WebHookEvent
|
22 | 23 | from readthedocs.projects.tasks.builds import sync_repository_task, update_docs_task
|
23 | 24 | from readthedocs.telemetry.models import BuildData
|
| 25 | +from readthedocs.vcs_support.backends.git import Backend |
24 | 26 |
|
25 | 27 | from .mockers import BuildEnvironmentMocker
|
26 | 28 |
|
@@ -60,17 +62,19 @@ def _get_project(self):
|
60 | 62 | return fixture.get(
|
61 | 63 | Project,
|
62 | 64 | slug="project",
|
| 65 | + repo="https://github.com/readthedocs/readthedocs.org", |
63 | 66 | enable_epub_build=True,
|
64 | 67 | enable_pdf_build=True,
|
65 | 68 | )
|
66 | 69 |
|
67 |
| - def _trigger_update_docs_task(self): |
| 70 | + def _trigger_update_docs_task(self, **kwargs): |
68 | 71 | # NOTE: is it possible to replace calling this directly by `trigger_build` instead? :)
|
| 72 | + kwargs.setdefault("build_api_key", "1234") |
| 73 | + kwargs.setdefault("build_commit", self.build.commit) |
69 | 74 | return update_docs_task.delay(
|
70 | 75 | self.version.pk,
|
71 | 76 | self.build.pk,
|
72 |
| - build_api_key="1234", |
73 |
| - build_commit=self.build.commit, |
| 77 | + **kwargs, |
74 | 78 | )
|
75 | 79 |
|
76 | 80 | class TestCustomConfigFile(BuildEnvironmentBase):
|
@@ -690,6 +694,72 @@ def test_failed_build(
|
690 | 694 | assert revoke_key_request._request.method == "POST"
|
691 | 695 | assert revoke_key_request.path == "/api/v2/revoke/"
|
692 | 696 |
|
| 697 | + @mock.patch.object(Backend, "ref_exists") |
| 698 | + @mock.patch("readthedocs.doc_builder.director.load_yaml_config") |
| 699 | + def test_checkout_tag_by_name(self, load_yaml_config, ref_exists): |
| 700 | + ref_exists.return_value = False |
| 701 | + self.version.type = TAG |
| 702 | + self.version.identifier = "abc123" |
| 703 | + self.version.verbose_name = "v1.0" |
| 704 | + self.version.slug = "v1.0" |
| 705 | + self.machine = False |
| 706 | + self.version.save() |
| 707 | + load_yaml_config.return_value = get_build_config({}) |
| 708 | + |
| 709 | + self._trigger_update_docs_task(build_commit=None) |
| 710 | + |
| 711 | + self.mocker.mocks["git.Backend.run"].assert_has_calls( |
| 712 | + [ |
| 713 | + mock.call("git", "clone", "--depth", "1", mock.ANY, "."), |
| 714 | + mock.call( |
| 715 | + "git", |
| 716 | + "fetch", |
| 717 | + "origin", |
| 718 | + "--force", |
| 719 | + "--prune", |
| 720 | + "--prune-tags", |
| 721 | + "--depth", |
| 722 | + "50", |
| 723 | + "refs/tags/v1.0:refs/tags/v1.0", |
| 724 | + ), |
| 725 | + mock.call("git", "checkout", "--force", "v1.0"), |
| 726 | + mock.call("git", "clean", "-d", "-f", "-f"), |
| 727 | + ] |
| 728 | + ) |
| 729 | + |
| 730 | + @mock.patch.object(Backend, "ref_exists") |
| 731 | + @mock.patch("readthedocs.doc_builder.director.load_yaml_config") |
| 732 | + def test_checkout_external_version_by_commit(self, load_yaml_config, ref_exists): |
| 733 | + ref_exists.return_value = False |
| 734 | + self.version.type = EXTERNAL |
| 735 | + self.version.identifier = "abc123" |
| 736 | + self.version.verbose_name = "22" |
| 737 | + self.version.slug = "22" |
| 738 | + self.machine = False |
| 739 | + self.version.save() |
| 740 | + load_yaml_config.return_value = get_build_config({}) |
| 741 | + |
| 742 | + self._trigger_update_docs_task(build_commit=None) |
| 743 | + |
| 744 | + self.mocker.mocks["git.Backend.run"].assert_has_calls( |
| 745 | + [ |
| 746 | + mock.call("git", "clone", "--depth", "1", mock.ANY, "."), |
| 747 | + mock.call( |
| 748 | + "git", |
| 749 | + "fetch", |
| 750 | + "origin", |
| 751 | + "--force", |
| 752 | + "--prune", |
| 753 | + "--prune-tags", |
| 754 | + "--depth", |
| 755 | + "50", |
| 756 | + "pull/22/head:external-22", |
| 757 | + ), |
| 758 | + mock.call("git", "checkout", "--force", "abc123"), |
| 759 | + mock.call("git", "clean", "-d", "-f", "-f"), |
| 760 | + ] |
| 761 | + ) |
| 762 | + |
693 | 763 | @mock.patch("readthedocs.doc_builder.director.load_yaml_config")
|
694 | 764 | def test_build_commands_executed(
|
695 | 765 | self,
|
|
0 commit comments