示例#1
0
    def _new_open_task(
            self,
            state_name=feconf.DEFAULT_INIT_STATE_NAME,
            task_type=improvements_models.TASK_TYPE_HIGH_BOUNCE_RATE,
            exploration_version=1):
        """Constructs a new default open task with the provided values.

        Args:
            state_name: str. The name of the state the task should target.
            task_type: str. The type of the task.
            exploration_version: int. The version of the exploration the task
                should target.

        Returns:
            improvements_domain.TaskEntry. A new open task entry.
        """
        return improvements_domain.TaskEntry(
            entity_type=improvements_models.TASK_ENTITY_TYPE_EXPLORATION,
            entity_id=self.EXP_ID,
            entity_version=exploration_version,
            task_type=task_type,
            target_type=improvements_models.TASK_TARGET_TYPE_STATE,
            target_id=state_name,
            issue_description='issue description',
            status=improvements_models.TASK_STATUS_OPEN,
            resolver_id=None,
            resolved_on=None)
示例#2
0
    def _new_resolved_task(
            self,
            state_name=feconf.DEFAULT_INIT_STATE_NAME,
            task_type=improvements_models.TASK_TYPE_HIGH_BOUNCE_RATE,
            exploration_version=1,
            resolved_on=MOCK_DATE):
        """Constructs a new default resolved task with the provided values.

        Args:
            state_name: str. The name of the state the task should target.
            task_type: str. The type of the task.
            exploration_version: int. The version of the exploration the task
                should target.
            resolved_on: datetime.datetime. Time at which the task was resolved.

        Returns:
            improvements_domain.TaskEntry. A new resolved task entry.
        """
        return improvements_domain.TaskEntry(
            entity_type=improvements_models.TASK_ENTITY_TYPE_EXPLORATION,
            entity_id=self.EXP_ID,
            entity_version=exploration_version,
            task_type=task_type,
            target_type=improvements_models.TASK_TARGET_TYPE_STATE,
            target_id=state_name,
            issue_description='issue description',
            status=improvements_models.TASK_STATUS_RESOLVED,
            resolver_id=self.owner_id,
            resolved_on=resolved_on)
示例#3
0
 def test_to_dict_has_expected_value(self):
     task_entry = improvements_domain.TaskEntry(
         improvements_models.TASK_ENTITY_TYPE_EXPLORATION, self.exp_id, 1,
         improvements_models.TASK_TYPE_HIGH_BOUNCE_RATE,
         improvements_models.TASK_TARGET_TYPE_STATE,
         feconf.DEFAULT_INIT_STATE_NAME, 'issue description',
         improvements_models.TASK_STATUS_RESOLVED, self.owner_id,
         self.MOCK_DATE)
     self.assertEqual(
         task_entry.to_dict(), {
             'entity_type':
             'exploration',
             'entity_id':
             self.exp_id,
             'entity_version':
             1,
             'task_type':
             'high_bounce_rate',
             'target_type':
             'state',
             'target_id':
             'Introduction',
             'issue_description':
             'issue description',
             'status':
             'resolved',
             'resolver_username':
             self.OWNER_USERNAME,
             'resolver_profile_picture_data_url':
             (user_services.DEFAULT_IDENTICON_DATA_URL),
             'resolved_on_msecs':
             utils.get_time_in_millisecs(self.MOCK_DATE),
         })
示例#4
0
 def post(self, exploration_id):
     task_entries = self.payload.get('task_entries', None)
     if task_entries is None:
         raise self.InvalidInputException('No task_entries provided')
     task_entries_to_put = []
     for task_entry in task_entries:
         entity_version = task_entry.get('entity_version', None)
         if entity_version is None:
             raise self.InvalidInputException('No entity_version provided')
         task_type = task_entry.get('task_type', None)
         if task_type is None:
             raise self.InvalidInputException('No task_type provided')
         target_id = task_entry.get('target_id', None)
         if target_id is None:
             raise self.InvalidInputException('No target_id provided')
         status = task_entry.get('status', None)
         if status is None:
             raise self.InvalidInputException('No status provided')
         # The issue_description is allowed to be None.
         issue_description = task_entry.get('issue_description', None)
         task_entries_to_put.append(
             improvements_domain.TaskEntry(
                 improvements_models.TASK_ENTITY_TYPE_EXPLORATION,
                 exploration_id,
                 entity_version,
                 task_type,
                 improvements_models.TASK_TARGET_TYPE_STATE,
                 target_id,
                 issue_description,
                 status,
                 self.user_id,
                 datetime.datetime.utcnow()))
     improvements_services.put_tasks(task_entries_to_put)
     self.render_json({})
