Exemplo n.º 1
0
 def test_clear_exploration_search_index(self):
     exp_services.load_demo('0')
     result = search_services.search_explorations('Welcome', [], [], 2)[0]
     self.assertEqual(result, ['0'])
     search_services.clear_exploration_search_index()
     result = search_services.search_explorations('Welcome', [], [], 2)[0]
     self.assertEqual(result, [])
Exemplo n.º 2
0
 def post(self):
     """Handles POST requests."""
     try:
         result = {}
         if self.payload.get('action') == 'reload_exploration':
             exploration_id = self.payload.get('exploration_id')
             self._reload_exploration(exploration_id)
         elif self.payload.get('action') == 'reload_collection':
             collection_id = self.payload.get('collection_id')
             self._reload_collection(collection_id)
         elif self.payload.get('action') == 'generate_dummy_explorations':
             num_dummy_exps_to_generate = self.payload.get(
                 'num_dummy_exps_to_generate')
             num_dummy_exps_to_publish = self.payload.get(
                 'num_dummy_exps_to_publish')
             if not isinstance(num_dummy_exps_to_generate, int):
                 raise self.InvalidInputException(
                     '%s is not a number' % num_dummy_exps_to_generate)
             elif not isinstance(num_dummy_exps_to_publish, int):
                 raise self.InvalidInputException('%s is not a number' %
                                                  num_dummy_exps_to_publish)
             elif num_dummy_exps_to_generate < num_dummy_exps_to_publish:
                 raise self.InvalidInputException(
                     'Generate count cannot be less than publish count')
             else:
                 self._generate_dummy_explorations(
                     num_dummy_exps_to_generate, num_dummy_exps_to_publish)
         elif self.payload.get('action') == 'clear_search_index':
             search_services.clear_collection_search_index()
             search_services.clear_exploration_search_index()
         elif (self.payload.get('action') ==
               'generate_dummy_new_structures_data'):
             self._load_dummy_new_structures_data()
         elif self.payload.get('action') == (
                 'flush_migration_bot_contribution_data'):
             user_services.flush_migration_bot_contributions_model()
         elif self.payload.get('action') == 'save_config_properties':
             new_config_property_values = self.payload.get(
                 'new_config_property_values')
             logging.info('[ADMIN] %s saved config property values: %s' %
                          (self.user_id, new_config_property_values))
             for (name, value) in new_config_property_values.items():
                 config_services.set_property(self.user_id, name, value)
         elif self.payload.get('action') == 'revert_config_property':
             config_property_id = self.payload.get('config_property_id')
             logging.info('[ADMIN] %s reverted config property: %s' %
                          (self.user_id, config_property_id))
             config_services.revert_property(self.user_id,
                                             config_property_id)
         elif self.payload.get('action') == 'start_new_job':
             for klass in (jobs_registry.ONE_OFF_JOB_MANAGERS +
                           (jobs_registry.AUDIT_JOB_MANAGERS)):
                 if klass.__name__ == self.payload.get('job_type'):
                     klass.enqueue(klass.create_new())
                     break
         elif self.payload.get('action') == 'cancel_job':
             job_id = self.payload.get('job_id')
             job_type = self.payload.get('job_type')
             for klass in (jobs_registry.ONE_OFF_JOB_MANAGERS +
                           (jobs_registry.AUDIT_JOB_MANAGERS)):
                 if klass.__name__ == job_type:
                     klass.cancel(job_id, self.user_id)
                     break
         elif self.payload.get('action') == 'start_computation':
             computation_type = self.payload.get('computation_type')
             for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                 if klass.__name__ == computation_type:
                     klass.start_computation()
                     break
         elif self.payload.get('action') == 'stop_computation':
             computation_type = self.payload.get('computation_type')
             for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                 if klass.__name__ == computation_type:
                     klass.stop_computation(self.user_id)
                     break
         elif self.payload.get('action') == 'upload_topic_similarities':
             data = self.payload.get('data')
             recommendations_services.update_topic_similarities(data)
         elif self.payload.get('action') == (
                 'regenerate_topic_related_opportunities'):
             topic_id = self.payload.get('topic_id')
             opportunities_count = (
                 opportunity_services.
                 regenerate_opportunities_related_to_topic(
                     topic_id, delete_existing_opportunities=True))
             result = {'opportunities_count': opportunities_count}
         self.render_json(result)
     except Exception as e:
         self.render_json({'error': python_utils.UNICODE(e)})
         raise
