Exemple #1
0
class TestLookup(unittest.TestCase):

    def setUp(self):
        self.translator = IdTranslator()

    def test_001_translate(self):
        self.assertNotEqual(self.translator, None)

        pass_1 = [ ['abc', 1, 10], ['abc', 2, 20], ['abc', None, None] ]
        for vals in pass_1:
            self.translator.set_value(vals[0], vals[1], vals[2])

        for vals in pass_1:
            self.assertEqual(self.translator.get_value(vals[0], vals[1]), vals[2])
            if vals[2]:
                self.assertEqual(self.translator.get_value(vals[0], vals[2]), -1)
                self.assertEqual(self.translator.get_value('hello', vals[2]), -1)

        pass_2 = [ ['abc', 1, 11], ['cba', 2, 20] ]
        for vals in pass_2:
            self.translator.set_value(vals[0], vals[1], vals[2])
        
        for vals in pass_2:
            self.assertEqual(self.translator.get_value(vals[0], vals[1]), vals[2])
            self.assertEqual(self.translator.get_value(vals[0], vals[2]), -1)
            self.assertEqual(self.translator.get_value('hello', vals[2]), -1)
     
    def test_002_none(self):
        self.assertEqual(self.translator.get_value('abc', None), None)
Exemple #2
0
class TestLookup(unittest.TestCase):
    def setUp(self):
        self.translator = IdTranslator()

    def test_001_translate(self):
        self.assertNotEqual(self.translator, None)

        pass_1 = [['abc', 1, 10], ['abc', 2, 20], ['abc', None, None]]
        for vals in pass_1:
            self.translator.set_value(vals[0], vals[1], vals[2])

        for vals in pass_1:
            self.assertEqual(self.translator.get_value(vals[0], vals[1]),
                             vals[2])
            if vals[2]:
                self.assertEqual(self.translator.get_value(vals[0], vals[2]),
                                 -1)
                self.assertEqual(self.translator.get_value('hello', vals[2]),
                                 -1)

        pass_2 = [['abc', 1, 11], ['cba', 2, 20]]
        for vals in pass_2:
            self.translator.set_value(vals[0], vals[1], vals[2])

        for vals in pass_2:
            self.assertEqual(self.translator.get_value(vals[0], vals[1]),
                             vals[2])
            self.assertEqual(self.translator.get_value(vals[0], vals[2]), -1)
            self.assertEqual(self.translator.get_value('hello', vals[2]), -1)

    def test_002_none(self):
        self.assertEqual(self.translator.get_value('abc', None), None)
Exemple #3
0
class SlurpSession(object):
    def __init__(self):
        self.ids = IdTranslator()
        self.hostid = 0
        self.catalogid = 0

    def setup_catalog(self, db, catalog):
        rv = db.query("select id from hosts where hostname=? and system=?",
                                        [catalog.hostname, catalog.system])
        if rv:
            self.hostid = rv[0][0]
        else:
            self.hostid = db.insert_row('hosts', ['hostname', 'system'], 
                                        [catalog.hostname, catalog.system])
        if not self.hostid:
            return False
        rv = db.query("select id_local from catalog hosts where lc_filename=? and host=?",
                                   [catalog.filename.lower(), self.hostid])
        if rv:
            self.catalogid = rv[0][0]
        else: 
            self.catalogid = db.insert_row('catalog', 
                                      ['filename', 'lc_filename', 'host'], 
                 [catalog.filename, catalog.filename.lower(), self.hostid])

        if not self.catalogid:
            return False
        return True

    def set_value(self, table, a, b):
        self.ids.set_value(table, a, b)

    def get_value(self, table, a):
        return self.ids.get_value(table, a)

    def dump(self):
        self.ids.dump()