Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
 def test_parse_csv_file(self):
     with open(self.filename, 'w') as f:
         f.write(_TYPICAL_TESTCASE)
     objects_from_file = importer.parse_csv_file(self.filename)
     objects_from_string = importer.parse_csv_string(_TYPICAL_TESTCASE)
     self.assertEqual(objects_from_string, objects_from_file)
Пример #6
0
 def test_parse_csv_string_empty(self):
     objects = importer.parse_csv_string('')
     self.assertEqual([], objects)
Пример #7
0
 def test_parse_csv_string(self):
     objects = importer.parse_csv_string(_TYPICAL_TESTCASE)
     self.assertEqual(2, len(objects))
     self.assertEqual('generic-service', objects[0]['use'])
     self.assertEqual('generic-host', objects[1]['use'])
Пример #8
0
 def test_parse_csv_file(self):
     with open(self.filename, 'w') as f:
         f.write(_TYPICAL_TESTCASE)
     objects_from_file = importer.parse_csv_file(self.filename)
     objects_from_string = importer.parse_csv_string(_TYPICAL_TESTCASE)
     self.assertEqual(objects_from_string, objects_from_file)
Пример #9
0
 def test_parse_csv_string_empty(self):    
     objects = importer.parse_csv_string('')
     self.assertEqual([], objects)
Пример #10
0
 def test_parse_csv_string(self):
     objects = importer.parse_csv_string(_TYPICAL_TESTCASE)
     self.assertEqual(2, len(objects))
     self.assertEqual('generic-service', objects[0]['use'])
     self.assertEqual('generic-host', objects[1]['use'])