示例#5
0
 def test_to_dict_with_non_existing_resolver_id(self) -> None:
     task_entry = improvements_domain.TaskEntry(
         constants.TASK_ENTITY_TYPE_EXPLORATION, self.exp.id, 1,
         constants.TASK_TYPE_HIGH_BOUNCE_RATE,
         constants.TASK_TARGET_TYPE_STATE, feconf.DEFAULT_INIT_STATE_NAME,
         'issue description', constants.TASK_STATUS_RESOLVED, None,
         self.MOCK_DATE)
     # In case of non-existing resolver_id,
     # get_task_dict_with_username_and_profile_picture should return
     # with no changes to the TaskEntry dict.
     task_entry_dict = (
         improvements.
         get_task_dict_with_username_and_profile_picture(  # type: ignore[no-untyped-call]
             task_entry))
     self.assertEqual(
         task_entry_dict, {
             'entity_type': 'exploration',
             'entity_id': self.exp.id,
             'entity_version': 1,
             'task_type': 'high_bounce_rate',
             'target_type': 'state',
             'target_id': 'Introduction',
             'issue_description': 'issue description',
             'status': 'resolved',
             'resolver_username': None,
             'resolver_profile_picture_data_url': None,
             'resolved_on_msecs': utils.get_time_in_millisecs(
                 self.MOCK_DATE),
         })
示例#6
0
 def test_composite_entity_id_has_expected_value(self):
     task_entry = improvements_domain.TaskEntry(
         improvements_models.TASK_ENTITY_TYPE_EXPLORATION, self.exp_id, 1,
         improvements_models.TASK_TYPE_HIGH_BOUNCE_RATE,
         improvements_models.TASK_TARGET_TYPE_STATE,
         feconf.DEFAULT_INIT_STATE_NAME, 'issue description',
         improvements_models.TASK_STATUS_RESOLVED, self.owner_id,
         self.MOCK_DATE)
     self.assertEqual(task_entry.composite_entity_id, 'exploration.eid.1')
示例#7
0
 def test_to_dict_with_non_existing_resolver_id_raises_exception(self):
     invalid_resolver_id = 'non_existing_user_id'
     task_entry = improvements_domain.TaskEntry(
         improvements_models.TASK_ENTITY_TYPE_EXPLORATION, self.exp_id, 1,
         improvements_models.TASK_TYPE_HIGH_BOUNCE_RATE,
         improvements_models.TASK_TARGET_TYPE_STATE,
         feconf.DEFAULT_INIT_STATE_NAME, 'issue description',
         improvements_models.TASK_STATUS_RESOLVED, invalid_resolver_id,
         self.MOCK_DATE)
     with self.assertRaisesRegexp(Exception, 'User not found'):
         task_entry.to_dict()
 def test_task_id_has_expected_value(self) -> None:
     task_entry = improvements_domain.TaskEntry(
         improvements_models.TASK_ENTITY_TYPE_EXPLORATION, self.exp_id, 1,
         improvements_models.TASK_TYPE_HIGH_BOUNCE_RATE,
         improvements_models.TASK_TARGET_TYPE_STATE,
         feconf.DEFAULT_INIT_STATE_NAME, 'issue description',
         improvements_models.TASK_STATUS_RESOLVED, self.owner_id,
         self.MOCK_DATE)
     self.assertEqual(
         task_entry.task_id,
         'exploration.eid.1.high_bounce_rate.state.Introduction')
示例#9
0
 def test_to_dict_with_invalid_resolver_id_raises_exception(self) -> None:
     invalid_resolver_id = 'non_existing_user_id'
     task_entry = improvements_domain.TaskEntry(
         constants.TASK_ENTITY_TYPE_EXPLORATION, self.exp.id, 1,
         constants.TASK_TYPE_HIGH_BOUNCE_RATE,
         constants.TASK_TARGET_TYPE_STATE, feconf.DEFAULT_INIT_STATE_NAME,
         'issue description', constants.TASK_STATUS_RESOLVED,
         invalid_resolver_id, self.MOCK_DATE)
     with self.assertRaisesRegex(
             Exception, 'User not found'):  # type: ignore[no-untyped-call]
         improvements.get_task_dict_with_username_and_profile_picture(  # type: ignore[no-untyped-call]
             task_entry)
def get_task_entry_from_model(task_entry_model):
    """Returns a domain object corresponding to the given task entry model.

    Args:
        task_entry_model: improvements_models.TaskEntryModel.

    Returns:
        improvements_domain.TaskEntry. The corresponding domain object.
    """
    return improvements_domain.TaskEntry(
        task_entry_model.entity_type, task_entry_model.entity_id,
        task_entry_model.entity_version, task_entry_model.task_type,
        task_entry_model.target_type, task_entry_model.target_id,
        task_entry_model.issue_description, task_entry_model.status,
        task_entry_model.resolver_id, task_entry_model.resolved_on)
