def test_three_lines_with_two_rows_should_be_counted_as_three(self):
     data = (b"room1:10.0.0.186:myorg:SW:1:public:parrot::\n"
             b"\n"
             b"room1:10.0.0.187:myorg:OTHER::parrot::\n")
     b = bulkparse.NetboxBulkParser(data)
     out_data = list(b)
     self.assertEquals(b.line_num, 3)
 def test_two_rows_returned_with_empty_lines_in_input(self):
     data = (b"room1:10.0.0.186:myorg:SW:SNMP v1 read profile::\n"
             b"\n"
             b"room1:10.0.0.187:myorg:OTHER:SNMP v1 read profile::\n")
     b = bulkparse.NetboxBulkParser(data)
     out_data = list(b)
     assert len(out_data) == 2
 def test_two_rows_returned_with_empty_lines_in_input(self):
     data = (b"room1:10.0.0.186:myorg:SW:1:public:parrot::\n"
             b"\n"
             b"room1:10.0.0.187:myorg:OTHER::parrot::\n")
     b = bulkparse.NetboxBulkParser(data)
     out_data = list(b)
     self.assertEquals(len(out_data), 2)
 def test_three_lines_with_two_rows_should_be_counted_as_three(self):
     data = (b"room1:10.0.0.186:myorg:SW:SNMP v1 read profile::\n"
             b"\n"
             b"room1:10.0.0.187:myorg:OTHER:SNMP v2c read profile::\n")
     b = bulkparse.NetboxBulkParser(data)
     out_data = list(b)
     assert b.line_num == 3
Exemple #5
0
 def test_invalid_room_gives_error(self):
     data = 'invalid:10.0.90.252:myorg:SW:{}::'.format(
         self.read_profile.name, )
     parser = bulkparse.NetboxBulkParser(data)
     importer = bulkimport.NetboxImporter(parser)
     _line_num, objects = six.next(importer)
     self.assertTrue(isinstance(objects, bulkimport.DoesNotExist))
Exemple #6
0
    def test_netbox_groups_are_set(self):
        data = 'myroom:10.0.90.10:myorg:SRV:::fileserver::WEB:UNIX:MAIL'
        parser = bulkparse.NetboxBulkParser(data)
        importer = bulkimport.NetboxImporter(parser)
        _line_num, objects = six.next(importer)

        netboxgroups = [o for o in objects if isinstance(o, manage.NetboxCategory)]
        self.assertTrue(len(netboxgroups) > 0, objects)
Exemple #7
0
    def test_netbox_function_is_set(self):
        data = 'myroom:10.0.90.252:myorg:SW:1:public:::does things:'
        parser = bulkparse.NetboxBulkParser(data)
        importer = bulkimport.NetboxImporter(parser)
        _line_num, objects = six.next(importer)

        types = dict((type(c), c) for c in objects)
        self.assertTrue(manage.NetboxInfo in types, types)
Exemple #8
0
    def test_simple_import_yields_netbox_and_device_model(self):
        data = 'myroom:10.0.90.252:myorg:SW:1:public::'
        parser = bulkparse.NetboxBulkParser(data)
        importer = bulkimport.NetboxImporter(parser)
        _line_num, objects = six.next(importer)

        self.assertTrue(isinstance(objects, list), repr(objects))
        self.assertTrue(len(objects) == 1, repr(objects))
        self.assertTrue(isinstance(objects[0], manage.Netbox), objects[0])
Exemple #9
0
    def test_netbox_function_is_set(self):
        data = 'myroom:10.0.90.252:myorg:SW:{}::does things:'.format(
            self.read_profile.name, )
        parser = bulkparse.NetboxBulkParser(data)
        importer = bulkimport.NetboxImporter(parser)
        _line_num, objects = next(importer)

        types = dict((type(c), c) for c in objects)
        self.assertTrue(manage.NetboxInfo in types, types)
Exemple #10
0
    def test_server_import_yields_netbox_and_device_model(self):
        data = 'myroom:10.0.90.253:myorg:SRV'
        parser = bulkparse.NetboxBulkParser(data)
        importer = bulkimport.NetboxImporter(parser)
        _line_num, objects = six.next(importer)

        self.assertTrue(isinstance(objects, list), repr(objects))
        self.assertTrue(len(objects) == 1, repr(objects))
        self.assertTrue(any(isinstance(o, manage.Netbox) for o in objects), msg=objects)
 def test_short_line_should_raise_error_with_correct_details(self):
     data = b"room1:10.0.0.8"
     b = bulkparse.NetboxBulkParser(data)
     try:
         six.next(b)
     except bulkparse.RequiredFieldMissing as error:
         assert error.line_num == 1
         assert error.missing_field == 'orgid'
     else:
         self.fail("No exception raised")
Exemple #12
0
    def test_simple_import_yields_objects_with_proper_values(self):
        data = 'myroom:10.0.90.252:myorg:SW:{}::'.format(
            self.read_profile.name, )
        parser = bulkparse.NetboxBulkParser(data)
        importer = bulkimport.NetboxImporter(parser)
        _line_num, objects = six.next(importer)

        (netbox, profile) = objects
        self.assertEqual(netbox.ip, '10.0.90.252')
        self.assertEqual(netbox.room_id, 'myroom')
        self.assertEqual(netbox.organization_id, 'myorg')
        self.assertEqual(netbox.category_id, 'SW')
        self.assertEqual(profile.profile, self.read_profile)
