Beispiel #1
0
    def test_build_release(self):
        # GIVEN
        version_file_path = commonhelper.given_python_version_file_exists()
        package_file_path = commonhelper.given_project_package_json_exists(
            "frontend")
        versioned_file_path = commonhelper.given_project_python_versioned_file_exists(
            "platform")
        repo_instance = self.mock_git_repo.return_value
        repo_instance.untracked_files = []
        repo_instance.is_dirty = mock.MagicMock(
            side_effect=[False, False, True, True])
        latest_tag = repo_instance.tags[-1]
        latest_tag.commit = mock.MagicMock('git.commit.Commit')
        diff1 = mock.MagicMock('git.diff.Diff')
        diff1.b_rawpath = versioned_file_path.encode('utf-8')
        latest_tag.commit.diff = mock.MagicMock(side_effect=[[diff1], []])

        # WHEN
        main(["main.py", "--init", "build-release", "1.2.3"])

        # THEN
        self.assertEqual(self.mock_git_repo.return_value.create_tag.call_count,
                         2)
        self.assertEqual(self.mock_git_repo.return_value.git.commit.call_count,
                         2)
        commonhelper.verify_versioned_file_updated(self, version_file_path,
                                                   "1.2.3")
        commonhelper.verify_versioned_file_updated(self, package_file_path,
                                                   "1.2.3")
        commonhelper.verify_versioned_file_updated(self, versioned_file_path,
                                                   "1.2.3")
Beispiel #2
0
    def test_update(self):
        # WHEN
        main(["main.py", "--init", "update"])

        # THEN
        self.mock_subprocess_call.assert_called_once_with(
            ["pip", "install", "--upgrade", "heliumcli"])
Beispiel #3
0
def given_config_exists(project_id="test",
                        name="Test",
                        host="test.heliumedu.com",
                        github_user="******"):
    main([
        "main.py", "init", "--config-only", project_id, name, host, github_user
    ])
Beispiel #4
0
    def test_init(self):
        # GIVEN
        self.assertFalse(os.path.exists(os.environ.get("HELIUMCLI_CONFIG_PATH")))

        # WHEN
        main(["main.py", "init", "my-project", "My Project", "myproject.heliumedu.com", "HeliumEdu"])

        # THEN
        self.assertTrue(os.path.exists(os.environ.get("HELIUMCLI_CONFIG_PATH")))
Beispiel #5
0
    def test_start_servers(self):
        # GIVEN
        commonhelper.given_runserver_exists("platform")

        # WHEN
        main(["main.py", "--init", "start-servers"])

        # THEN
        self.mock_subprocess_popen.assert_called_once_with(
            os.path.join(utils.get_projects_dir(), "platform",
                         utils.get_config(True)["serverBinFilename"]))
Beispiel #6
0
    def test_build_release_fails_when_dirty(self):
        # GIVEN
        repo_instance = self.mock_git_repo.return_value
        repo_instance.is_dirty = mock.MagicMock(return_value=True)

        # WHEN
        main(["main.py", "--init", "build-release", "1.2.3"])

        # THEN
        self.mock_git_repo.return_value.create_tag.assert_not_called()
        self.mock_git_repo.return_value.git.commit.assert_not_called()
Beispiel #7
0
    def test_update_clone_projects(self, mock_path_exists):
        # WHEN
        main(["main.py", "--init", "update-projects"])

        # THEN
        self.assertEqual(self.mock_git_repo.clone_from.call_count, 2)
        self.mock_subprocess_call.assert_any_call([
            "make", "install", "-C",
            os.path.join(utils.get_projects_dir(), "platform")
        ])
        self.mock_subprocess_call.assert_any_call([
            "make", "install", "-C",
            os.path.join(utils.get_projects_dir(), "frontend")
        ])
Beispiel #8
0
    def test_deploy_build_all_tags(self):
        # WHEN
        main([
            "main.py", "--init", "deploy-build", "1.2.3", "devbox", "--code",
            "--migrate", "--envvars", "--conf", "--ssl"
        ])

        # THEN
        self.mock_subprocess_call.assert_called_once_with([
            "ansible-playbook",
            '--inventory-file={}/hosts/devbox'.format(utils.get_ansible_dir()),
            '-v', '--extra-vars', 'build_version=1.2.3', '--tags',
            'code,migrate,envvars,conf,ssl',
            '{}/{}.yml'.format(utils.get_ansible_dir(), "devbox")
        ])
