Skip to content

Commit

Permalink
Test bulk operations in models
Browse files Browse the repository at this point in the history
  • Loading branch information
adilhussain540 committed Dec 7, 2023
1 parent 8c8c5d3 commit e3d4781
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from unittest import mock

from django.core.exceptions import ValidationError
from django.test import TestCase

Expand All @@ -24,6 +26,18 @@ def test_get_version(self):
self.cookie_group.get_version(), self.cookie.created.isoformat()
)

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

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")

self.assertEqual(mock_delete_cache.call_count, 1)


class CookieTest(TestCase):
def setUp(self):
Expand All @@ -42,6 +56,18 @@ def setUp(self):
def test_varname(self):
self.assertEqual(self.cookie.varname, "optional=foo:.example.com")

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

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")

self.assertEqual(mock_delete_cache.call_count, 1)


class ValidateCookieNameTest(TestCase):
def test_valid(self):
Expand Down

0 comments on commit e3d4781

Please sign in to comment.