Skip to content

Commit

Permalink
Add CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RouganStriker committed Feb 12, 2020
1 parent c24a7a6 commit 7b5151b
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 6 deletions.
21 changes: 15 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
sudo: false
language: python
python:
- "2.7"
- "3.6"
install:
- "pip install flake8==2.6.2"
jobs:
include:
- python: "2.7"
env: DJANGO=1.11 LINT=true
- python: "3.6"
env: DJANGO=1.11 LINT=true
- python: "3.6"
env: DJANGO=2.0
- python: "3.6"
env: DJANGO=2.1
- python: "3.6"
env: DJANGO=2.2
- python: "3.6"
env: DJANGO=3.0
script:
- "make lint"
- "./ci.sh"
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
lint:
find . -name '*.py' | xargs flake8 --ignore=E501,W601

test:
(cd testing; python manage.py test)
11 changes: 11 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -ev

if [ "${LINT}" = "true" ]; then
pip install flake8==2.6.2
make lint
fi

python setup.py install
pip install django=="${DJANGO}"
make test
Empty file added testing/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions testing/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
import os
import sys

path, scriptname = os.path.split(__file__)

sys.path.append(os.path.abspath(path))
sys.path.append(os.path.abspath(os.path.join(path, '..')))

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)

53 changes: 53 additions & 0 deletions testing/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os as _os

_PROJECT_PATH = _os.path.abspath(_os.path.dirname(__file__))

DEBUG = True
ADMINS = ()
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'testing.db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
TIME_ZONE = 'America/Chicago'
USE_TZ = True
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True

SECRET_KEY = 'p_2zsf+@4uw$kcdl$!tkf0lrh%w^!#@2@iwo4plef2n$(@uj4_'

MIDDLEWARE = (
'django.middleware.common.CommonMiddleware',
)

INSTALLED_APPS = (
'keyvaluestore',
'tests'
)

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'WARNING',
'propagate': True,
},
},
}

Empty file added testing/tests/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions testing/tests/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.test import TestCase

from keyvaluestore.utils import (
get_value_for_key,
get_value_or_default,
set_key_value
)


class KeyValueStoreTests(TestCase):
def test_get_value_for_missing_key(self):
self.assertRaises(KeyError, get_value_for_key, "nonexistent")

def test_get_value_or_default(self):
default_value = "default123"
self.assertEqual(get_value_or_default("nonexistent", default_value), default_value)

def test_set_value_for_keyt(self):
key = "cache_key"
expected_value = "apple123"
set_key_value(key, expected_value)

self.assertEqual(get_value_for_key(key), expected_value)

0 comments on commit 7b5151b

Please sign in to comment.