|
6 | 6 | from unittest.mock import MagicMock, patch
|
7 | 7 |
|
8 | 8 | from allauth.socialaccount.models import SocialAccount
|
| 9 | +from django.conf import settings |
9 | 10 | from django.contrib.auth.models import User
|
10 | 11 | from django.test import TestCase
|
11 | 12 | from django_dynamic_fixture import get
|
@@ -541,3 +542,156 @@ def test_install_apt_packages(self, load_config, run):
|
541 | 542 | user='root:root',
|
542 | 543 | )
|
543 | 544 | )
|
| 545 | + |
| 546 | + @patch('readthedocs.projects.tasks.UpdateDocsTaskStep.build_docs', new=MagicMock) |
| 547 | + @patch('readthedocs.projects.tasks.UpdateDocsTaskStep.setup_vcs', new=MagicMock) |
| 548 | + @patch.object(BuildEnvironment, 'run') |
| 549 | + @patch('readthedocs.doc_builder.config.load_config') |
| 550 | + def test_build_tools(self, load_config, build_run): |
| 551 | + config = BuildConfigV2( |
| 552 | + {}, |
| 553 | + { |
| 554 | + 'version': 2, |
| 555 | + 'build': { |
| 556 | + 'os': 'ubuntu-20.04', |
| 557 | + 'tools': { |
| 558 | + 'python': '3.10', |
| 559 | + 'nodejs': '16', |
| 560 | + 'rust': '1.55', |
| 561 | + 'golang': '1.17', |
| 562 | + }, |
| 563 | + }, |
| 564 | + }, |
| 565 | + source_file='readthedocs.yml', |
| 566 | + ) |
| 567 | + config.validate() |
| 568 | + load_config.return_value = config |
| 569 | + |
| 570 | + version = self.project.versions.first() |
| 571 | + build = get( |
| 572 | + Build, |
| 573 | + project=self.project, |
| 574 | + version=version, |
| 575 | + ) |
| 576 | + with mock_api(self.repo): |
| 577 | + result = tasks.update_docs_task.delay( |
| 578 | + version.pk, |
| 579 | + build_pk=build.pk, |
| 580 | + record=False, |
| 581 | + intersphinx=False, |
| 582 | + ) |
| 583 | + self.assertTrue(result.successful()) |
| 584 | + self.assertEqual(build_run.call_count, 14) |
| 585 | + |
| 586 | + python_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['python']['3.10'] |
| 587 | + nodejs_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['nodejs']['16'] |
| 588 | + rust_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['rust']['1.55'] |
| 589 | + golang_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['golang']['1.17'] |
| 590 | + self.assertEqual( |
| 591 | + build_run.call_args_list, |
| 592 | + [ |
| 593 | + mock.call('asdf', 'install', 'python', python_version), |
| 594 | + mock.call('asdf', 'global', 'python', python_version), |
| 595 | + mock.call('asdf', 'reshim', 'python'), |
| 596 | + mock.call('python', '-mpip', 'install', '-U', 'virtualenv', 'setuptools'), |
| 597 | + mock.call('asdf', 'install', 'nodejs', nodejs_version), |
| 598 | + mock.call('asdf', 'global', 'nodejs', nodejs_version), |
| 599 | + mock.call('asdf', 'reshim', 'nodejs'), |
| 600 | + mock.call('asdf', 'install', 'rust', rust_version), |
| 601 | + mock.call('asdf', 'global', 'rust', rust_version), |
| 602 | + mock.call('asdf', 'reshim', 'rust'), |
| 603 | + mock.call('asdf', 'install', 'golang', golang_version), |
| 604 | + mock.call('asdf', 'global', 'golang', golang_version), |
| 605 | + mock.call('asdf', 'reshim', 'golang'), |
| 606 | + mock.ANY, |
| 607 | + ], |
| 608 | + ) |
| 609 | + |
| 610 | + @patch('readthedocs.projects.tasks.UpdateDocsTaskStep.build_docs', new=MagicMock) |
| 611 | + @patch('readthedocs.projects.tasks.UpdateDocsTaskStep.setup_vcs', new=MagicMock) |
| 612 | + @patch('readthedocs.doc_builder.python_environments.tarfile') |
| 613 | + @patch('readthedocs.doc_builder.python_environments.build_tools_storage') |
| 614 | + @patch.object(BuildEnvironment, 'run') |
| 615 | + @patch('readthedocs.doc_builder.config.load_config') |
| 616 | + def test_build_tools_cached(self, load_config, build_run, build_tools_storage, tarfile): |
| 617 | + config = BuildConfigV2( |
| 618 | + {}, |
| 619 | + { |
| 620 | + 'version': 2, |
| 621 | + 'build': { |
| 622 | + 'os': 'ubuntu-20.04', |
| 623 | + 'tools': { |
| 624 | + 'python': '3.10', |
| 625 | + 'nodejs': '16', |
| 626 | + 'rust': '1.55', |
| 627 | + 'golang': '1.17', |
| 628 | + }, |
| 629 | + }, |
| 630 | + }, |
| 631 | + source_file='readthedocs.yml', |
| 632 | + ) |
| 633 | + config.validate() |
| 634 | + load_config.return_value = config |
| 635 | + |
| 636 | + build_tools_storage.open.return_value = b'' |
| 637 | + build_tools_storage.exists.return_value = True |
| 638 | + tarfile.open.return_value.__enter__.return_value.extract_all.return_value = None |
| 639 | + |
| 640 | + version = self.project.versions.first() |
| 641 | + build = get( |
| 642 | + Build, |
| 643 | + project=self.project, |
| 644 | + version=version, |
| 645 | + ) |
| 646 | + with mock_api(self.repo): |
| 647 | + result = tasks.update_docs_task.delay( |
| 648 | + version.pk, |
| 649 | + build_pk=build.pk, |
| 650 | + record=False, |
| 651 | + intersphinx=False, |
| 652 | + ) |
| 653 | + self.assertTrue(result.successful()) |
| 654 | + self.assertEqual(build_run.call_count, 13) |
| 655 | + |
| 656 | + python_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['python']['3.10'] |
| 657 | + nodejs_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['nodejs']['16'] |
| 658 | + rust_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['rust']['1.55'] |
| 659 | + golang_version = settings.RTD_DOCKER_BUILD_SETTINGS['tools']['golang']['1.17'] |
| 660 | + self.assertEqual( |
| 661 | + # NOTE: casting the first argument as `list()` shows a better diff |
| 662 | + # explaining where the problem is |
| 663 | + list(build_run.call_args_list), |
| 664 | + [ |
| 665 | + mock.call( |
| 666 | + 'mv', |
| 667 | + # Use mock.ANY here because path differs when ran locally |
| 668 | + # and on CircleCI |
| 669 | + mock.ANY, |
| 670 | + f'/home/docs/.asdf/installs/python/{python_version}', |
| 671 | + ), |
| 672 | + mock.call('asdf', 'global', 'python', python_version), |
| 673 | + mock.call('asdf', 'reshim', 'python'), |
| 674 | + mock.call( |
| 675 | + 'mv', |
| 676 | + mock.ANY, |
| 677 | + f'/home/docs/.asdf/installs/nodejs/{nodejs_version}', |
| 678 | + ), |
| 679 | + mock.call('asdf', 'global', 'nodejs', nodejs_version), |
| 680 | + mock.call('asdf', 'reshim', 'nodejs'), |
| 681 | + mock.call( |
| 682 | + 'mv', |
| 683 | + mock.ANY, |
| 684 | + f'/home/docs/.asdf/installs/rust/{rust_version}', |
| 685 | + ), |
| 686 | + mock.call('asdf', 'global', 'rust', rust_version), |
| 687 | + mock.call('asdf', 'reshim', 'rust'), |
| 688 | + mock.call( |
| 689 | + 'mv', |
| 690 | + mock.ANY, |
| 691 | + f'/home/docs/.asdf/installs/golang/{golang_version}', |
| 692 | + ), |
| 693 | + mock.call('asdf', 'global', 'golang', golang_version), |
| 694 | + mock.call('asdf', 'reshim', 'golang'), |
| 695 | + mock.ANY, |
| 696 | + ], |
| 697 | + ) |
0 commit comments