Skip to content

Commit

Permalink
Merge 3ad2bff into 5114374
Browse files Browse the repository at this point in the history
  • Loading branch information
brew committed Nov 24, 2017
2 parents 5114374 + 3ad2bff commit b681a97
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 45 deletions.
23 changes: 11 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
language: python
os:
- linux

python:
- 3.6

services:
- redis
python:
- 2.7
- 3.3
- 3.4
- 3.5
sudo: false

env:
- TOXENV="py${PYTHON_VERSION//./}"

install:
- pip install tox coveralls
before_script:
- sleep 30
script: tox
- pip install tox coveralls
script:
- tox
after_success:
- coveralls
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[![Travis](https://img.shields.io/travis/openspending/os-api-cache/master.svg)](https://travis-ci.org/openspending/os-api-cache)
[![Coveralls](http://img.shields.io/coveralls/openspending/os-api-cache/master.svg)](https://coveralls.io/r/openspending/os-api-cache?branch=master)

# os-api-cache
Manage a cache for OpenSpending API
Manage a cache for OpenSpending API
5 changes: 3 additions & 2 deletions os_api_cache/redis_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class RedisCache(BaseCache):
def __init__(self, redis_host, redis_port,
default_timeout):
super(RedisCache, self).__init__(default_timeout=default_timeout)
self.redis_connection = StrictRedis(host=redis_host, port=redis_port, db=1)
self.redis_connection = StrictRedis(host=redis_host,
port=redis_port, db=1)

def _put(self, context, params, item, timeout):
key = RedisCache._make_key(context, params)
Expand Down Expand Up @@ -47,4 +48,4 @@ def _make_key(context, params):

@staticmethod
def _make_context_key(context):
return RedisCache._make_key('ctx', context)
return RedisCache._make_key('ctx', context)
11 changes: 0 additions & 11 deletions run_coveralls.py

This file was deleted.

10 changes: 2 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


setup(
name='os-api-cache',
name='os_api_cache',
version='0.0.5',
description=(
'Manage a cache for OpenSpending API'
Expand All @@ -25,17 +25,11 @@

classifiers=[
'Development Status :: 4 - Beta',

'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Topic :: Utilities',

'License :: OSI Approved :: MIT License',

'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
],

keywords='fdp fiscal data api openspending cache',
Expand Down
Empty file added tests/__init__.py
Empty file.
15 changes: 8 additions & 7 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@

from redis import StrictRedis

from os_api_cache import RedisCache
from os_api_cache import OSCache

TIMEOUT = 5

TIMEOUT=5

@pytest.fixture
def redis_cache():
redis_host = 'localhost'
redis_port= 6379
redis_port = 6379
redis_connection = StrictRedis(host=redis_host, port=redis_port, db=1)
redis_connection.flushdb()
_cache = RedisCache(redis_host, redis_port, TIMEOUT)
_cache = OSCache(redis_host, redis_port, TIMEOUT)
return _cache


Expand Down Expand Up @@ -49,12 +50,12 @@ def test_default_timeout(self, redis_cache):
time.sleep(TIMEOUT)
assert redis_cache.get(context, params) is None

def test_nondefault_timeout(self, redis_cache):
def test_nondefault_timeout_reset(self, redis_cache):
'''key resets timeout to default_timeout after first access.'''
context = 'context'
params = {'key': 'value'}
item = {'a', 'b', 'c'}
redis_cache.put(context, params, item, timeout=TIMEOUT*2-1)
assert 'a' in redis_cache.get(context, params)
redis_cache.put(context, params, item, timeout=TIMEOUT*2)
time.sleep(TIMEOUT)
assert 'a' in redis_cache.get(context, params)
time.sleep(TIMEOUT)
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[tox]
package=os_api_cache
envlist=
py35
py36
skip_missing_interpreters = true

[testenv]
Expand All @@ -12,8 +13,7 @@ deps=
coveralls
commands=
py.test \
--cov os_package_registry \
--cov {[tox]package} \
--cov-config tox.ini \
--cov-report term-missing \
--cov-config .coveragerc \
{posargs}
python {toxinidir}/run_coveralls.py

0 comments on commit b681a97

Please sign in to comment.