diff options
author | Jordan Cook <jordan.cook@pioneer.com> | 2021-03-24 15:27:57 -0500 |
---|---|---|
committer | Jordan Cook <jordan.cook@pioneer.com> | 2021-03-24 15:35:51 -0500 |
commit | c4fd835c935c699ee8e4950afc59bafca6b10f69 (patch) | |
tree | 58de429010446a78e80477fd90d83b280d9b9a4e | |
parent | e680611d450cc5bec0a8b956275341f61962f5a0 (diff) | |
download | requests-cache-c4fd835c935c699ee8e4950afc59bafca6b10f69.tar.gz |
Enable DynamoDB integration test with GitHub Actions and local docker-compose; use in-memory database
-rw-r--r-- | .github/workflows/build.yml | 4 | ||||
-rw-r--r-- | docker-compose.yml | 28 | ||||
-rw-r--r-- | requests_cache/backends/base.py | 2 | ||||
-rw-r--r-- | requests_cache/core.py | 1 | ||||
-rw-r--r-- | setup.py | 1 | ||||
-rw-r--r-- | tests/test_custom_dict.py | 2 | ||||
-rw-r--r-- | tests/test_dynamodbdict.py | 11 |
7 files changed, 26 insertions, 23 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dfa9f22..963bc28 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,7 +28,8 @@ jobs: mongodb-version: 4.4 - uses: supercharge/redis-github-action@1.2.0 with: - redis-version: '6' + redis-version: 6 + - uses: rrainn/dynamodb-action@v2.0.0 # Cache packages per python version, and reuse until setup.py changes - name: Cache pip packages @@ -65,6 +66,7 @@ jobs: - uses: supercharge/redis-github-action@1.2.0 with: redis-version: '6' + - uses: rrainn/dynamodb-action@v2.0.0 - name: Install dependencies run: pip install ".[dev]" diff --git a/docker-compose.yml b/docker-compose.yml index d9a098e..0b64f12 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,37 +4,39 @@ version: '3' services: dynamodb: image: amazon/dynamodb-local - hostname: dynamodb-local - container_name: dynamodb-local + container_name: dynamodb ports: - - 8000:8000 - command: "-jar DynamoDBLocal.jar -sharedDb -optimizeDbBeforeStartup -dbPath ./data" - volumes: - - 'dynamodb_data:/home/dynamodblocal/data' - working_dir: /home/dynamodblocal + - '8000:8000' + command: '-jar DynamoDBLocal.jar -inMemory' + environment: + AWS_ACCESS_KEY_ID: 'placeholder' + AWS_SECRET_ACCESS_KEY: 'placeholder' +# volumes: +# - 'dynamodb_data:/home/dynamodblocal/data' + working_dir: '/home/dynamodblocal' mongo: image: mongo + container_name: mongo environment: - MONGO_INITDB_DATABASE: aiohttp_client_cache_pytest + MONGO_INITDB_DATABASE: 'requests_cache_pytest' ports: - - 27017:27017 + - '27017:27017' volumes: - 'mongodb_data:/data/db' redis: + container_name: redis image: docker.io/bitnami/redis + ports: + - '6379:6379' environment: ALLOW_EMPTY_PASSWORD: 'yes' # REDIS_DISABLE_COMMANDS: 'FLUSHDB,FLUSHALL' - ports: - - 6379:6379 volumes: - 'redis_data:/bitnami/redis/data' volumes: - dynamodb_data: - driver: local mongodb_data: driver: local redis_data: diff --git a/requests_cache/backends/base.py b/requests_cache/backends/base.py index 8e8aeb5..4c229ed 100644 --- a/requests_cache/backends/base.py +++ b/requests_cache/backends/base.py @@ -181,7 +181,7 @@ class BaseStorage(MutableMapping): """Base class for backend storage implementations Args: - secret_key: Optional secret key used to sign cache items + secret_key: Optional secret key used to sign cache items for added security salt: Optional salt used to sign cache items serializer: Custom serializer that provides ``loads`` and ``dumps`` methods """ diff --git a/requests_cache/core.py b/requests_cache/core.py index 554b702..67d69be 100644 --- a/requests_cache/core.py +++ b/requests_cache/core.py @@ -236,6 +236,7 @@ class CachedSession(CacheMixin, OriginalSession): returns a boolean indicating whether or not that response should be cached. Will be applied to both new and previously cached responses. old_data_on_error: Return expired cached responses if new request fails + secret_key: Optional secret key used to sign cache items for added security **Cache Name:** @@ -9,7 +9,6 @@ extras_require = { 'build': ['coveralls', 'twine', 'wheel'], # Packages for all supported backends + features 'backends': ['boto3', 'pymongo', 'redis', 'itsdangerous'], - 'security': ['itsdangerous'], # Packages used for documentation builds 'docs': [ 'm2r2', diff --git a/tests/test_custom_dict.py b/tests/test_custom_dict.py index 648c1dc..b42c50e 100644 --- a/tests/test_custom_dict.py +++ b/tests/test_custom_dict.py @@ -22,7 +22,7 @@ class BaseCustomDictTestCase(object): for table in self.TABLES: d = self.dict_class(self.NAMESPACE, table) d.clear() - super(BaseCustomDictTestCase, self).tearDown() + super().tearDown() def test_set_get(self): d1 = self.dict_class(self.NAMESPACE, self.TABLES[0]) diff --git a/tests/test_dynamodbdict.py b/tests/test_dynamodbdict.py index 9b8c5ef..6e89ee6 100644 --- a/tests/test_dynamodbdict.py +++ b/tests/test_dynamodbdict.py @@ -1,23 +1,22 @@ #!/usr/bin/env python import os -import pytest import unittest from tests.test_custom_dict import BaseCustomDictTestCase -pytestmark = pytest.mark.skip(reason='Integration test database is not set up') try: from requests_cache.backends.dynamodb import DynamoDbDict except ImportError: print("DynamoDb not installed") else: + # boto3 will accept any values for creds, but they still need to be present + os.environ['AWS_ACCESS_KEY_ID'] = 'placeholder' + os.environ['AWS_SECRET_ACCESS_KEY'] = 'placeholder' class WrapDynamoDbDict(DynamoDbDict): def __init__(self, namespace, collection_name='dynamodb_dict_data', **options): - options['endpoint_url'] = ( - os.environ['DYNAMODB_ENDPOINT_URL'] if 'DYNAMODB_ENDPOINT_URL' in os.environ else None - ) - super(WrapDynamoDbDict, self).__init__(namespace, collection_name, **options) + options['endpoint_url'] = 'http://0.0.0.0:8000' + super().__init__(namespace, collection_name, **options) class DynamoDbDictTestCase(BaseCustomDictTestCase, unittest.TestCase): dict_class = WrapDynamoDbDict |