Skip to content

Commit

Permalink
Test cache
Browse files Browse the repository at this point in the history
  • Loading branch information
erwan committed Nov 12, 2014
1 parent 281c731 commit 26490bb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion prismic/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class ShelveCache(object):
A cache implementation based on Shelve: https://docs.python.org/2/library/shelve.html.
By default, it will be created with "filename" equal to the api domain name. If you want to
run 2 processes using the same
run 2 processes using the same repository, you need to set a different file name to avoid
concurrency problems.
"""
def __init__(self, filename):
self.filename = filename
Expand Down
18 changes: 17 additions & 1 deletion tests/test_prismic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .test_prismic_fixtures import fixture_api, fixture_search, fixture_groups, \
fixture_structured_lists, fixture_empty_paragraph, fixture_store_geopoint, \
fixture_image_links, fixture_spans_labels, fixture_block_labels, fixture_custom_html
import time
import json
import logging
import prismic
Expand All @@ -37,7 +38,7 @@ def setUp(self):
self.fixture_spans_labels = json.loads(fixture_spans_labels)
self.fixture_custom_html = json.loads(fixture_custom_html)

self.api = prismic.Api(self.fixture_api, self.token, ShelveCache(None))
self.api = prismic.Api(self.fixture_api, self.token, ShelveCache("prismictest"))

def tearDown(self):
"""Teardown."""
Expand Down Expand Up @@ -430,6 +431,21 @@ def test_geopoint_near(self):
self.assertEqual(f.data['q'], ['[[:d = geopoint.near(my.store.coordinates, 40.689757, -74.0451453, 15)]]'])


class TestCache(unittest.TestCase):

def setUp(self):
self.cache = ShelveCache("cachetest")

def test_set_get(self):
self.cache.set("foo", "bar", 3600)
self.assertEqual(self.cache.get("foo"), "bar")

def test_expiration(self):
self.cache.set("toto", "tata", 2)
time.sleep(3)
self.assertIsNone(self.cache.get("toto"))


if __name__ == '__main__':
unittest.main()

0 comments on commit 26490bb

Please sign in to comment.