Skip to content

Commit

Permalink
test(Suor#348): add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael committed Jul 30, 2021
1 parent e2f60db commit 7678176
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,12 @@ def _curried(*moreargs, **morekwargs):
setattr(self, '_get_private_data', curry(sum, [1, 2, 3, 4]))

name = models.CharField(max_length=255)


class ChatBoxDesign(models.Model):
width = models.IntegerField()
height = models.IntegerField()

class ChatBox(models.Model):
name = models.CharField(max_length=222)
design = models.OneToOneField(ChatBoxDesign, on_delete=models.SET_NULL, null=True)
2 changes: 2 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
'tests.noncachedvideoproxy': None,
'tests.noncachedmedia': None,
'auth.*': {},
'tests.ChatBox': {"ops": "all", "timeout": 3600 },
'tests.ChatBoxDesign': {"ops": "all", "timeout": 3600}
}

if os.environ.get('CACHEOPS_PREFIX'):
Expand Down
37 changes: 37 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,3 +1029,40 @@ def test_m2m_changed_call_invalidate(self, mock_invalidate_dict):
brand = Brand.objects.using('slave').create()
brand.labels.add(label)
mock_invalidate_dict.assert_called_with(mock.ANY, mock.ANY, using='slave')


class TestIssue348(BaseTestCase):
def test_case(self):
chatbox = ChatBox.objects.create(name="test")
design = ChatBoxDesign.objects.create(width=100, height=100)
chatbox.design = design
chatbox.save()

self.assertIsNotNone(chatbox)
self.assertIsNotNone(chatbox.design)

chatbox = ChatBox.objects.cache().get(pk=1)
self.assertIsNotNone(chatbox)
self.assertIsNotNone(chatbox.design)

d = ChatBoxDesign.objects.get(pk=1)
self.assertIsNotNone(d)
d.delete()

verify = ChatBoxDesign.objects.all().count()
self.assertEquals(verify, 0)

# c = ChatBox.objects.cache().get(pk=1)
# self.assertIsNone(c.design)

c = ChatBox.objects.get(pk=1)
self.assertIsNone(c.design)

# Walk around
# c = ChatBox.objects.get(pk=1)
# from django.core.exceptions import ObjectDoesNotExist
# try:
# has_design = c.design is not None
# except ObjectDoesNotExist as e:
# has_design = False
# self.assertFalse(has_design)

0 comments on commit 7678176

Please sign in to comment.