Skip to content

Commit

Permalink
Test that a conditional upsert doesn't return anything if no rows wer…
Browse files Browse the repository at this point in the history
…e affected
  • Loading branch information
Photonios committed Feb 24, 2021
1 parent 071e184 commit 6dac0ed
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/test_upsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def test_upsert_with_update_condition():

obj1 = model.objects.create(name="joe", priority=1, active=False)

model.objects.upsert(
# should not return anything because no rows were affected
assert not model.objects.upsert(
conflict_target=["name"],
update_condition=CombinedExpression(
model._meta.get_field("active").get_col(model._meta.db_table),
Expand All @@ -101,10 +102,25 @@ def test_upsert_with_update_condition():
)

obj1.refresh_from_db()

assert obj1.priority == 1
assert not obj1.active

# should return something because one row was affected
obj1_pk = model.objects.upsert(
conflict_target=["name"],
update_condition=CombinedExpression(
model._meta.get_field("active").get_col(model._meta.db_table),
"=",
Value(False),
),
fields=dict(name="joe", priority=2, active=True),
)

obj1.refresh_from_db()
assert obj1.pk == obj1_pk
assert obj1.priority == 2
assert obj1.active


def test_upsert_and_get_applies_converters():
"""Tests that converters are properly applied when using upsert_and_get."""
Expand Down

0 comments on commit 6dac0ed

Please sign in to comment.