Example #1
0
 def test_roughly(self):
     numbers = []
     for i in range(100):
         numbers.append(utils.roughly(100, 10))
     # expect at least one of them to be less than 100
     ok_([x for x in numbers if x < 100])
     # same the other way
     ok_([x for x in numbers if x > 100])
     ok_(min(numbers) >= 90)
     ok_(max(numbers) <= 110)
Example #2
0
 def test_roughly(self):
     numbers = []
     for i in range(100):
         numbers.append(utils.roughly(100, 10))
     # expect at least one of them to be less than 100
     ok_([x for x in numbers if x < 100])
     # same the other way
     ok_([x for x in numbers if x > 100])
     ok_(min(numbers) >= 90)
     ok_(max(numbers) <= 110)
Example #3
0
 def get_unique_title(self):
     cache_key = 'unique_title_{}'.format(self.id)
     value = cache.get(cache_key)
     if value is None:
         value = self._get_unique_title()
         cache.set(cache_key, value, roughly(60 * 60 * 5))
     else:
         # When it comes out of memcache (not LocMemCache) it comes
         # out as a byte string. smart_text() always returns a
         # unicode string even if you pass in a unicode string.
         value = smart_text(value)
     return value
Example #4
0
 def get_unique_title(self):
     cache_key = 'unique_title_{}'.format(self.id)
     value = cache.get(cache_key)
     if value is None:
         value = self._get_unique_title()
         cache.set(cache_key, value, roughly(60 * 60 * 5))
     else:
         # When it comes out of memcache (not LocMemCache) it comes
         # out as a byte string. smart_text() always returns a
         # unicode string even if you pass in a unicode string.
         value = smart_text(value)
     return value