Skip to content

Commit

Permalink
Update tests to assert return values of bulk actions
Browse files Browse the repository at this point in the history
  • Loading branch information
adilhussain540 committed Dec 7, 2023
1 parent 8b48d3b commit 93abd02
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ def test_get_version(self):

@mock.patch("cookie_consent.models.delete_cache")
def test_bulk_delete(self, mock_delete_cache):
CookieGroup.objects.filter(id=self.cookie_group.id).delete()
deleted_objs_count, _ = CookieGroup.objects.filter(id=self.cookie_group.id).delete()

# Deleting a CookieGroup also deletes the associated Cookies, that's why we expect a count of 2.
self.assertEqual(deleted_objs_count, 2)
self.assertEqual(mock_delete_cache.call_count, 1)

@mock.patch("cookie_consent.models.delete_cache")
def test_bulk_update(self, mock_delete_cache):
CookieGroup.objects.filter(id=self.cookie_group.id).update(name="Optional2")
updated_objs_count = CookieGroup.objects.filter(id=self.cookie_group.id).update(name="Optional2")

self.assertEqual(updated_objs_count, 1)
self.assertEqual(mock_delete_cache.call_count, 1)


Expand All @@ -58,14 +61,16 @@ def test_varname(self):

@mock.patch("cookie_consent.models.delete_cache")
def test_bulk_delete(self, mock_delete_cache):
Cookie.objects.filter(id=self.cookie.id).delete()
deleted_objs_count, _ = Cookie.objects.filter(id=self.cookie.id).delete()

self.assertEqual(deleted_objs_count, 1)
self.assertEqual(mock_delete_cache.call_count, 1)

@mock.patch("cookie_consent.models.delete_cache")
def test_bulk_update(self, mock_delete_cache):
Cookie.objects.filter(id=self.cookie.id).update(name="foo2")
updated_objs_count = Cookie.objects.filter(id=self.cookie.id).update(name="foo2")

self.assertEqual(updated_objs_count, 1)
self.assertEqual(mock_delete_cache.call_count, 1)


Expand Down

0 comments on commit 93abd02

Please sign in to comment.