File: test_storage_redis.py

package info (click to toggle)
python-cachecontrol 0.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 376 kB
  • sloc: python: 2,026; makefile: 167; sh: 8
file content (26 lines) | stat: -rw-r--r-- 776 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# SPDX-FileCopyrightText: 2015 Eric Larson
#
# SPDX-License-Identifier: Apache-2.0

from datetime import datetime, timezone
from unittest.mock import Mock

from cachecontrol.caches import RedisCache


class TestRedisCache:
    def setup_method(self):
        self.conn = Mock()
        self.cache = RedisCache(self.conn)

    def test_set_expiration_datetime(self):
        self.cache.set("foo", "bar", expires=datetime(2014, 2, 2))
        assert self.conn.setex.called

    def test_set_expiration_datetime_aware(self):
        self.cache.set("foo", "bar", expires=datetime(2014, 2, 2, tzinfo=timezone.utc))
        assert self.conn.setex.called

    def test_set_expiration_int(self):
        self.cache.set("foo", "bar", expires=600)
        assert self.conn.setex.called