Esempio n. 1
0
    def test_backup_restoration_with_valid_export_metadata_filepath(self):
        check_function_calls = {
            'open_tab_is_called': False,
            'input_is_called': False
        }
        expected_check_function_calls = {
            'open_tab_is_called': True,
            'input_is_called': True
        }
        def mock_open_tab(unused_url):
            check_function_calls['open_tab_is_called'] = True
        valid_export_metadata_filepath = (
            'oppia-export-backups/20181111-123456/'
            '20181111-123456.overall_export_metadata')
        def mock_input():
            check_function_calls['input_is_called'] = True
            return valid_export_metadata_filepath

        open_tab_swap = self.swap(
            common, 'open_new_tab_in_browser_if_possible', mock_open_tab)
        input_swap = self.swap(python_utils, 'INPUT', mock_input)
        with self.exists_swap, self.run_cmd_swap, open_tab_swap, input_swap:
            restore_backup.main(args=['--project_name=sample_project_name'])

        self.assertEqual(
            self.all_cmd_tokens,
            [
                common.GCLOUD_PATH, 'config', 'set', 'project',
                'sample_project_name',
                common.GCLOUD_PATH, 'datastore', 'import',
                'gs://%s' % valid_export_metadata_filepath, '--async'])
        self.assertEqual(check_function_calls, expected_check_function_calls)
Esempio n. 2
0
    def test_check_status(self):
        with self.exists_swap, self.run_cmd_swap:
            restore_backup.main(args=['--check_status'])

        self.assertEqual(
            self.all_cmd_tokens,
            [common.GCLOUD_PATH, 'datastore', 'operations', 'list'])
 def test_missing_gae_dir(self):
     def mock_exists(unused_path):
         return False
     exists_swap = self.swap(os.path, 'exists', mock_exists)
     with exists_swap, self.assertRaisesRegexp(
         Exception, 'Directory %s does not exist.' % restore_backup.GAE_DIR):
         restore_backup.main(args=[])
Esempio n. 4
0
 def test_missing_gae_dir(self):
     def mock_exists(unused_path):
         return False
     exists_swap = self.swap(os.path, 'exists', mock_exists)
     with exists_swap, self.assertRaisesRegexp(
         Exception,
         'Directory %s does not exist.' % common.GOOGLE_APP_ENGINE_SDK_HOME):
         restore_backup.main(args=[])
Esempio n. 5
0
 def test_cancel_operation_when_user_aborts_cancellation_after_warning(self):
     print_arr = []
     def mock_print(msg):
         print_arr.append(msg)
     def mock_input():
         if 'Cancellation' in print_arr[-1]:
             return 'n'
         return 'Sample operation'
     print_swap = self.swap(python_utils, 'PRINT', mock_print)
     input_swap = self.swap(python_utils, 'INPUT', mock_input)
     with self.exists_swap, self.run_cmd_swap, print_swap, input_swap:
         restore_backup.main(args=['--cancel_operation'])
     self.assertEqual(self.all_cmd_tokens, [])
Esempio n. 6
0
 def test_missing_project_name(self):
     with self.exists_swap, self.assertRaisesRegexp(
         Exception, 'Please provide project name for backup restoration.'):
         restore_backup.main(args=[])