Exemplo n.º 3
0
 def post(self):
     """Handles POST requests."""
     try:
         result = {}
         if self.payload.get('action') == 'reload_exploration':
             exploration_id = self.payload.get('exploration_id')
             self._reload_exploration(exploration_id)
         elif self.payload.get('action') == 'reload_collection':
             collection_id = self.payload.get('collection_id')
             self._reload_collection(collection_id)
         elif self.payload.get('action') == 'generate_dummy_explorations':
             num_dummy_exps_to_generate = self.payload.get(
                 'num_dummy_exps_to_generate')
             num_dummy_exps_to_publish = self.payload.get(
                 'num_dummy_exps_to_publish')
             if not isinstance(num_dummy_exps_to_generate, int):
                 raise self.InvalidInputException(
                     '%s is not a number' % num_dummy_exps_to_generate)
             elif not isinstance(num_dummy_exps_to_publish, int):
                 raise self.InvalidInputException('%s is not a number' %
                                                  num_dummy_exps_to_publish)
             elif num_dummy_exps_to_generate < num_dummy_exps_to_publish:
                 raise self.InvalidInputException(
                     'Generate count cannot be less than publish count')
             else:
                 self._generate_dummy_explorations(
                     num_dummy_exps_to_generate, num_dummy_exps_to_publish)
         elif self.payload.get('action') == 'clear_search_index':
             search_services.clear_collection_search_index()
             search_services.clear_exploration_search_index()
         elif (self.payload.get('action') ==
               'generate_dummy_new_structures_data'):
             self._load_dummy_new_structures_data()
         elif (self.payload.get('action') == 'generate_dummy_new_skill_data'
               ):
             self._generate_dummy_skill_and_questions()
         elif self.payload.get('action') == 'save_config_properties':
             new_config_property_values = self.payload.get(
                 'new_config_property_values')
             logging.info('[ADMIN] %s saved config property values: %s' %
                          (self.user_id, new_config_property_values))
             for (name, value) in new_config_property_values.items():
                 config_services.set_property(self.user_id, name, value)
         elif self.payload.get('action') == 'revert_config_property':
             config_property_id = self.payload.get('config_property_id')
             logging.info('[ADMIN] %s reverted config property: %s' %
                          (self.user_id, config_property_id))
             config_services.revert_property(self.user_id,
                                             config_property_id)
         elif self.payload.get('action') == 'start_new_job':
             for klass in (jobs_registry.ONE_OFF_JOB_MANAGERS +
                           (jobs_registry.AUDIT_JOB_MANAGERS)):
                 if klass.__name__ == self.payload.get('job_type'):
                     klass.enqueue(klass.create_new())
                     break
         elif self.payload.get('action') == 'cancel_job':
             job_id = self.payload.get('job_id')
             job_type = self.payload.get('job_type')
             for klass in (jobs_registry.ONE_OFF_JOB_MANAGERS +
                           (jobs_registry.AUDIT_JOB_MANAGERS)):
                 if klass.__name__ == job_type:
                     klass.cancel(job_id, self.user_id)
                     break
         elif self.payload.get('action') == 'start_computation':
             computation_type = self.payload.get('computation_type')
             for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                 if klass.__name__ == computation_type:
                     klass.start_computation()
                     break
         elif self.payload.get('action') == 'stop_computation':
             computation_type = self.payload.get('computation_type')
             for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                 if klass.__name__ == computation_type:
                     klass.stop_computation(self.user_id)
                     break
         elif self.payload.get('action') == 'upload_topic_similarities':
             data = self.payload.get('data')
             recommendations_services.update_topic_similarities(data)
         elif self.payload.get('action') == (
                 'regenerate_topic_related_opportunities'):
             topic_id = self.payload.get('topic_id')
             opportunities_count = (
                 opportunity_services.
                 regenerate_opportunities_related_to_topic(
                     topic_id, delete_existing_opportunities=True))
             result = {'opportunities_count': opportunities_count}
         elif self.payload.get('action') == 'update_feature_flag_rules':
             feature_name = self.payload.get('feature_name')
             new_rule_dicts = self.payload.get('new_rules')
             commit_message = self.payload.get('commit_message')
             if not isinstance(feature_name, python_utils.BASESTRING):
                 raise self.InvalidInputException(
                     'feature_name should be string, received \'%s\'.' %
                     (feature_name))
             elif not isinstance(commit_message, python_utils.BASESTRING):
                 raise self.InvalidInputException(
                     'commit_message should be string, received \'%s\'.' %
                     (commit_message))
             elif (not isinstance(new_rule_dicts, list) or not all([
                     isinstance(rule_dict, dict)
                     for rule_dict in new_rule_dicts
             ])):
                 raise self.InvalidInputException(
                     'new_rules should be a list of dicts, received'
                     ' \'%s\'.' % new_rule_dicts)
             try:
                 feature_services.update_feature_flag_rules(
                     feature_name, self.user_id, commit_message,
                     new_rule_dicts)
             except (utils.ValidationError,
                     feature_services.FeatureFlagNotFoundException) as e:
                 raise self.InvalidInputException(e)
             logging.info('[ADMIN] %s updated feature %s with new rules: '
                          '%s.' %
                          (self.user_id, feature_name, new_rule_dicts))
         self.render_json(result)
     except Exception as e:
         logging.error('[ADMIN] %s', e)
         self.render_json({'error': python_utils.UNICODE(e)})
         python_utils.reraise_exception()