Exemple #13
0
    def test_simple_import_yields_objects_with_proper_values(self):
        data = 'myroom:10.0.90.252:myorg:SW:1:public::'
        parser = bulkparse.NetboxBulkParser(data)
        importer = bulkimport.NetboxImporter(parser)
        _line_num, objects = six.next(importer)

        (netbox, ) = objects
        self.assertEqual(netbox.ip, '10.0.90.252')
        self.assertEqual(netbox.room_id, 'myroom')
        self.assertEqual(netbox.organization_id, 'myorg')
        self.assertEqual(netbox.category_id, 'SW')
        self.assertEqual(netbox.snmp_version, '1')
        self.assertEqual(netbox.read_only, 'public')
 def test_parse_single_line_yields_columns(self):
     data = (
         b"room1:10.0.0.186:myorg:SW:1:public:secret:amaster:doesthings:"
         b"key=value:blah1:blah2")
     b = bulkparse.NetboxBulkParser(data)
     out_data = six.next(b)
     self.assertTrue(isinstance(out_data, dict), out_data)
     self.assertEquals(out_data['roomid'], 'room1')
     self.assertEquals(out_data['ip'], '10.0.0.186')
     self.assertEquals(out_data['orgid'], 'myorg')
     self.assertEquals(out_data['catid'], 'SW')
     self.assertEquals(out_data['master'], 'amaster')
     self.assertEquals(out_data['data'], 'key=value')
     self.assertEquals(out_data['netboxgroup'], ['blah1', 'blah2'])
Exemple #15
0
    def test_simple_import_yields_netbox_and_device_model(self):
        data = 'myroom:10.0.90.252:myorg:SW:{}::'.format(
            self.read_profile.name, )
        parser = bulkparse.NetboxBulkParser(data)
        importer = bulkimport.NetboxImporter(parser)
        _line_num, objects = six.next(importer)

        self.assertTrue(isinstance(objects, list), repr(objects))
        self.assertTrue(len(objects) == 2, repr(objects))
        self.assertTrue(any(isinstance(o, manage.Netbox) for o in objects),
                        msg=objects)
        self.assertTrue(any(
            isinstance(o, manage.NetboxProfile) for o in objects),
                        msg=objects)
 def test_parse_single_line_yields_columns(self):
     data = (
         b"room1:10.0.0.186:myorg:SW:SNMP v2c read profile:amaster:doesthings:"
         b"key=value:blah1:blah2")
     b = bulkparse.NetboxBulkParser(data)
     out_data = six.next(b)
     assert isinstance(out_data, dict)
     assert out_data['roomid'] == 'room1'
     assert out_data['ip'] == '10.0.0.186'
     assert out_data['orgid'] == 'myorg'
     assert out_data['catid'] == 'SW'
     assert out_data['master'] == 'amaster'
     assert out_data['data'] == 'key=value'
     assert out_data['netboxgroup'] == ['blah1', 'blah2']
 def test_invalid_ip_should_raise_error(self):
     data = b"room1:10.0.x.x:myorg:SW:SNMP v2c read profile::\n"
     b = bulkparse.NetboxBulkParser(data)
     with pytest.raises(bulkparse.InvalidFieldValue):
         six.next(b)
 def test_short_line_should_raise_error(self):
     data = b"room1:10.0.0.8"
     b = bulkparse.NetboxBulkParser(data)
     with pytest.raises(bulkparse.RequiredFieldMissing):
         b.__next__()
 def test_parse_returns_iterator(self):
     data = b"room1:10.0.0.186:myorg:OTHER::parrot::"
     b = bulkparse.NetboxBulkParser(data)
     self.assertTrue(hasattr(b, '__next__'))
 def test_parse_single_line_should_yield_value(self):
     data = b"room1:10.0.0.186:myorg:OTHER::parrot::"
     b = bulkparse.NetboxBulkParser(data)
     out_data = six.next(b)
     self.assertTrue(out_data is not None)
 def test_parse_single_line_should_yield_value(self):
     data = b"room1:10.0.0.186:myorg:OTHER:SNMP v2c read profile:::"
     b = bulkparse.NetboxBulkParser(data)
     out_data = six.next(b)
     assert (out_data is not None)
 def test_parse_returns_iterator(self):
     data = b"room1:10.0.0.186:myorg:OTHER:SNMP v1 read profile:::"
     b = bulkparse.NetboxBulkParser(data)
     assert (hasattr(b, '__next__'))
 def test_invalid_ip_should_raise_error(self):
     data = b"room1:10.0.x.x:myorg:SW:public:parrot::\n"
     b = bulkparse.NetboxBulkParser(data)
     self.assertRaises(bulkparse.InvalidFieldValue, lambda: six.next(b))
 def test_short_line_should_raise_error(self):
     data = b"room1:10.0.0.8"
     b = bulkparse.NetboxBulkParser(data)
     self.assertRaises(bulkparse.RequiredFieldMissing, b.__next__)
Exemple #25
0
 def parse_to_objects(data):
     parser = bulkparse.NetboxBulkParser(data)
     importer = bulkimport.NetboxImporter(parser)
     _line_num, objects = six.next(importer)
     return objects