def from_csv(cls, rows): _ = rows.pop(0) settings = [] for row in rows: _, subcategory, _, _, audit_option, _, _ = row.split(',') if subcategory: settings.append(SubcategorySetting.from_csv(row)) elif audit_option: settings.append(AuditOption.from_csv(row)) else: settings.append(GlobalObjectAccessAuditSetting.from_csv(row)) return cls(settings=settings)
def test_to_csv(self): option_value = OptionValue() audit_option = AuditOption(type='CrashOnAuditFail', value=option_value) self.assertEqual(audit_option.to_csv(), ',,Option:CrashOnAuditFail,,Disabled,,0\n')
def test_from_csv(self): audit_option = AuditOption.from_csv(',,Option:CrashOnAuditFail,,Disabled,,0\n') self.assertIsInstance(audit_option, AuditOption)
def test_invalid_value_type(self): with self.assertRaises(TypeError): AuditOption(type='CrashOnAuditFail', value=None)
def test_valid_value(self): option_value = OptionValue() audit_option = AuditOption(type='CrashOnAuditFail', value=option_value) self.assertEqual(audit_option.value.enabled, False)
def test_invalid_type_type(self): option_value = OptionValue() with self.assertRaises(TypeError): AuditOption(type=None, value=option_value)
def test_valid_type(self): option_value = OptionValue() audit_option = AuditOption(type='CrashOnAuditFail', value=option_value) self.assertEqual(audit_option.type, 'CrashOnAuditFail')