def test_new_record(self): from datetime import date expected = ('AAPL', date(2014, 4, 1), 5) dml.upsert_records(self.conn, [expected], self.upsert_statement) result = fetch_one_result(self.conn, self.result_query) self.assertEqual(expected, result)
def test_conflict_no_update(self): expected = ('AAPL', date(2014, 4, 1), 5) second = ('AAPL', date(2013, 4, 1), 5) dml.upsert_records(self.conn, [expected], self.upsert_statement) dml.upsert_records(self.conn, [second], self.upsert_statement) result = fetch_one_result(self.conn, self.result_query) self.assertEqual(expected, result)
def test_conflict_replace_record(self): first = ('AAPL', date(2014, 4, 1), 5) expected = ('AAPL', date(2015, 4, 1), 5) dml.upsert_records(self.conn, [first], self.upsert_statement) dml.upsert_records(self.conn, [expected], self.upsert_statement) result = fetch_one_result(self.conn, self.result_query) self.assertEqual(expected, result)
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)