Esempio n. 1
0
 def test_invalid_version(self):
     args_swap = self.swap(
         sys, 'argv', [
             'deploy.py', '--app_name=oppiaserver', '--version=1.2.3'])
     with args_swap, self.assertRaisesRegexp(
         Exception, 'Cannot use custom version with production app.'):
         deploy.execute_deployment()
Esempio n. 2
0
 def test_invalid_release_version(self):
     hyphen_swap = self.swap(deploy, 'HYPHEN_CHAR', '.')
     with self.get_branch_swap, self.args_swap, self.install_swap:
         with hyphen_swap, self.assertRaisesRegexp(
             Exception,
             'Current release version has \'.\' character.'):
             deploy.execute_deployment()
Esempio n. 3
0
    def test_missing_mailgun_api(self):
        args_swap = self.swap(sys, 'argv',
                              ['deploy.py', '--app_name=oppiaserver'])
        feconf_swap = self.swap(deploy, 'FECONF_PATH', MOCK_FECONF_FILEPATH)

        def mock_main(unused_personal_access_token):
            pass

        def mock_get_personal_access_token():
            return 'test'

        def mock_get_organization(unused_self, unused_name):
            return github.Organization.Organization(requester='',
                                                    headers='',
                                                    attributes={},
                                                    completed='')

        def mock_get_repo(unused_self, unused_org):
            return 'repo'

        def mock_check_blocking_bug_issue_count(unused_repo):
            pass

        def mock_check_prs_for_current_release_are_released(unused_repo):
            pass

        def mock_check_output(unused_cmd_tokens):
            return 'Update authors and changelog for v1.2.3'

        def mock_check_travis_and_circleci_tests(unused_current_branch_name):
            pass

        config_swap = self.swap(update_configs, 'main', mock_main)
        get_token_swap = self.swap(common, 'get_personal_access_token',
                                   mock_get_personal_access_token)
        get_org_swap = self.swap(github.Github, 'get_organization',
                                 mock_get_organization)
        get_repo_swap = self.swap(github.Organization.Organization, 'get_repo',
                                  mock_get_repo)
        bug_check_swap = self.swap(common, 'check_blocking_bug_issue_count',
                                   mock_check_blocking_bug_issue_count)
        pr_check_swap = self.swap(
            common, 'check_prs_for_current_release_are_released',
            mock_check_prs_for_current_release_are_released)
        out_swap = self.swap(subprocess, 'check_output', mock_check_output)
        check_tests_swap = self.swap(deploy, 'check_travis_and_circleci_tests',
                                     mock_check_travis_and_circleci_tests)

        with self.get_branch_swap, self.install_swap, self.cwd_check_swap:
            with self.release_script_exist_swap, self.gcloud_available_swap:
                with self.run_swap, self.create_swap, config_swap:
                    with get_token_swap, get_org_swap, get_repo_swap:
                        with bug_check_swap, pr_check_swap, out_swap:
                            with args_swap, feconf_swap, check_tests_swap:
                                with self.assertRaisesRegexp(
                                        Exception,
                                        'The mailgun API key must be added before '
                                        'deployment.'):
                                    deploy.execute_deployment()
Esempio n. 4
0
 def test_invalid_branch(self):
     def mock_get_branch():
         return 'invalid'
     get_branch_swap = self.swap(
         common, 'get_current_branch_name', mock_get_branch)
     with get_branch_swap, self.args_swap, self.install_swap:
         with self.assertRaisesRegexp(
             Exception,
             'The deployment script must be run from a release branch.'):
             deploy.execute_deployment()
Esempio n. 5
0
 def test_exception_is_raised_for_deploying_test_branch_to_test_server(self):
     def mock_get_branch():
         return 'test-deploy'
     get_branch_swap = self.swap(
         common, 'get_current_branch_name', mock_get_branch)
     with get_branch_swap, self.args_swap, self.install_swap:
         with self.assertRaisesRegexp(
             Exception,
             'Test branch can only be deployed to backup server.'):
             deploy.execute_deployment()
Esempio n. 6
0
 def test_missing_third_party_dir(self):
     third_party_swap = self.swap(deploy, 'THIRD_PARTY_DIR', 'INVALID_DIR')
     with self.get_branch_swap, self.install_swap, self.cwd_check_swap:
         with self.release_script_exist_swap, self.gcloud_available_swap:
             with self.run_swap, self.args_swap:
                 with third_party_swap, self.assertRaisesRegexp(
                     Exception,
                     'Could not find third_party directory at INVALID_DIR. '
                     'Please run install_third_party_libs.py prior to '
                     'running this script.'):
                     deploy.execute_deployment()
Esempio n. 7
0
 def test_invalid_release_version_length(self):
     args_swap = self.swap(sys, 'argv', [
         'deploy.py', '--app_name=oppiatestserver',
         '--version=release-1.2.3-invalid-too-long'
     ])
     with self.get_branch_swap, args_swap, self.install_swap:
         with self.assertRaisesRegexp(
                 AssertionError,
                 'The length of the "version" arg should be less than or '
                 'equal to 25 characters.'):
             deploy.execute_deployment()
Esempio n. 8
0
 def test_invalid_last_commit_msg(self):
     args_swap = self.swap(
         sys, 'argv', ['deploy.py', '--app_name=oppiaserver'])
     def mock_check_output(unused_cmd_tokens):
         return 'Invalid'
     out_swap = self.swap(
         subprocess, 'check_output', mock_check_output)
     with self.get_branch_swap, self.install_swap, self.cwd_check_swap:
         with self.release_script_exist_swap, self.gcloud_available_swap:
             with self.run_swap, self.create_swap, args_swap, out_swap:
                 with self.assertRaisesRegexp(
                     Exception, 'Invalid last commit message: Invalid.'):
                     deploy.execute_deployment()
