Exemplo n.º 1
0
class TestConfig(AlignakTest):
    # setUp is inherited from AlignakTest

    def create_db(self):
        self.db = DB(table_prefix='test_')

    def test_create_insert_query(self):
        self.create_db()
        data = OrderedDict((
            ('id', "1"),
            ("is_master", True),
            ('plop', "master of the universe")))
        q = self.db.create_insert_query('instances', data)
        expected = "INSERT INTO test_instances  (id , is_master , plop  ) " \
                   "VALUES ('1' , '1' , 'master of the universe'  )"
        self.assertEqual(expected, q)

        # Now some UTF8 funny characters
        data = OrderedDict((
            ('id', "1"),
            ("is_master", True),
            ('plop', u'£°é§')))
        q = self.db.create_insert_query('instances', data)
        c = u"INSERT INTO test_instances  (id , is_master , plop  ) VALUES ('1' , '1' , '£°é§'  )"
        print type(q), type(c)
        print len(q), len(c)

        self.assertEqual(c, q)

    def test_update_query(self):
        self.create_db()
        data = OrderedDict((
            ('id', "1"),
            ("is_master", True),
            ('plop', "master of the universe")))
        where = OrderedDict((
            ('id', "1"),
            ("is_master", True)))
        q = self.db.create_update_query('instances', data, where)
        # beware of the last space
        print "Q", q
        self.assertEqual("UPDATE test_instances set plop='master of the universe'  WHERE id='1' and is_master='1' ", q)

        # Now some UTF8 funny characters
        data = OrderedDict((
            ('id', "1"),
            ("is_master", True),
            ('plop', u'£°é§')))
        where = OrderedDict((
            ('id', "£°é§"),
            ("is_master", True)))
        q = self.db.create_update_query('instances', data, where)
        #print "Q", q
        c = u"UPDATE test_instances set plop='£°é§'  WHERE id='£°é§' and is_master='1'"
        self.assertEqual(c.strip(), q.strip())
Exemplo n.º 2
0
class TestConfig(AlignakTest):
    # setUp is inherited from AlignakTest

    def create_db(self):
        self.db = DB(table_prefix='test_')

    def test_create_insert_query(self):
        self.create_db()
        data = OrderedDict((('id', "1"), ("is_master", True),
                            ('plop', "master of the universe")))
        q = self.db.create_insert_query('instances', data)
        expected = "INSERT INTO test_instances  (id , is_master , plop  ) " \
                   "VALUES ('1' , '1' , 'master of the universe'  )"
        self.assertEqual(expected, q)

        # Now some UTF8 funny characters
        data = OrderedDict(
            (('id', "1"), ("is_master", True), ('plop', u'£°é§')))
        q = self.db.create_insert_query('instances', data)
        c = u"INSERT INTO test_instances  (id , is_master , plop  ) VALUES ('1' , '1' , '£°é§'  )"
        print type(q), type(c)
        print len(q), len(c)

        self.assertEqual(c, q)

    def test_update_query(self):
        self.create_db()
        data = OrderedDict((('id', "1"), ("is_master", True),
                            ('plop', "master of the universe")))
        where = OrderedDict((('id', "1"), ("is_master", True)))
        q = self.db.create_update_query('instances', data, where)
        # beware of the last space
        print "Q", q
        self.assertEqual(
            "UPDATE test_instances set plop='master of the universe'  WHERE id='1' and is_master='1' ",
            q)

        # Now some UTF8 funny characters
        data = OrderedDict(
            (('id', "1"), ("is_master", True), ('plop', u'£°é§')))
        where = OrderedDict((('id', "£°é§"), ("is_master", True)))
        q = self.db.create_update_query('instances', data, where)
        #print "Q", q
        c = u"UPDATE test_instances set plop='£°é§'  WHERE id='£°é§' and is_master='1'"
        self.assertEqual(c.strip(), q.strip())
Exemplo n.º 3
0
 def create_db(self):
     self.db = DB(table_prefix='test_')
Exemplo n.º 4
0
 def create_db(self):
     self.db = DB(table_prefix='test_')