Skip to content

Commit

Permalink
Added unit test for refresh_from_db()
Browse files Browse the repository at this point in the history
  • Loading branch information
vdboor committed Jul 15, 2019
1 parent 263fb65 commit 6af023d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions polymorphic/tests/test_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,3 +1234,14 @@ def test_prefetch_related_with_missing(self):
self.assertEqual(
len(objects[1].many2many.non_polymorphic()), 1
) # base object does exist

def test_refresh_from_db_fields(self):
"""Test whether refresh_from_db(fields=..) works as it performs .only() queries"""
obj = Model2B.objects.create(field1="aa", field2="bb")
Model2B.objects.filter(pk=obj.pk).update(field1="aa1", field2="bb2")
obj.refresh_from_db(fields=["field2"])
assert obj.field1 == "aa"
assert obj.field2 == "bb2"

obj.refresh_from_db(fields=["field1"])
assert obj.field1 == "aa1"

0 comments on commit 6af023d

Please sign in to comment.