Exemplo n.º 4
0
    def post(self):
        """Handles POST requests."""
        action = self.normalized_payload.get('action')
        try:
            result = {}
            if action == 'reload_exploration':
                exploration_id = self.normalized_payload.get('exploration_id')
                self._reload_exploration(exploration_id)
            elif action == 'reload_collection':
                collection_id = self.normalized_payload.get('collection_id')
                self._reload_collection(collection_id)
            elif action == 'generate_dummy_explorations':
                num_dummy_exps_to_generate = self.normalized_payload.get(
                    'num_dummy_exps_to_generate')
                num_dummy_exps_to_publish = self.normalized_payload.get(
                    'num_dummy_exps_to_publish')

                if num_dummy_exps_to_generate < num_dummy_exps_to_publish:
                    raise self.InvalidInputException(
                        'Generate count cannot be less than publish count')
                else:
                    self._generate_dummy_explorations(
                        num_dummy_exps_to_generate, num_dummy_exps_to_publish)
            elif action == 'clear_search_index':
                search_services.clear_collection_search_index()
                search_services.clear_exploration_search_index()
            elif action == 'generate_dummy_new_structures_data':
                self._load_dummy_new_structures_data()
            elif action == 'generate_dummy_new_skill_data':
                self._generate_dummy_skill_and_questions()
            elif action == 'save_config_properties':
                new_config_property_values = self.normalized_payload.get(
                    'new_config_property_values')
                logging.info('[ADMIN] %s saved config property values: %s' %
                             (self.user_id, new_config_property_values))
                for (name, value) in new_config_property_values.items():
                    config_services.set_property(self.user_id, name, value)
            elif action == 'revert_config_property':
                config_property_id = self.normalized_payload.get(
                    'config_property_id')
                logging.info('[ADMIN] %s reverted config property: %s' %
                             (self.user_id, config_property_id))
                config_services.revert_property(self.user_id,
                                                config_property_id)
            elif action == 'upload_topic_similarities':
                data = self.normalized_payload.get('data')
                recommendations_services.update_topic_similarities(data)
            elif action == 'regenerate_topic_related_opportunities':
                topic_id = self.normalized_payload.get('topic_id')
                opportunities_count = (
                    opportunity_services.
                    regenerate_opportunities_related_to_topic(
                        topic_id, delete_existing_opportunities=True))
                result = {'opportunities_count': opportunities_count}
            elif action == 'update_feature_flag_rules':
                feature_name = self.normalized_payload.get('feature_name')
                new_rule_dicts = self.normalized_payload.get('new_rules')
                commit_message = self.normalized_payload.get('commit_message')

                try:
                    feature_services.update_feature_flag_rules(
                        feature_name, self.user_id, commit_message,
                        new_rule_dicts)
                except (utils.ValidationError,
                        feature_services.FeatureFlagNotFoundException) as e:
                    raise self.InvalidInputException(e)
                logging.info('[ADMIN] %s updated feature %s with new rules: '
                             '%s.' %
                             (self.user_id, feature_name, new_rule_dicts))
            self.render_json(result)
        except Exception as e:
            logging.exception('[ADMIN] %s', e)
            self.render_json({'error': python_utils.UNICODE(e)})
            python_utils.reraise_exception()
