コード例 #1
0
    def test_prompt_bad_name(self):
        test_io = io.TestIO()

        test_io.answers.append('My Name')
        test_io.answers.append('myname')
        name = prompt.DjangoSuperuserLoginPrompt.prompt(test_io, '[1/2]', {})
        self.assertEqual(name, 'myname')
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #2
0
    def test_prompt_bad_id(self):
        test_io = io.TestIO()

        test_io.answers.append('2short')
        test_io.answers.append('long-enough')
        project_id = prompt.ProjectIdPrompt.prompt(test_io, '[1/2]', {})
        self.assertEqual(project_id, 'long-enough')
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #3
0
    def test_prompt_default_project_name(self):
        test_io = io.TestIO()

        test_io.answers.append('')
        path = prompt.DjangoFilesystemPath.prompt(
            test_io, '[1/2]', {'project_name': 'Project Name'})
        self.assertIn('project-name', path)
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #4
0
    def test_prompt_default_project_name(self):
        test_io = io.TestIO()

        test_io.answers.append('')
        project_id = prompt.ProjectIdPrompt.prompt(
            test_io, '[1/2]', {'project_name': 'My Project'})
        self.assertRegex(project_id, r'my-project-\d{6}')
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #5
0
    def test_prompt_bad_address(self):
        test_io = io.TestIO()

        test_io.answers.append('Not An Email Address')
        test_io.answers.append('*****@*****.**')
        email = prompt.DjangoSuperuserEmailPrompt.prompt(test_io, '[1/2]', {})
        self.assertEqual(email, '*****@*****.**')
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #6
0
    def test_prompt_bad_name(self):
        test_io = io.TestIO()

        test_io.answers.append('5')
        test_io.answers.append('djangoapp')
        name = prompt.DjangoAppNamePrompt.prompt(test_io, '[1/2]', {})
        self.assertEqual(name, 'djangoapp')
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #7
0
    def test_prompt(self):
        test_io = io.TestIO()

        test_io.password_answers.append('mypass32')
        test_io.password_answers.append('mypass32')
        password = prompt.DjangoSuperuserPasswordPrompt.prompt(
            test_io, '[1/2]', {})
        self.assertEqual(password, 'mypass32')
        self.assertEqual(len(test_io.password_answers), 0)  # All answers used.
コード例 #8
0
    def test_bad_password(self):
        test_io = io.TestIO()

        test_io.password_answers.append(' ')
        test_io.password_answers.append('secondtry2')
        test_io.password_answers.append('secondtry2')
        password = prompt.PostgresPasswordPrompt.prompt(test_io, '[1/2]', {})
        self.assertEqual(password, 'secondtry2')
        self.assertEqual(len(test_io.password_answers), 0)  # All answers used.
コード例 #9
0
    def test_prompt_existing_path(self, yes_replace_character):
        test_io = io.TestIO()

        with tempfile.NamedTemporaryFile() as f:
            test_io.answers.append(f.name)
            test_io.answers.append(yes_replace_character)
            path = prompt.DjangoFilesystemPath.prompt(test_io, '[1/2]', {})
            self.assertEqual(path, f.name)
            self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #10
