Пример #1
0
    def test_when_all_columns_are_primary_keys(self):
        upserter = dml.UpsertPrimaryKey(self.table_name, self.columns,
                                        self.primary_keys)

        expected = 'INSERT INTO foobar (foo, bar) VALUES (%s, %s)'
        result = upserter.query

        self.assertSQLStatementEqual(expected, result)
Пример #2
0
    def test_when_all_columns_are_primary_keys(self):
        upserter = dml.UpsertPrimaryKey(self.table_name, self.columns,
                                        self.primary_keys)

        expected = ('INSERT INTO foobar AS current (foo, bar) VALUES (%s, %s)'
                    ' ON CONFLICT (foo, bar) DO NOTHING')
        result = upserter.query

        self.assertSQLStatementEqual(expected, result)
Пример #3
0
    def test_update_on_primary_key(self):
        primary_keys = ['ticker']
        upserter = dml.UpsertPrimaryKey(self.table_name, self.column_names,
                                        primary_keys)
        first = ('AAPL', date(2014, 4, 1), 5)
        expected = ('AAPL', date(2014, 4, 1), 6)

        upserter(self.conn, [first])
        upserter(self.conn, [expected])

        result = fetch_one_result(self.conn, self.result_query)

        self.assertEqual(expected, result)