Exemplo n.º 5
0
 def post(self):
     """Handles POST requests."""
     try:
         if self.payload.get('action') == 'reload_exploration':
             exploration_id = self.payload.get('exploration_id')
             self._reload_exploration(exploration_id)
         elif self.payload.get('action') == 'reload_collection':
             collection_id = self.payload.get('collection_id')
             self._reload_collection(collection_id)
         elif self.payload.get('action') == 'generate_dummy_explorations':
             num_dummy_exps_to_generate = self.payload.get(
                 'num_dummy_exps_to_generate')
             num_dummy_exps_to_publish = self.payload.get(
                 'num_dummy_exps_to_publish')
             if not isinstance(num_dummy_exps_to_generate, int):
                 raise self.InvalidInputException(
                     '%s is not a number' % num_dummy_exps_to_generate)
             elif not isinstance(num_dummy_exps_to_publish, int):
                 raise self.InvalidInputException(
                     '%s is not a number' % num_dummy_exps_to_publish)
             elif num_dummy_exps_to_generate < num_dummy_exps_to_publish:
                 raise self.InvalidInputException(
                     'Generate count cannot be less than publish count')
             else:
                 self._generate_dummy_explorations(
                     num_dummy_exps_to_generate, num_dummy_exps_to_publish)
         elif self.payload.get('action') == 'clear_search_index':
             search_services.clear_collection_search_index()
             search_services.clear_exploration_search_index()
         elif self.payload.get('action') == 'save_config_properties':
             new_config_property_values = self.payload.get(
                 'new_config_property_values')
             logging.info('[ADMIN] %s saved config property values: %s' %
                          (self.user_id, new_config_property_values))
             for (name, value) in new_config_property_values.iteritems():
                 config_services.set_property(self.user_id, name, value)
         elif self.payload.get('action') == 'revert_config_property':
             config_property_id = self.payload.get('config_property_id')
             logging.info('[ADMIN] %s reverted config property: %s' %
                          (self.user_id, config_property_id))
             config_services.revert_property(
                 self.user_id, config_property_id)
         elif self.payload.get('action') == 'start_new_job':
             for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                 if klass.__name__ == self.payload.get('job_type'):
                     klass.enqueue(klass.create_new())
                     break
         elif self.payload.get('action') == 'cancel_job':
             job_id = self.payload.get('job_id')
             job_type = self.payload.get('job_type')
             for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                 if klass.__name__ == job_type:
                     klass.cancel(job_id, self.user_id)
                     break
         elif self.payload.get('action') == 'start_computation':
             computation_type = self.payload.get('computation_type')
             for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                 if klass.__name__ == computation_type:
                     klass.start_computation()
                     break
         elif self.payload.get('action') == 'stop_computation':
             computation_type = self.payload.get('computation_type')
             for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                 if klass.__name__ == computation_type:
                     klass.stop_computation(self.user_id)
                     break
         elif self.payload.get('action') == 'upload_topic_similarities':
             data = self.payload.get('data')
             recommendations_services.update_topic_similarities(data)
         self.render_json({})
     except Exception as e:
         self.render_json({'error': unicode(e)})
         raise