Beispiel #1
0
 def test_get_project_name_invalid_manage_py(self):
     # Create a temporary directory to put Django project files
     project_dir = tempfile.mkdtemp()
     management.call_command('startproject', 'mysite', project_dir)
     manage_py_path = os.path.join(project_dir, 'manage.py')
     os.remove(manage_py_path)
     with open(manage_py_path, 'w') as f:
         f.write('12345')
     with self.assertRaises(utils.ProjectContentError):
         utils.get_django_project_name(project_dir)
     shutil.rmtree(project_dir)
Beispiel #2
0
def main(args: argparse.Namespace, console: io.IO = io.ConsoleIO()):
    if not tool_requirements.check_and_handle_requirements(
            console, args.backend):
        return

    actual_parameters = {
        'project_creation_mode': workflow.ProjectCreationMode.CREATE,
        'bucket_name': getattr(args, 'bucket_name', None),
        'service_accounts': getattr(args, 'service_accounts', None),
        'services': getattr(args, 'services', None),
        'appengine_service_name': getattr(args, 'appengine_service_name',
                                          None),
        'cluster_name': getattr(args, 'cluster_name', None),
        'database_instance_name': getattr(args, 'database_instance_name',
                                          None),
    }

    prompt_args = {**vars(args), **actual_parameters}
    root_prompt = prompt.RootPrompt()
    actual_parameters = root_prompt.prompt(prompt.Command.CLOUDIFY, console,
                                           prompt_args)
    workflow_manager = workflow.WorkflowManager(
        actual_parameters['credentials'])

    django_directory_path = actual_parameters['django_directory_path_cloudify']
    django_project_name = utils.get_django_project_name(django_directory_path)
    try:
        admin_url = workflow_manager.create_and_deploy_new_project(
            project_name=actual_parameters['project_name'],
            project_id=actual_parameters['project_id'],
            project_creation_mode=actual_parameters['project_creation_mode'],
            billing_account_name=actual_parameters['billing_account_name'],
            django_project_name=django_project_name,
            django_superuser_name=actual_parameters['django_superuser_login'],
            django_superuser_email=actual_parameters['django_superuser_email'],
            django_superuser_password=actual_parameters[
                'django_superuser_password'],
            django_directory_path=django_directory_path,
            django_requirements_path=actual_parameters.get(
                'django_requirements_path'),
            django_settings_path=actual_parameters['django_settings_path'],
            database_password=actual_parameters['database_password'],
            cluster_name=actual_parameters['cluster_name'],
            database_instance_name=actual_parameters['database_instance_name'],
            required_services=actual_parameters['services'],
            required_service_accounts=actual_parameters['service_accounts'],
            appengine_service_name=actual_parameters['appengine_service_name'],
            cloud_storage_bucket_name=actual_parameters['bucket_name'],
            backend=args.backend,
            deploy_existing_django_project=True)
    except workflow.ProjectExistsError:
        console.error('A project with id "{}" already exists'.format(
            actual_parameters['project_id']))

    survey.prompt_for_survey(console)
    return admin_url
Beispiel #3
0
 def test_manage_py_uses_variable_for_settings_module(self):
     """Test case for manage.py uses a variable for settings module."""
     project_dir = tempfile.mkdtemp()
     management.call_command('startproject', 'mysite', project_dir)
     manage_py_path = os.path.join(project_dir, 'manage.py')
     with open(manage_py_path) as f:
         file_content = f.read()
         file_content = file_content.replace('\'mysite.settings\'',
                                             'module_variable')
     with open(manage_py_path, 'wt') as f:
         f.write(file_content)
     self.assertIsNone(utils.get_django_project_name(project_dir))
     shutil.rmtree(project_dir)
Beispiel #4
0
 def test_get_project_name_not_default_settings_module(self):
     # Create a temporary directory to put Django project files
     project_dir = tempfile.mkdtemp()
     management.call_command('startproject', 'mysite', project_dir)
     manage_py_path = os.path.join(project_dir, 'manage.py')
     with open(manage_py_path) as f:
         file_content = f.read()
         file_content = file_content.replace('mysite.settings',
                                             'mysite.settings.dev')
     with open(manage_py_path, 'wt') as f:
         f.write(file_content)
     self.assertEqual(utils.get_django_project_name(project_dir), 'mysite')
     shutil.rmtree(project_dir)
Beispiel #5
0
 def test_get_project_name_no_manage_py(self):
     # Create a temporary directory to put Django project files
     project_dir = tempfile.mkdtemp()
     self.assertIsNone(utils.get_django_project_name(project_dir))
     shutil.rmtree(project_dir)
Beispiel #6
0
 def test_get_project_name(self):
     # Create a temporary directory to put Django project files
     project_dir = tempfile.mkdtemp()
     management.call_command('startproject', 'mysite', project_dir)
     self.assertEqual(utils.get_django_project_name(project_dir), 'mysite')
     shutil.rmtree(project_dir)
Beispiel #7
0
 def test_get_project_name_no_manage_py(self):
     # Create a temporary directory to put Django project files
     project_dir = tempfile.mkdtemp()
     with self.assertRaises(utils.ProjectContentError):
         utils.get_django_project_name(project_dir)
     shutil.rmtree(project_dir)