From 3db1256895aa5086621335e42134a1ffd5b06965 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Sun, 1 May 2016 11:21:55 +1000 Subject: [PATCH] Adds test for end_batch functionality --- registrasion/tests/test_batch.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/registrasion/tests/test_batch.py b/registrasion/tests/test_batch.py index 51aa19dd..590f7f04 100644 --- a/registrasion/tests/test_batch.py +++ b/registrasion/tests/test_batch.py @@ -120,3 +120,26 @@ class BatchTestCase(RegistrationCartTestCase): @BatchController.memoise def _memoiseme(self, user): return object() + + def test_batch_end_functionality_is_called(self): + + class Ender(object): + end_count = 0 + def end_batch(self): + self.end_count += 1 + + @BatchController.memoise + def get_ender(user): + return Ender() + + # end_batch should get called once on exiting the batch + with BatchController.batch(self.USER_1): + ender = get_ender(self.USER_1) + self.assertEquals(1, ender.end_count) + + # end_batch should get called once on exiting the batch + # no matter how deep the object gets cached + with BatchController.batch(self.USER_1): + with BatchController.batch(self.USER_1): + ender = get_ender(self.USER_1) + self.assertEquals(1, ender.end_count)