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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Tests for the attribute container interface."""
from __future__ import unicode_literals
import unittest
from plaso.containers import interface
from tests import test_lib as shared_test_lib
class AttributeContainerIdentifierTest(shared_test_lib.BaseTestCase):
"""Tests for the attribute container identifier."""
def testCopyToString(self):
"""Tests the CopyToString function."""
identifier = interface.AttributeContainerIdentifier()
expected_identifier_string = '{0:d}'.format(id(identifier))
identifier_string = identifier.CopyToString()
self.assertEqual(identifier_string, expected_identifier_string)
class AttributeContainerTest(shared_test_lib.BaseTestCase):
"""Tests for the attribute container interface."""
# pylint: disable=protected-access
def testCopyToDict(self):
"""Tests the CopyToDict function."""
attribute_container = interface.AttributeContainer()
attribute_container.attribute_name = 'attribute_name'
attribute_container.attribute_value = 'attribute_value'
expected_dict = {
'attribute_name': 'attribute_name',
'attribute_value': 'attribute_value'}
test_dict = attribute_container.CopyToDict()
self.assertEqual(test_dict, expected_dict)
def testGetAttributeNames(self):
"""Tests the GetAttributeNames function."""
attribute_container = interface.AttributeContainer()
attribute_container._protected_attribute = 'protected'
attribute_container.attribute_name = 'attribute_name'
attribute_container.attribute_value = 'attribute_value'
expected_attribute_names = ['attribute_name', 'attribute_value']
attribute_names = sorted(attribute_container.GetAttributeNames())
self.assertEqual(attribute_names, expected_attribute_names)
attribute_container._SERIALIZABLE_PROTECTED_ATTRIBUTES = [
'_protected_attribute']
expected_attribute_names = [
'_protected_attribute', 'attribute_name', 'attribute_value']
attribute_names = sorted(attribute_container.GetAttributeNames())
self.assertEqual(attribute_names, expected_attribute_names)
def testGetAttributes(self):
"""Tests the GetAttributes function."""
attribute_container = interface.AttributeContainer()
attribute_container._protected_attribute = 'protected'
attribute_container.attribute_name = 'attribute_name'
attribute_container.attribute_value = 'attribute_value'
expected_attributes = [
('attribute_name', 'attribute_name'),
('attribute_value', 'attribute_value')]
attributes = sorted(attribute_container.GetAttributes())
self.assertEqual(attributes, expected_attributes)
attribute_container._SERIALIZABLE_PROTECTED_ATTRIBUTES = [
'_protected_attribute']
expected_attributes = [
('_protected_attribute', 'protected'),
('attribute_name', 'attribute_name'),
('attribute_value', 'attribute_value')]
attributes = sorted(attribute_container.GetAttributes())
self.assertEqual(attributes, expected_attributes)
def testGetAttributeValueHash(self):
"""Tests the GetAttributeValuesHash function."""
attribute_container = interface.AttributeContainer()
attribute_container._protected_attribute = 'protected'
attribute_container.attribute_name = 'attribute_name'
attribute_container.attribute_value = 'attribute_value'
attribute_values_hash1 = attribute_container.GetAttributeValuesHash()
attribute_container.attribute_value = 'changes'
attribute_values_hash2 = attribute_container.GetAttributeValuesHash()
self.assertNotEqual(attribute_values_hash1, attribute_values_hash2)
attribute_container.attribute_value = 'attribute_value'
attribute_container._SERIALIZABLE_PROTECTED_ATTRIBUTES = [
'_protected_attribute']
attribute_values_hash2 = attribute_container.GetAttributeValuesHash()
self.assertNotEqual(attribute_values_hash1, attribute_values_hash2)
def testGetAttributeValuesString(self):
"""Tests the GetAttributeValuesString function."""
attribute_container = interface.AttributeContainer()
attribute_container._protected_attribute = 'protected'
attribute_container.attribute_name = 'attribute_name'
attribute_container.attribute_value = 'attribute_value'
attribute_values_string1 = attribute_container.GetAttributeValuesString()
attribute_container.attribute_value = 'changes'
attribute_values_string2 = attribute_container.GetAttributeValuesString()
self.assertNotEqual(attribute_values_string1, attribute_values_string2)
attribute_container.attribute_value = 'attribute_value'
attribute_container._SERIALIZABLE_PROTECTED_ATTRIBUTES = [
'_protected_attribute']
attribute_values_string2 = attribute_container.GetAttributeValuesString()
self.assertNotEqual(attribute_values_string1, attribute_values_string2)
def testGetIdentifier(self):
"""Tests the GetIdentifier function."""
attribute_container = interface.AttributeContainer()
identifier = attribute_container.GetIdentifier()
self.assertIsNotNone(identifier)
def testGetSessionIdentifier(self):
"""Tests the GetSessionIdentifier function."""
attribute_container = interface.AttributeContainer()
session_identifier = attribute_container.GetSessionIdentifier()
self.assertIsNone(session_identifier)
def testSetIdentifier(self):
"""Tests the SetIdentifier function."""
attribute_container = interface.AttributeContainer()
attribute_container.SetIdentifier(None)
def testSetSessionIdentifier(self):
"""Tests the SetSessionIdentifier function."""
attribute_container = interface.AttributeContainer()
attribute_container.SetSessionIdentifier(None)
if __name__ == '__main__':
unittest.main()
|