0
    def test_invalid_numeric_choice(self, unused_mock):
        test_io = io.TestIO()

        test_io.answers.append('a')
        test_io.answers.append('1')
        billing_name = prompt.BillingPrompt.prompt(test_io, '[1/2]', {},
                                                   self.credentials)
        self.assertEqual(billing_name, _FAKE_BILLING_ACCOUNTS[0]['name'])
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #11
0
    def test_prompt_bad_name(self):
        test_io = io.TestIO()

        test_io.answers.append('S')
        test_io.answers.append('Long Enough')
        args = self.google_project_name_prompt.prompt(test_io, '[1/2]', {})
        name = args['project_name']
        self.assertEqual(name, 'Long Enough')
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #12
0
    def test_invalid_numeric_choice(self, unused_mock):
        test_io = io.TestIO()

        test_io.answers.append('a')
        test_io.answers.append('1')
        args = self.billing_prompt.prompt(test_io, '[1/2]', {})
        billing_name = args['billing_account_name']
        self.assertEqual(billing_name, _FAKE_BILLING_ACCOUNTS[0]['name'])
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #13
0
    def test_have_existing_accounts_create_new_account(self, *unused_mocks):
        test_io = io.TestIO()

        test_io.answers.append('')
        args = self.billing_prompt.prompt(test_io, '[1/2]', {})
        billing_name = args['billing_account_name']
        self.assertEqual(billing_name,
                         _FAKE_BILLING_ACCOUNTS_AFTER_CREATE[-1]['name'])
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #14
0
    def test_prompt_default_project_name(self):
        test_io = io.TestIO()

        test_io.answers.append('')
        args = {'project_name': 'Project Name'}
        args = self.file_system_prompt.prompt(test_io, '[1/2]', args)
        path = args['django_directory_path']
        self.assertIn('project-name', path)
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #15
0
    def test_prompt(self):
        test_io = io.TestIO()

        test_io.password_answers.append('mypass32')
        test_io.password_answers.append('mypass32')
        args = self.postgres_password_prompt.prompt(test_io, '[1/2]', {})
        password = args['database_password']
        self.assertEqual(password, 'mypass32')
        self.assertEqual(len(test_io.password_answers), 0)  # All answers used.
コード例 #16
0
    def test_prompt_bad_name(self):
        test_io = io.TestIO()

        test_io.answers.append('My Name')
        test_io.answers.append('myname')
        args = self.django_superuser_prompt.prompt(test_io, '[1/2]', {})
        name = args['django_superuser_login']
        self.assertEqual(name, 'myname')
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #17
0
    def test_prompt_bad_address(self):
        test_io = io.TestIO()

        test_io.answers.append('Not An Email Address')
        test_io.answers.append('*****@*****.**')
        args = self.django_superuser_email_prompt.prompt(test_io, '[1/2]', {})
        email = args['django_superuser_email']
        self.assertEqual(email, '*****@*****.**')
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #18
0
    def test_no_existing_accounts_create_new_account_success_second_time(
            self, *unused_mocks):
        test_io = io.TestIO()

        test_io.answers.append('')
        args = self.billing_prompt.prompt(test_io, '[1/2]', {})
        billing_name = args['billing_account_name']
        self.assertEqual(billing_name, _SINGLE_FAKE_ACCOUNT[0]['name'])
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #19
0
    def test_prompt_bad_name(self):
        test_io = io.TestIO()

        test_io.answers.append('5')
        test_io.answers.append('djangoapp')
        args = self.django_app_name_prompt.prompt(test_io, '[1/2]', {})
        name = args['django_app_name']
        self.assertEqual(name, 'djangoapp')
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #20
0
    def test_bad_password(self):
        test_io = io.TestIO()

        test_io.password_answers.append(' ')
        test_io.password_answers.append('secondtry2')
        test_io.password_answers.append('secondtry2')
        args = self.superuser_password_prompt.prompt(test_io, '[1/2]', {})
        password = args['django_superuser_password']
        self.assertEqual(password, 'secondtry2')
        self.assertEqual(len(test_io.password_answers), 0)  # All answers used.
コード例 #21
0
    def test_prompt(self):
        test_io = io.TestIO()

        test_io.password_answers.append('mypass32')
        test_io.password_answers.append('mypass32')
        args = {'django_superuser_login': '******'}
        args = self.superuser_password_prompt.prompt(test_io, '[1/2]', args)
        password = args['django_superuser_password']
        self.assertEqual(password, 'mypass32')
        self.assertEqual(len(test_io.password_answers), 0)  # All answers used.
コード例 #22
0
    def test_prompt_use_existing_project(self, unused_mock):
        test_io = io.TestIO()

        args = {
            'project_creation_mode': workflow.ProjectCreationMode.MUST_EXIST,
            'project_id': 'project-abc'
        }
        name = prompt.GoogleCloudProjectNamePrompt.prompt(
            test_io, '[1/2]', args, self.credentials)
        self.assertEqual(name, _FAKE_PROJECT_RESPONSE['name'])
