Ticket #4041: 4041.diff

File 4041.diff, 1.0 KB (added by Gary Wilson <gary.wilson@…>, 8 years ago)

added __contains__ to BaseCache class

  • django/core/cache/backends/base.py

    === modified file 'django/core/cache/backends/base.py'
     
    5454        Returns True if the key is in the cache and has not expired.
    5555        """
    5656        return self.get(key) is not None
     57
     58    def __contains__(self, key):
     59        """
     60        Allow use of 'in' operator.
     61        """
     62        return self.has_key(key)
  • tests/regressiontests/cache/tests.py

    === modified file 'tests/regressiontests/cache/tests.py'
     
    4646        self.assertEqual(cache.has_key("hello"), True)
    4747        self.assertEqual(cache.has_key("goodbye"), False)
    4848
     49    def test_in(self):
     50        # has_key
     51        cache.set("hello", "goodbye")
     52        self.assertEqual("hello" in cache, True)
     53        self.assertEqual("goodbye" in cache, False)
     54
    4955    def test_data_types(self):
    5056        # test data types
    5157        stuff = {
Back to Top