def testExportsOriginalResultAnywayIfItIsNotStatEntry(self): result = collectors.ArtifactFilesDownloaderResult( original_result=export_test_lib.DataAgnosticConverterTestValue()) converter = file.ArtifactFilesDownloaderResultConverter() converted = list(converter.Convert(self.metadata, result)) # Test that something gets exported and that this something wasn't # produced by ArtifactFilesDownloaderResultConverter. self.assertLen(converted, 1) self.assertNotIsInstance(converted[0], file.ExportedArtifactFilesDownloaderResult)
def testDataAgnosticConverterIsUsedWhenNoSpecificConverterIsDefined(self): original_value = export_test_lib.DataAgnosticConverterTestValue() # There's no converter defined for # export_test_lib.DataAgnosticConverterTestValue, # so we expect DataAgnosticExportConverter to be used. converted_values = list( export.ConvertValues(self.metadata, [original_value])) self.assertLen(converted_values, 1) converted_value = converted_values[0] self.assertEqual(converted_value.__class__.__name__, "AutoExportedDataAgnosticConverterTestValue")
def testConvertedValuesCanBeSerializedAndDeserialized(self): original_value = export_test_lib.DataAgnosticConverterTestValue( string_value="string value", int_value=42, bool_value=True, enum_value=export_test_lib.DataAgnosticConverterTestValue. EnumOption.OPTION_2, urn_value=rdfvalue.RDFURN("aff4:/bar"), datetime_value=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(42)) converted_value = self.ConvertOriginalValue(original_value) serialized = converted_value.SerializeToBytes() deserialized = converted_value.__class__.FromSerializedBytes( serialized) self.assertEqual(converted_value, deserialized)
def testAddsMetadataAndIgnoresRepeatedAndMessagesFields(self): original_value = export_test_lib.DataAgnosticConverterTestValue() converted_value = self.ConvertOriginalValue(original_value) # No 'metadata' field in the original value. self.assertCountEqual([t.name for t in original_value.type_infos], [ "string_value", "int_value", "bool_value", "repeated_string_value", "message_value", "enum_value", "another_enum_value", "urn_value", "datetime_value" ]) # But there's one in the converted value. self.assertCountEqual([t.name for t in converted_value.type_infos], [ "metadata", "string_value", "int_value", "bool_value", "enum_value", "another_enum_value", "urn_value", "datetime_value" ]) # Metadata value is correctly initialized from user-supplied metadata. self.assertEqual(converted_value.metadata.source_urn, rdfvalue.RDFURN("aff4:/foo"))
def testProcessesPrimitiveTypesCorrectly(self): original_value = export_test_lib.DataAgnosticConverterTestValue( string_value="string value", int_value=42, bool_value=True, enum_value=export_test_lib.DataAgnosticConverterTestValue. EnumOption.OPTION_2, urn_value=rdfvalue.RDFURN("aff4:/bar"), datetime_value=rdfvalue.RDFDatetime.FromSecondsSinceEpoch(42)) converted_value = self.ConvertOriginalValue(original_value) self.assertEqual(converted_value.string_value.__class__, original_value.string_value.__class__) self.assertEqual(converted_value.string_value, "string value") self.assertEqual(converted_value.int_value.__class__, original_value.int_value.__class__) self.assertEqual(converted_value.int_value, 42) self.assertEqual(converted_value.bool_value.__class__, original_value.bool_value.__class__) self.assertEqual(converted_value.bool_value, True) self.assertEqual(converted_value.enum_value.__class__, original_value.enum_value.__class__) self.assertEqual(converted_value.enum_value, converted_value.EnumOption.OPTION_2) self.assertIsInstance(converted_value.urn_value, rdfvalue.RDFURN) self.assertEqual(converted_value.urn_value, rdfvalue.RDFURN("aff4:/bar")) self.assertIsInstance(converted_value.datetime_value, rdfvalue.RDFDatetime) self.assertEqual(converted_value.datetime_value, rdfvalue.RDFDatetime.FromSecondsSinceEpoch(42))