def test_request(self): middleware = Cache() middleware.process_request(None) self.assertTrue(hasattr(PER_THREAD, 'cache')) response = middleware.process_response(None, 'response') self.assertFalse(hasattr(PER_THREAD, 'cache')) self.assertEqual(response, 'response')
class TestMiddleware(TestsWithPizza): def setUp(self): self.middleware = Cache() self.middleware.process_request(None) super(TestMiddleware, self).setUp() def tearDown(self): super(TestMiddleware, self).tearDown() self.middleware.process_response(None, None)
def test_request(self): called = [] def flush_cache(*a): called.append(True) middleware = Cache() middleware.process_request(None) with patch('slumber.connector.Client._flush_client_instance_cache', flush_cache): response = middleware.process_response(None, 'response') self.assertTrue(called) self.assertEqual(response, 'response')
class TestMiddleware(TestsWithPizza): def setUp(self): self.middleware = Cache() self.middleware.process_request(None) super(TestMiddleware, self).setUp() def tearDown(self): super(TestMiddleware, self).tearDown() self.middleware.process_response(None, None) def test_alias_writes_are_visible(self): m1 = client.slumber_examples.Pizza.get(pk=1) m2 = client.slumber_examples.Pizza.get(pk=1) self.assertEqual(m1.id, m2.id) with self.assertRaises(AttributeError): m1.attr with self.assertRaises(AttributeError): m2.attr m1.attr = 'attribute data' self.assertEqual(m1.attr, 'attribute data') self.assertEqual(m1.attr, m2.attr)
class TestMiddleware(TestsWithPizza): def setUp(self): self.middleware = Cache() self.middleware.process_request(None) super(TestMiddleware, self).setUp() def tearDown(self): super(TestMiddleware, self).tearDown() self.middleware.process_response(None, None) def test_alias_writes_are_visible(self): m1 = client.slumber_examples.Pizza.get(pk=1) m2 = client.slumber_examples.Pizza.get(pk=1) self.assertEqual(m1.id, m2.id) self.assertTrue(PER_THREAD.cache.get(m1._url, None), (m1._url, PER_THREAD.cache.keys())) with self.assertRaises(AttributeError): m1.attr with self.assertRaises(AttributeError): m2.attr m1.attr = 'attribute data' self.assertEqual(m1.attr, 'attribute data') self.assertEqual(m1.attr, m2.attr)
def setUp(self): self.middleware = Cache() self.middleware.process_request(None) super(TestMiddleware, self).setUp()