File: test_cache.py

package info (click to toggle)
mopidy-soundcloud 3.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 864 kB
  • sloc: python: 826; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 733 bytes parent folder | download | duplicates (3)
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
27
28
29
import unittest
from unittest import mock

from mopidy_soundcloud.soundcloud import cache


class CacheTest(unittest.TestCase):
    def test_decorator(self):
        func = mock.Mock()
        decorated_func = cache()
        decorated_func(func)
        func()
        assert func.called is True
        assert decorated_func._call_count == 1

    def test_set_default_cache(self):
        @cache()
        def returnstring():
            return "ok"

        assert returnstring() == "ok"

    def test_set_ttl_cache(self):
        func = mock.Mock()
        decorated_func = cache(func, ttl=5)
        func()
        assert func.called is True
        assert decorated_func._call_count == 1
        assert decorated_func.ttl == 5