Skip to content

Commit

Permalink
Merge branch 'master' into 171_pg_array_field_contains_support
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan6419846 authored Apr 19, 2024
2 parents 8f1448c + d7c7e32 commit 5106bf5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django_mock_queries/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def _do_update(self, *args, **_):
objects = self.objects.filter(pk=pk_val)

if objects.exists():
attrs = {field.name: value for field, _, value in values if value is not None}
attrs = {field.attname: value for field, _, value in values if value is not None}
self.objects.update(**attrs)
return True
else:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,16 @@ def test_model_mocker_objects_create(self):
obj = Car.objects.create(speed=10)
self.assertEqual(Car.objects.get(pk=obj.id), obj)

def test_model_mocker_update_fk_from_instance(self):
with ModelMocker(Manufacturer):
with ModelMocker(Car, outer=False):
manufacturer = Manufacturer.objects.create(name='foo')
obj = Car.objects.create(speed=10, make=manufacturer)
obj.make = Manufacturer.objects.create(name='bar')
obj.save()

self.assertEqual(Car.objects.get(pk=obj.id).make.name, 'bar')

def test_model_mocker_with_custom_method(self):
with self.CarModelMocker(Car, 'validate_price') as mocker:
obj = Car()
Expand Down

0 comments on commit 5106bf5

Please sign in to comment.