def _WriteNewAttributeContainer(self, container): """Writes a new attribute container to the store. Args: container (AttributeContainer): attribute container. """ containers = self._attribute_containers.get(container.CONTAINER_TYPE, None) if containers is None: containers = collections.OrderedDict() self._attribute_containers[container.CONTAINER_TYPE] = containers next_sequence_number = self._GetAttributeContainerNextSequenceNumber( container.CONTAINER_TYPE) identifier = identifiers.FakeIdentifier(next_sequence_number) container.SetIdentifier(identifier) lookup_key = identifier.CopyToString() # Make sure the fake storage preserves the state of the attribute container. container = copy.deepcopy(container) containers[lookup_key] = container if container.CONTAINER_TYPE == self._CONTAINER_TYPE_EVENT_TAG: event_identifier = container.GetEventIdentifier() lookup_key = event_identifier.CopyToString() self._event_tag_per_event_identifier[lookup_key] = container
def _PrepareAttributeContainer(self, attribute_container): """Prepares an attribute container for storage. Args: attribute_container (AttributeContainer): attribute container. Returns: AttributeContainer: copy of the attribute container to store in the fake storage. """ attribute_values_hash = hash(attribute_container.GetAttributeValuesString()) identifier = identifiers.FakeIdentifier(attribute_values_hash) attribute_container.SetIdentifier(identifier) # Make sure the fake storage preserves the state of the attribute container. return copy.deepcopy(attribute_container)
def testGetAttributeContainerByIdentifier(self): """Tests the GetAttributeContainerByIdentifier function.""" test_reader = reader.StorageReader() test_reader._store = fake_store.FakeStore() test_reader._store.Open() try: event_source = event_sources.EventSource() test_reader._store.AddAttributeContainer(event_source) test_identifier = event_source.GetIdentifier() test_container = test_reader.GetAttributeContainerByIdentifier( event_source.CONTAINER_TYPE, test_identifier) self.assertIsNotNone(test_container) test_identifier = identifiers.FakeIdentifier(99) test_container = test_reader.GetAttributeContainerByIdentifier( event_source.CONTAINER_TYPE, test_identifier) self.assertIsNone(test_container) finally: test_reader._store.Close()