Пример #1
0
 def test_get_info_for_empty_output(self):
     # check for JSON task_output with missing keys
     instructor_task = self._create_success_entry()
     instructor_task.task_output = "{}"
     succeeded, message = get_task_completion_info(instructor_task)
     self.assertFalse(succeeded)
     self.assertEquals(message, "No progress status information available")
Пример #2
0
 def test_get_info_for_broken_input(self):
     # check for non-JSON task_input, but then just ignore it
     instructor_task = self._create_success_entry()
     instructor_task.task_input = "{ bad"
     succeeded, message = get_task_completion_info(instructor_task)
     self.assertFalse(succeeded)
     self.assertEquals(message, "Status: rescored 2 of 3 (out of 5)")
Пример #3
0
 def test_get_info_for_missing_output(self):
     # check for missing task_output
     instructor_task = self._create_success_entry()
     instructor_task.task_output = None
     succeeded, message = get_task_completion_info(instructor_task)
     self.assertFalse(succeeded)
     self.assertEquals(message, "No status information available")
Пример #4
0
 def test_get_info_for_broken_output(self):
     # check for non-JSON task_output
     instructor_task = self._create_success_entry()
     instructor_task.task_output = "{ bad"
     succeeded, message = get_task_completion_info(instructor_task)
     self.assertFalse(succeeded)
     self.assertEquals(message, "No parsable status information available")
Пример #5
0
 def test_get_info_for_broken_output(self):
     # check for non-JSON task_output
     instructor_task = self._create_success_entry()
     instructor_task.task_output = "{ bad"
     succeeded, message = get_task_completion_info(instructor_task)
     assert not succeeded
     assert message == 'No parsable status information available'
Пример #6
0
 def test_get_info_for_broken_input(self):
     # check for non-JSON task_input, but then just ignore it
     instructor_task = self._create_success_entry()
     instructor_task.task_input = "{ bad"
     succeeded, message = get_task_completion_info(instructor_task)
     self.assertFalse(succeeded)
     self.assertEquals(message, "Status: rescored 2 of 3 (out of 5)")
Пример #7
0
 def test_get_info_for_missing_output(self):
     # check for missing task_output
     instructor_task = self._create_success_entry()
     instructor_task.task_output = None
     succeeded, message = get_task_completion_info(instructor_task)
     assert not succeeded
     assert message == 'No status information available'
Пример #8
0
 def test_get_info_for_empty_output(self):
     # check for JSON task_output with missing keys
     instructor_task = self._create_success_entry()
     instructor_task.task_output = "{}"
     succeeded, message = get_task_completion_info(instructor_task)
     self.assertFalse(succeeded)
     self.assertEquals(message, "No progress status information available")
Пример #9
0
 def test_get_info_for_broken_output(self):
     # check for non-JSON task_output
     instructor_task = self._create_success_entry()
     instructor_task.task_output = "{ bad"
     succeeded, message = get_task_completion_info(instructor_task)
     self.assertFalse(succeeded)
     self.assertEquals(message, "No parsable status information available")
Пример #10
0
 def test_get_info_for_missing_output(self):
     # check for missing task_output
     instructor_task = self._create_success_entry()
     instructor_task.task_output = None
     succeeded, message = get_task_completion_info(instructor_task)
     self.assertFalse(succeeded)
     self.assertEquals(message, "No status information available")
Пример #11
0
def extract_task_features(task):
    """
    Convert task to dict for json rendering.
    Expects tasks have the following features:
    * task_type (str, type of task)
    * task_input (dict, input(s) to the task)
    * task_id (str, celery id of the task)
    * requester (str, username who submitted the task)
    * task_state (str, state of task eg PROGRESS, COMPLETED)
    * created (datetime, when the task was completed)
    * task_output (optional)
    """
    # Pull out information from the task
    features = [
        'task_type', 'task_input', 'task_id', 'requester', 'task_state'
    ]
    task_feature_dict = {
        feature: str(getattr(task, feature))
        for feature in features
    }
    # Some information (created, duration, status, task message) require additional formatting
    task_feature_dict['created'] = task.created.isoformat()

    # Get duration info, if known
    duration_sec = 'unknown'
    if hasattr(task, 'task_output') and task.task_output is not None:
        try:
            task_output = json.loads(task.task_output)
        except ValueError:
            log.error(
                "Could not parse task output as valid json; task output: %s",
                task.task_output)
        else:
            if 'duration_ms' in task_output:
                duration_sec = int(task_output['duration_ms'] / 1000.0)
    task_feature_dict['duration_sec'] = duration_sec

    # Get progress status message & success information
    success, task_message = get_task_completion_info(task)
    status = _("Complete") if success else _("Incomplete")
    task_feature_dict['status'] = status
    task_feature_dict['task_message'] = task_message

    return task_feature_dict
Пример #12
0
def extract_task_features(task):
    """
    Convert task to dict for json rendering.
    Expects tasks have the following features:
    * task_type (str, type of task)
    * task_input (dict, input(s) to the task)
    * task_id (str, celery id of the task)
    * requester (str, username who submitted the task)
    * task_state (str, state of task eg PROGRESS, COMPLETED)
    * created (datetime, when the task was completed)
    * task_output (optional)
    """
    # Pull out information from the task
    features = ['task_type', 'task_input', 'task_id', 'requester', 'task_state']
    task_feature_dict = {feature: str(getattr(task, feature)) for feature in features}
    # Some information (created, duration, status, task message) require additional formatting
    task_feature_dict['created'] = task.created.isoformat()

    # Get duration info, if known
    duration_sec = 'unknown'
    if hasattr(task, 'task_output') and task.task_output is not None:
        try:
            task_output = json.loads(task.task_output)
        except ValueError:
            log.error("Could not parse task output as valid json; task output: %s", task.task_output)
        else:
            if 'duration_ms' in task_output:
                duration_sec = int(task_output['duration_ms'] / 1000.0)
    task_feature_dict['duration_sec'] = duration_sec

    # Get progress status message & success information
    success, task_message = get_task_completion_info(task)
    status = _("Complete") if success else _("Incomplete")
    task_feature_dict['status'] = status
    task_feature_dict['task_message'] = task_message

    return task_feature_dict
Пример #13
0
 def test_get_info_for_queuing_task(self):
     # get status for a task that is still running:
     instructor_task = self._create_entry()
     succeeded, message = get_task_completion_info(instructor_task)
     self.assertFalse(succeeded)
     self.assertEquals(message, "No status information available")
Пример #14
0
 def test_get_info_for_queuing_task(self):
     # get status for a task that is still running:
     instructor_task = self._create_entry()
     succeeded, message = get_task_completion_info(instructor_task)
     assert not succeeded
     assert message == 'No status information available'
Пример #15
0
 def test_get_info_for_queuing_task(self):
     # get status for a task that is still running:
     instructor_task = self._create_entry()
     succeeded, message = get_task_completion_info(instructor_task)
     self.assertFalse(succeeded)
     self.assertEquals(message, "No status information available")