

def test_prefix_search_simple(self):
    ' Test the simple prefix search function.\n        '
    schema = {
        'id': self.schema_attrs['id'],
    }
    query_keys = dict()
    query_keys['testing testing'] = 'description'
    query_keys['1.2.3.4'] = 'prefix'
    query_str = ''
    for (key, val) in query_keys.items():
        if (val == 'description'):
            query_str += ('"%s" ' % key)
        else:
            query_str += ('%s ' % key)
    res = self.nipap.smart_search_prefix(self.auth, schema, query_str)
    for interp in res['interpretation']:
        self.assertEqual((interp['string'] in query_keys), True, ('Function returned unknown interpreted string %s' % interp['string']))
    prefix_attrs = {
        'authoritative_source': 'nipap-test',
        'prefix': '1.3.3.77/32',
        'type': 'host',
        'description': 'test-ish prefix',
        'comment': 'Test prefix #77! ;)',
    }
    self.nipap.add_prefix(self.auth, schema, prefix_attrs)
    res = self.nipap.smart_search_prefix(self.auth, schema, '1.3.3.77 "-ish" ')
    self.assertEqual(res['result'][(- 1)]['prefix'], '1.3.3.77/32', 'Prefix not found')

dataset/ETHPy150Open SpriteLink/NIPAP/tests/nipapbase.py NipapTest.test_prefix_search_simple/original