MCPcopy
hub / github.com/django/django / test_binary_string

Method test_binary_string

tests/cache/tests.py:562–585  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

560 self.assertEqual(cache.get(key), value)
561
562 def test_binary_string(self):
563 # Binary strings should be cacheable
564 from zlib import compress, decompress
565
566 value = "value_to_be_compressed"
567 compressed_value = compress(value.encode())
568
569 # Test set
570 cache.set("binary1", compressed_value)
571 compressed_result = cache.get("binary1")
572 self.assertEqual(compressed_value, compressed_result)
573 self.assertEqual(value, decompress(compressed_result).decode())
574
575 # Test add
576 self.assertIs(cache.add("binary1-add", compressed_value), True)
577 compressed_result = cache.get("binary1-add")
578 self.assertEqual(compressed_value, compressed_result)
579 self.assertEqual(value, decompress(compressed_result).decode())
580
581 # Test set_many
582 cache.set_many({"binary1-set_many": compressed_value})
583 compressed_result = cache.get("binary1-set_many")
584 self.assertEqual(compressed_value, compressed_result)
585 self.assertEqual(value, decompress(compressed_result).decode())
586
587 def test_set_many(self):
588 # Multiple keys can be set using set_many

Callers

nothing calls this directly

Calls 6

encodeMethod · 0.45
setMethod · 0.45
getMethod · 0.45
decodeMethod · 0.45
addMethod · 0.45
set_manyMethod · 0.45

Tested by

no test coverage detected