Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
branches: [ main ]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
env:
TEST_AUTH_TOKEN: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
TEST_CACHE_NAME: dummy

steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel build
pip install -e . --extra-index-url https://momento.jfrog.io/artifactory/api/pypi/pypi-public/simple

- name: Build package
run: python -m pip install -e .

- name: Run tests
run: python tests/*
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,14 @@ To test your changes you can then just run your python shell as follows:

`python` this will start the interactive shell or if you prefer you may put all
your code in a my_test.py file and run `python my_test.py`

# Tests

- Integration tests require an auth token for testing. Set this as `TEST_AUTH_TOKEN`.
- `TEST_CACHE_NAME` is required, but for now any string value works.

Run:

```
TEST_AUTH_TOKEN=<auth token> TEST_CACHE_NAME=<cache name> python3 tests/*
```
39 changes: 39 additions & 0 deletions tests/test_momento.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import unittest
import os
import uuid

import momento.momento as momento
from momento.cache_operation_responses import CacheResult


_AUTH_TOKEN = os.getenv('TEST_AUTH_TOKEN')
_TEST_CACHE_NAME = os.getenv('TEST_CACHE_NAME')
_DEFAULT_TTL_SECONDS = 60

class TestMomento(unittest.TestCase):

@classmethod
def setUpClass(cls):
if not _AUTH_TOKEN:
raise RuntimeError("Integration tests require TEST_AUTH_TOKEN env var; see README for more details.")
if not _TEST_CACHE_NAME:
raise RuntimeError("Integration tests require TEST_CACHE_NAME env var; see README for more details.")

def test_happy_path(self):
key = str(uuid.uuid4())
value = str(uuid.uuid4())

with momento.init(_AUTH_TOKEN) as momento_client:
with momento_client.get_cache(_TEST_CACHE_NAME,
ttl_seconds=_DEFAULT_TTL_SECONDS, create_if_absent=True) as cache_client:

cache_client.set(key, value)

get_resp = cache_client.get(key)

self.assertEqual(get_resp.result(), CacheResult.HIT)
self.assertEqual(get_resp.str_utf8(), value)


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