Beispiel #9
0
    def test_deploy_build_code_limit_hosts(self):
        # WHEN
        main([
            "main.py", "--init", "deploy-build", "1.2.3", "devbox", "--code",
            "--roles", "host1,host2"
        ])

        # THEN
        self.mock_subprocess_call.assert_called_once_with([
            "ansible-playbook",
            '--inventory-file={}/hosts/devbox'.format(utils.get_ansible_dir()),
            '-v', '--extra-vars', 'build_version=1.2.3', '--tags', 'code',
            '--limit', 'host1,host2',
            '{}/{}.yml'.format(utils.get_ansible_dir(), "devbox")
        ])
Beispiel #10
0
    def test_set_build(self, mock_path_exists):
        # GIVEN
        utils._save_config(os.environ.get("HELIUMCLI_CONFIG_PATH"),
                           settings.get_default_settings())

        # WHEN
        main(["main.py", "--init", "set-build", "1.2.3"])

        # THEN
        self.mock_git_repo.return_value.git.checkout.assert_has_calls(
            [mock.call("1.2.3"), mock.call("1.2.3")])
        self.mock_subprocess_call.assert_any_call([
            "make", "install", "-C",
            os.path.join(utils.get_projects_dir(), "platform")
        ])
        self.mock_subprocess_call.assert_any_call([
            "make", "install", "-C",
            os.path.join(utils.get_projects_dir(), "frontend")
        ])
Beispiel #11
0
    def test_update_projects(self, mock_path_exists):
        # GIVEN
        utils._save_config(os.environ.get("HELIUMCLI_CONFIG_PATH"),
                           settings.get_default_settings())

        # WHEN
        main(["main.py", "--init", "update-projects"])

        # THEN
        self.assertEqual(self.mock_git_repo.return_value.git.pull.call_count,
                         3)
        self.mock_subprocess_call.assert_any_call([
            "make", "install", "-C",
            os.path.join(utils.get_projects_dir(), "platform")
        ])
        self.mock_subprocess_call.assert_any_call([
            "make", "install", "-C",
            os.path.join(utils.get_projects_dir(), "frontend")
        ])
Beispiel #12
0
    def test_deploy_build(self):
        self.subprocess_popen.stop()

        # GIVEN
        commonhelper.given_hosts_file_exists()

        # WHEN
        main(["main.py", "--init", "deploy-build", "1.2.3", "devbox"])

        # THEN
        self.assertEqual(self.mock_subprocess_call.call_count, 2)
        self.mock_subprocess_call.assert_any_call([
            "ssh", "-t", "*****@*****.**",
            utils.get_config(True)["hostProvisionCommand"]
        ])
        self.mock_subprocess_call.assert_any_call([
            "ansible-playbook",
            '--inventory-file={}/hosts/devbox'.format(utils.get_ansible_dir()),
            '-v', '--extra-vars', 'build_version=1.2.3',
            '{}/{}.yml'.format(utils.get_ansible_dir(), "devbox")
        ])

        self.subprocess_popen.start()
Beispiel #13
0
    def test_prep_code(self):
        # GIVEN
        commonhelper.given_python_version_file_exists("1.2.3")
        versioned_file1_path = commonhelper.given_project_python_versioned_file_exists(
            "platform")
        versioned_file2_path = commonhelper.given_project_js_versioned_file_exists(
            "frontend")
        repo_instance = self.mock_git_repo.return_value
        latest_tag = repo_instance.tags[-1]
        latest_tag.commit = mock.MagicMock('git.commit.Commit')
        diff1 = mock.MagicMock('git.diff.Diff')
        diff1.b_rawpath = versioned_file1_path.encode('utf-8')
        diff2 = mock.MagicMock('git.diff.Diff')
        diff2.b_rawpath = versioned_file2_path.encode('utf-8')
        latest_tag.commit.diff = mock.MagicMock(side_effect=[[diff1], [diff2]])

        # WHEN
        main(["main.py", "--init", "prep-code"])

        # THEN
        commonhelper.verify_versioned_file_updated(self, versioned_file1_path,
                                                   "1.2.3")
        commonhelper.verify_versioned_file_updated(self, versioned_file2_path,
                                                   "1.2.3")