def test_with_update(self, pet): sql = django_pg_upsert.Upsert(pet, fields=["name"], update=["age"]).as_sql() assert sql == [( 'INSERT INTO "starwars_pet" ("name", "alias_name", "age", "created_at", "updated_at", "owner_id") VALUES (%s, %s, %s, %s, %s, %s) ON CONFLICT ("name") DO UPDATE SET age = EXCLUDED.age', ( "dog", None, 12, datetime.datetime(2020, 1, 1, 12, 0), datetime.datetime(2020, 1, 1, 12, 0), None, ), )]
def test_without_pass_params(self, pet): sql = django_pg_upsert.Upsert(pet).as_sql() assert sql == [( 'INSERT INTO "starwars_pet" ("name", "alias_name", "age", "created_at", "updated_at", "owner_id") VALUES (%s, %s, %s, %s, %s, %s) ON CONFLICT DO NOTHING', ( "dog", None, 12, datetime.datetime(2020, 1, 1, 12, 0), datetime.datetime(2020, 1, 1, 12, 0), None, ), )]
def test_with_constraint(self, pet): sql = django_pg_upsert.Upsert( pet, constraint="starwars_pet_name_key").as_sql() assert sql == [( 'INSERT INTO "starwars_pet" ("name", "alias_name", "age", "created_at", "updated_at", "owner_id") VALUES (%s, %s, %s, %s, %s, %s) ON CONFLICT ON CONSTRAINT starwars_pet_name_key DO NOTHING', ( "dog", None, 12, datetime.datetime(2020, 1, 1, 12, 0), datetime.datetime(2020, 1, 1, 12, 0), None, ), )]