コード例 #23
0
 def test_prompt_default(self):
     test_io = io.TestIO()
     args = {
         'project_creation_mode': workflow.ProjectCreationMode.CREATE,
     }
     test_io.answers.append('')
     args = self.project_id_prompt.prompt(test_io, '[1/2]', args)
     project_id = args['project_id']
     self.assertRegex(project_id, r'django-\d{6}')
     self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #24
0
    def test_prompt_django_superuser_login(self):
        test_io = io.TestIO()

        test_io.password_answers.append('mypass32')
        test_io.password_answers.append('mypass32')
        password = prompt.DjangoSuperuserPasswordPrompt.prompt(
            test_io, '[1/2]', {'django_superuser_login': '******'})
        self.assertIn('guido', ' '.join(c for (c, *a) in test_io.tell_calls))
        self.assertEqual(password, 'mypass32')
        self.assertEqual(len(test_io.password_answers), 0)  # All answers used.
コード例 #25
0
    def test_prompt_use_existing_project(self, unused_mock):
        test_io = io.TestIO()

        args = {
            'project_creation_mode': workflow.ProjectCreationMode.MUST_EXIST,
            'project_id': 'project-abc'
        }
        args = self.google_project_name_prompt.prompt(test_io, '[1/2]', args)
        name = args['project_name']
        self.assertEqual(name, _FAKE_PROJECT_RESPONSE['name'])
コード例 #26
0
 def test_prompt(self):
     test_io = io.TestIO()
     args = self.name_prompt.prompt(
         test_io,
         '[2/2]',
         {'django_directory_path_cloudify': self.project_dir},
     )
     project_name = args.get('django_project_name_cloudify', None)
     self.assertEqual(self.project_name, project_name)
     self.assertEmpty(test_io.answers)  # All answers used.
コード例 #27
0
    def test_prompt_existing_path(self, yes_replace_character):
        test_io = io.TestIO()

        with tempfile.NamedTemporaryFile() as f:
            test_io.answers.append(f.name)
            test_io.answers.append(yes_replace_character)
            args = self.file_system_prompt.prompt(test_io, '[1/2]', {})
            path = args['django_directory_path']
            self.assertEqual(path, f.name)
            self.assertEqual(len(test_io.answers), 0)  # All answers used.
コード例 #28
0
    def test_invalid_numeric_choice_multiple_accounts(self, unused_mock):
        test_io = io.TestIO()

        test_io.answers.append('a')
        test_io.answers.append('1')
        billing_name = prompt.BillingPrompt.prompt(test_io, '[1/2]', {},
                                                   self.credentials)
        self.assertEqual(billing_name, _FAKE_BILLING_ACCOUNTS[0]['name'])
        self.assertEqual(len(test_io.answers), 0)  # All answers used.
        self.assertIn('enter a value between 1 and 2', test_io.ask_prompts[-1])
コード例 #29
0
 def test_ignore_user_error(self, mock_open_browser, *unused_mocks):
     test_io = io.TestIO()
     test_io.answers.append('Y')  # Agree to open browser to create an issue
     error = KeyError('Test KeyError')
     with self.assertRaises(KeyError):
         try:
             raise crash_handling.UserError() from error
         except Exception as e:
             crash_handling.handle_crash(e, 'command_fake', test_io)
     mock_open_browser.assert_not_called()
コード例 #30
0
    def test_prompt_same_name_as_project(self):
        test_io = io.TestIO()

        test_io.answers.append('djangoproject')
        test_io.answers.append('djangoapp')
        args = {'django_project_name': 'djangoproject'}
        args = self.django_app_name_prompt.prompt(test_io, '[1/2]', args)
        name = args['django_app_name']
        self.assertEqual(name, 'djangoapp')
        self.assertEqual(len(test_io.answers), 0)  # All answers used.