Example #1
0
 def test_read_simple(self):
     pg_python.pg_server("test_db", "postgres", "@pgtest", "localhost",
                         False)
     create_rows()
     rows = pg_python.read(test_table, [COL_1], {COL_2: 'read'})
     self.assertEqual(len(rows), 1)
     self.assertEqual(rows[0][COL_1], 'title1')
     print("Read simple done")
     clear_table()
Example #2
0
 def test_read_greater_than(self):
     pg_python.pg_server("test_db", "postgres", "@pgtest", "localhost",
                         False)
     create_rows()
     rows = pg_python.read(test_table, [COL_1], {COL_5 + " >": 10})
     self.assertEqual(len(rows), 1)
     self.assertEqual(rows[0][COL_1], 'title6')
     print("Read greater than done")
     clear_table()
Example #3
0
 def test_single_update(self):
     pg_python.pg_server("test_db", "postgres", "@pgtest", "localhost",
                         False)
     create_rows()
     pg_python.update(test_table, {COL_4: 'updated_name1'},
                      {COL_1: 'title1%'},
                      clause='ilike')
     title1 = pg_python.read(test_table, [COL_4], {COL_1: 'title15'})
     self.assertEqual(title1[0][COL_4], 'updated_name1')
     clear_table()
Example #4
0
 def test_update_raw(self):
     pg_python.pg_server("test_db", "postgres", "@pgtest", "localhost",
                         False)
     create_rows()
     updates = pg_python.update_raw("update " + test_table + " set " +
                                    COL_4 + "= 'updated_name1' where " +
                                    COL_1 + " ilike 'title1%'")
     title1 = pg_python.read(test_table, [COL_4], {COL_1: 'title15'})
     self.assertEqual(title1[0][COL_4], 'updated_name1')
     self.assertEqual(updates, 2)
     print("UPdate raw done")
     clear_table()
Example #5
0
 def test_read_in(self):
     pg_python.pg_server("test_db", "postgres", "@pgtest", "localhost",
                         False)
     create_rows()
     values = ['title15', 'title1', 'title2', 'title3']
     rows = pg_python.read(test_table, [COL_1], {COL_1: values},
                           clause=" in ")
     read_values = []
     for row in rows:
         read_values.append(row.get(COL_1))
     self.assertEqual(sorted(read_values), sorted(values))
     print("Read IN done")
     clear_table()
Example #6
0
    def test_update(self):
        pg_python.pg_server("test_db", "postgres", "@pgtest", "localhost",
                            False)
        create_rows()
        dict_lst = [{
            COL_1: 'title1',
            UPDATE: 'updated_name1'
        }, {
            COL_1: 'title2',
            UPDATE: "update'd_name2"
        }]
        pg_python.update_multiple(test_table, COL_4, [COL_1], dict_lst)
        title1 = pg_python.read(test_table, [COL_4], {COL_1: 'title1'})
        title2 = pg_python.read(test_table, [COL_4], {COL_1: 'title2'})
        self.assertEqual(title1[0][COL_4], 'updated_name1')
        self.assertEqual(title2[0][COL_4], "update'd_name2")

        clear_table()
Example #7
0
 def test_multiple_insert(self):
     pg_python.pg_server("test_db", "postgres", "@pgtest", "localhost",
                         False)
     column_to_insert = [COL_1, COL_3]
     insert_dict_list = [{
         COL_1: "insert1",
         COL_3: 1
     }, {
         COL_3: 2,
         COL_1: "insert2"
     }, {
         COL_1: "insert3",
         COL_3: 3
     }]
     pg_python.insert_multiple(test_table, column_to_insert,
                               insert_dict_list)
     val1 = pg_python.read(test_table, [COL_1], {COL_3: 1})
     val2 = pg_python.read(test_table, [COL_1], {COL_3: 2})
     val3 = pg_python.read(test_table, [COL_1], {COL_3: 3})
     values = [val1[0][COL_1], val2[0][COL_1], val3[0][COL_1]]
     self.assertEqual(values, ["insert1", "insert2", "insert3"])
     clear_table()
Example #8
0
import pg_python

pg_python.pg_server("crawler", "postgres", "@hawkerIndia", "postgres-master.hawker.news", False)
pg_python.delete("xyz", {"key": "1000", "name": "2000"})