def test_dict_to_objects(self): dict_list = importer.parse_csv_string(_TYPICAL_TESTCASE) pynag_objects = importer.dict_to_pynag_objects(dict_list) self.assertEqual(2, len(pynag_objects)) self.assertEqual('generic-service', pynag_objects[0].use) self.assertEqual('generic-host', pynag_objects[1].use) self.assertEqual('service', pynag_objects[0].object_type) self.assertEqual('host', pynag_objects[1].object_type)
def parse_objects_from_form(self): cleaned_data = self.clean() objects = cleaned_data['objects'] object_type = cleaned_data['object_type'] destination_filename = self.cleaned_data['destination_filename'] seperator = cleaned_data['seperator'] parsed_objects = importer.parse_csv_string(objects, seperator=seperator) pynag_objects = importer.dict_to_pynag_objects(parsed_objects, object_type=object_type) for pynag_object in pynag_objects: if destination_filename: pynag_object.set_filename(destination_filename) else: pynag_object.set_filename(pynag_object.get_suggested_filename()) return pynag_objects
def parse_objects_from_form(self): cleaned_data = self.clean() objects = cleaned_data['objects'] object_type = cleaned_data['object_type'] destination_filename = self.cleaned_data['destination_filename'] seperator = cleaned_data['seperator'] parsed_objects = importer.parse_csv_string(objects, seperator=seperator) pynag_objects = importer.dict_to_pynag_objects(parsed_objects, object_type=object_type) for pynag_object in pynag_objects: if destination_filename: pynag_object.set_filename(destination_filename) else: pynag_object.set_filename( pynag_object.get_suggested_filename()) return pynag_objects