File: tasks.py

package info (click to toggle)
plaso 20201007-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 519,924 kB
  • sloc: python: 79,002; sh: 629; xml: 72; sql: 14; vhdl: 11; makefile: 10
file content (131 lines) | stat: -rw-r--r-- 4,191 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Tests for the tasks attribute containers."""

from __future__ import unicode_literals

import time
import unittest
import uuid

from plaso.containers import tasks

from tests import test_lib as shared_test_lib


class TaskTest(shared_test_lib.BaseTestCase):
  """Tests for the task attribute container."""

  # TODO: replace by GetAttributeNames test
  def testCopyToDict(self):
    """Tests the CopyToDict function."""
    session_identifier = '{0:s}'.format(uuid.uuid4().hex)
    task = tasks.Task(session_identifier=session_identifier)

    self.assertIsNotNone(task.identifier)
    self.assertIsNotNone(task.start_time)
    self.assertIsNone(task.completion_time)

    expected_dict = {
        'aborted': False,
        'has_retry': False,
        'identifier': task.identifier,
        'session_identifier': task.session_identifier,
        'start_time': task.start_time}

    test_dict = task.CopyToDict()

    self.assertEqual(test_dict, expected_dict)

  def testCreateRetryTask(self):
    """Tests the CreateRetryTask function."""
    session_identifier = '{0:s}'.format(uuid.uuid4().hex)
    task = tasks.Task(session_identifier=session_identifier)
    task.path_spec = 'test_path_spec'

    retry_task = task.CreateRetryTask()
    self.assertNotEqual(retry_task.identifier, task.identifier)
    self.assertTrue(task.has_retry)
    self.assertFalse(retry_task.has_retry)
    self.assertEqual(retry_task.path_spec, task.path_spec)

  def testCreateTaskCompletion(self):
    """Tests the CreateTaskCompletion function."""
    session_identifier = '{0:s}'.format(uuid.uuid4().hex)
    task = tasks.Task(session_identifier=session_identifier)

    task_completion = task.CreateTaskCompletion()
    self.assertIsNotNone(task_completion)

  def testCreateTaskStart(self):
    """Tests the CreateTaskStart function."""
    session_identifier = '{0:s}'.format(uuid.uuid4().hex)
    task = tasks.Task(session_identifier=session_identifier)

    task_start = task.CreateTaskStart()
    self.assertIsNotNone(task_start)

  def testUpdateProcessingTime(self):
    """Tests the UpdateProcessingTime function."""
    session_identifier = '{0:s}'.format(uuid.uuid4().hex)
    task = tasks.Task(session_identifier=session_identifier)

    self.assertIsNone(task.last_processing_time)

    task.UpdateProcessingTime()
    self.assertIsNotNone(task.last_processing_time)


class TaskCompletionTest(shared_test_lib.BaseTestCase):
  """Tests for the task completion attribute container."""

  # TODO: replace by GetAttributeNames test
  def testCopyToDict(self):
    """Tests the CopyToDict function."""
    session_identifier = '{0:s}'.format(uuid.uuid4().hex)
    timestamp = int(time.time() * 1000000)
    task_identifier = '{0:s}'.format(uuid.uuid4().hex)
    task_completion = tasks.TaskCompletion(
        identifier=task_identifier, session_identifier=session_identifier)
    task_completion.timestamp = timestamp

    self.assertEqual(task_completion.identifier, task_identifier)

    expected_dict = {
        'aborted': False,
        'identifier': task_completion.identifier,
        'session_identifier': task_completion.session_identifier,
        'timestamp': timestamp}

    test_dict = task_completion.CopyToDict()

    self.assertEqual(test_dict, expected_dict)


class TaskStartTest(shared_test_lib.BaseTestCase):
  """Tests for the task start attribute container."""

  # TODO: replace by GetAttributeNames test
  def testCopyToDict(self):
    """Tests the CopyToDict function."""
    session_identifier = '{0:s}'.format(uuid.uuid4().hex)
    timestamp = int(time.time() * 1000000)
    task_identifier = '{0:s}'.format(uuid.uuid4().hex)
    task_start = tasks.TaskStart(
        identifier=task_identifier, session_identifier=session_identifier)
    task_start.timestamp = timestamp

    self.assertEqual(task_start.identifier, task_identifier)

    expected_dict = {
        'identifier': task_start.identifier,
        'session_identifier': session_identifier,
        'timestamp': timestamp}

    test_dict = task_start.CopyToDict()

    self.assertEqual(test_dict, expected_dict)


if __name__ == '__main__':
  unittest.main()