示例#11
0
    def test_constructor_ignores_resolution_args_when_task_is_open(self):
        task_entry = improvements_domain.TaskEntry(
            improvements_models.TASK_ENTITY_TYPE_EXPLORATION, self.exp_id, 1,
            improvements_models.TASK_TYPE_HIGH_BOUNCE_RATE,
            improvements_models.TASK_TARGET_TYPE_STATE,
            feconf.DEFAULT_INIT_STATE_NAME, 'issue description',
            improvements_models.TASK_STATUS_OPEN, self.owner_id, self.MOCK_DATE)

        self.assertEqual(task_entry.entity_type, 'exploration')
        self.assertEqual(task_entry.entity_id, self.exp_id)
        self.assertEqual(task_entry.entity_version, 1)
        self.assertEqual(task_entry.task_type, 'high_bounce_rate')
        self.assertEqual(task_entry.target_type, 'state')
        self.assertEqual(task_entry.target_id, 'Introduction')
        self.assertEqual(task_entry.issue_description, 'issue description')
        self.assertEqual(task_entry.status, 'open')
        self.assertIsNone(task_entry.resolver_id)
        self.assertIsNone(task_entry.resolved_on)
示例#12
0
    def test_can_create_obsolete_task_with_corresponding_values(self):
        task_entry = improvements_domain.TaskEntry(
            improvements_models.TASK_ENTITY_TYPE_EXPLORATION, self.exp_id, 1,
            improvements_models.TASK_TYPE_HIGH_BOUNCE_RATE,
            improvements_models.TASK_TARGET_TYPE_STATE,
            feconf.DEFAULT_INIT_STATE_NAME, 'issue description',
            improvements_models.TASK_STATUS_OBSOLETE, None, None)

        self.assertEqual(task_entry.entity_type, 'exploration')
        self.assertEqual(task_entry.entity_id, self.exp_id)
        self.assertEqual(task_entry.entity_version, 1)
        self.assertEqual(task_entry.task_type, 'high_bounce_rate')
        self.assertEqual(task_entry.target_type, 'state')
        self.assertEqual(task_entry.target_id, 'Introduction')
        self.assertEqual(task_entry.issue_description, 'issue description')
        self.assertEqual(task_entry.status, 'obsolete')
        self.assertIsNone(task_entry.resolver_id)
        self.assertIsNone(task_entry.resolved_on)
示例#13
0
 def post(self, exploration_id):
     task_entries = self.normalized_payload.get('task_entries')
     task_entries_to_put = []
     for task_entry in task_entries:
         entity_version = task_entry['entity_version']
         task_type = task_entry['task_type']
         target_id = task_entry['target_id']
         status = task_entry['status']
         # The issue_description is allowed to be None.
         issue_description = task_entry.get('issue_description', None)
         task_entries_to_put.append(
             improvements_domain.TaskEntry(
                 constants.TASK_ENTITY_TYPE_EXPLORATION, exploration_id,
                 entity_version, task_type,
                 constants.TASK_TARGET_TYPE_STATE, target_id,
                 issue_description, status, self.user_id,
                 datetime.datetime.utcnow()))
     improvements_services.put_tasks(task_entries_to_put)
     self.render_json({})
示例#14
0
    def test_can_create_resolved_task_with_corresponding_value(self) -> None:
        task_entry = improvements_domain.TaskEntry(
            constants.TASK_ENTITY_TYPE_EXPLORATION, self.exp_id, 1,
            constants.TASK_TYPE_HIGH_BOUNCE_RATE,
            constants.TASK_TARGET_TYPE_STATE,
            feconf.DEFAULT_INIT_STATE_NAME, 'issue description',
            constants.TASK_STATUS_RESOLVED, self.owner_id,
            self.MOCK_DATE)

        self.assertEqual(task_entry.entity_type, 'exploration')
        self.assertEqual(task_entry.entity_id, self.exp_id)
        self.assertEqual(task_entry.entity_version, 1)
        self.assertEqual(task_entry.task_type, 'high_bounce_rate')
        self.assertEqual(task_entry.target_type, 'state')
        self.assertEqual(task_entry.target_id, 'Introduction')
        self.assertEqual(task_entry.issue_description, 'issue description')
        self.assertEqual(task_entry.status, 'resolved')
        self.assertEqual(task_entry.resolver_id, self.owner_id)
        self.assertEqual(task_entry.resolved_on, self.MOCK_DATE)
示例#15
0
 def test_to_dict_has_expected_value(self) -> None:
     # Data url for images/avatar/user_blue_72px.png.
     # Generated using utils.convert_png_to_data_url.
     task_entry = improvements_domain.TaskEntry(
         constants.TASK_ENTITY_TYPE_EXPLORATION, self.exp_id, 1,
         constants.TASK_TYPE_HIGH_BOUNCE_RATE,
         constants.TASK_TARGET_TYPE_STATE,
         feconf.DEFAULT_INIT_STATE_NAME, 'issue description',
         constants.TASK_STATUS_RESOLVED, self.owner_id,
         self.MOCK_DATE)
     self.assertEqual(task_entry.to_dict(), {
         'entity_type': 'exploration',
         'entity_id': self.exp_id,
         'entity_version': 1,
         'task_type': 'high_bounce_rate',
         'target_type': 'state',
         'target_id': 'Introduction',
         'issue_description': 'issue description',
         'status': 'resolved',
         'resolver_username': None,
         'resolver_profile_picture_data_url': None,
         'resolved_on_msecs': utils.get_time_in_millisecs(self.MOCK_DATE),
     })