Esempio n. 9
0
    def test_exception_is_raised_for_deploying_test_branch_to_prod(self):
        args_swap = self.swap(sys, 'argv',
                              ['deploy.py', '--app_name=oppiaserver'])

        def mock_get_branch():
            return 'test-deploy'

        get_branch_swap = self.swap(common, 'get_current_branch_name',
                                    mock_get_branch)
        with get_branch_swap, args_swap, self.install_swap:
            with self.assertRaisesRegexp(
                    Exception, 'Test branch cannot be deployed to prod.'):
                deploy.execute_deployment()
Esempio n. 10
0
 def test_invalid_dir_access(self):
     def mock_getcwd():
         return 'invalid'
     getcwd_swap = self.swap(os, 'getcwd', mock_getcwd)
     with self.get_branch_swap, self.install_swap, self.cwd_check_swap:
         with self.release_script_exist_swap, self.gcloud_available_swap:
             with self.args_swap, self.exists_swap, self.check_output_swap:
                 with self.dir_exists_swap, self.copytree_swap, self.cd_swap:
                     with self.run_swap, getcwd_swap:
                         with self.assertRaisesRegexp(
                             Exception,
                             'Invalid directory accessed '
                             'during deployment: invalid'):
                             deploy.execute_deployment()
Esempio n. 11
0
    def test_function_calls_with_custom_version(self):
        check_function_calls = {
            'preprocess_release_gets_called': False,
            'update_and_check_indexes_gets_called': False,
            'build_scripts_gets_called': False,
            'deploy_application_and_write_log_entry_gets_called': False,
            'switch_version_gets_called': False,
            'flush_memcache_gets_called': False,
            'check_breakage_gets_called': False
        }
        expected_check_function_calls = {
            'preprocess_release_gets_called': True,
            'update_and_check_indexes_gets_called': True,
            'build_scripts_gets_called': True,
            'deploy_application_and_write_log_entry_gets_called': True,
            'switch_version_gets_called': True,
            'flush_memcache_gets_called': True,
            'check_breakage_gets_called': True
        }
        def mock_getcwd():
            return 'deploy-oppiatestserver-release-1.2.3-%s' % (
                deploy.CURRENT_DATETIME.strftime('%Y%m%d-%H%M%S'))
        def mock_preprocess_release(unused_app_name, unused_deploy_data_path):
            check_function_calls['preprocess_release_gets_called'] = True
        def mock_update_and_check_indexes(unused_app_name):
            check_function_calls['update_and_check_indexes_gets_called'] = True
        def mock_build_scripts():
            check_function_calls['build_scripts_gets_called'] = True
        def mock_deploy_application_and_write_log_entry(
                unused_app_name, version_to_deploy_to,
                unused_current_git_revision):
            if version_to_deploy_to == 'release-1-2-3-custom':
                check_function_calls[
                    'deploy_application_and_write_log_entry_gets_called'] = True
        def mock_switch_version(
                unused_app_name, current_release_version):
            if current_release_version == 'release-1-2-3-custom':
                check_function_calls['switch_version_gets_called'] = True
        def mock_flush_memcache(unused_app_name):
            check_function_calls['flush_memcache_gets_called'] = True
        def mock_check_breakage(
                unused_app_name, current_release_version):
            if current_release_version == 'release-1-2-3-custom':
                check_function_calls['check_breakage_gets_called'] = True

        cwd_swap = self.swap(os, 'getcwd', mock_getcwd)
        preprocess_swap = self.swap(
            deploy, 'preprocess_release', mock_preprocess_release)
        update_swap = self.swap(
            deploy, 'update_and_check_indexes', mock_update_and_check_indexes)
        build_swap = self.swap(deploy, 'build_scripts', mock_build_scripts)
        deploy_swap = self.swap(
            deploy, 'deploy_application_and_write_log_entry',
            mock_deploy_application_and_write_log_entry)
        switch_swap = self.swap(
            deploy, 'switch_version', mock_switch_version)
        memcache_swap = self.swap(
            deploy, 'flush_memcache', mock_flush_memcache)
        check_breakage_swap = self.swap(
            deploy, 'check_breakage', mock_check_breakage)
        args_swap = self.swap(
            sys, 'argv', [
                'deploy.py', '--app_name=oppiatestserver',
                '--version=release-1.2.3-custom'])

        with self.get_branch_swap, self.install_swap, self.cwd_check_swap:
            with self.release_script_exist_swap, self.gcloud_available_swap:
                with args_swap, self.exists_swap, self.check_output_swap:
                    with self.dir_exists_swap, self.copytree_swap, self.cd_swap:
                        with cwd_swap, preprocess_swap, update_swap, build_swap:
                            with deploy_swap, switch_swap, self.run_swap:
                                with memcache_swap, check_breakage_swap:
                                    deploy.execute_deployment()
        self.assertEqual(check_function_calls, expected_check_function_calls)
Esempio n. 12
0
 def test_missing_app_name(self):
     args_swap = self.swap(
         sys, 'argv', ['deploy.py'])
     with args_swap, self.assertRaisesRegexp(
         Exception, 'No app name specified.'):
         deploy.execute_deployment()
Esempio n. 13
0
 def test_invalid_app_name(self):
     args_swap = self.swap(
         sys, 'argv', ['deploy.py', '--app_name=invalid'])
     with args_swap, self.assertRaisesRegexp(
         Exception, 'Invalid app name: invalid'):
         deploy.execute_deployment()