Skip to content

Commit

Permalink
travis.yml
Browse files Browse the repository at this point in the history
add redis to travis

remove redis

remove tests that test the server

ignore .coverage

add coverage

container based infra, cache pip

install nose-cov
  • Loading branch information
zackkitzmiller committed Dec 31, 2015
1 parent 05a73c9 commit 9523641
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ env/
*~
*#*
*.swp
pkg
pkg
.coverage
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: python
python:
- "2.7"
install: "pip install -r requirements.txt"
before_script: "pip install nose-cov"
script: nosetests --with-coverage --cover-package=sixpack
sudo: false
cache: pip
56 changes: 45 additions & 11 deletions sixpack/test/test_sixpack_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from mock import patch, Mock
import unittest

from sixpack import sixpack


class TestSixpackClent(unittest.TestCase):

unit = True
Expand Down Expand Up @@ -30,9 +32,12 @@ def test_generate_uuid(self):

def test_should_return_ok_for_multiple_tests(self):
session = sixpack.Session('runnerJose')
session.participate('ok-ok', ['water', 'oil'])
ret1 = session.convert('ok-ok')
ret2 = session.convert('ok-ok')
with patch('requests.get', new=new_participate):
session.participate('ok-ok', ['water', 'oil'])

with patch('requests.get', new=new_convert):
ret1 = session.convert('ok-ok')
ret2 = session.convert('ok-ok')

self.assertEqual(ret1['status'], 'ok')
self.assertEqual(ret2['status'], 'ok')
Expand All @@ -44,7 +49,7 @@ def test_settings_to_constructor(self):
self.assertEqual(session.host, 'http://localhost:5000')

params = {'host': 'http://sixpack-ec2-01:8911'}
session = sixpack.Session(options = params)
session = sixpack.Session(options=params)
self.assertEqual(session.host, 'http://sixpack-ec2-01:8911')

def test_client_id_on_constructor(self):
Expand All @@ -71,16 +76,22 @@ def test_failure_on_bad_kpi_name_convert(self):

def test_should_return_ok_for_a_kpi(self):
session = sixpack.Session('runnerOsvaldo')
session.participate('with-kpi', ['water', 'oil'])
ret = session.convert('with-kpi', kpi='my-shiny-kpi')
self.assertEqual(ret['status'], 'ok')

def test_should_return_ok_for_a_traffic_fraction(self):
session = sixpack.Session('supperUser')
session.participate('my-subset-experiment', ['water', 'oil'], traffic_fraction=0.2)
ret = session.convert('my-subset-experiment')
with patch('requests.get', new=new_participate):
session.participate('with-kpi', ['water', 'oil'])

with patch('requests.get', new=new_convert):
ret = session.convert('with-kpi', kpi='my-shiny-kpi')

self.assertEqual(ret['status'], 'ok')

def test_should_return_failed_for_sixpack_unavailable(self):
session = sixpack.Session('runnerOsvaldo')

with patch('requests.get', new=sixpack_unavailable):
ret = session.participate('with-kpi', ['water', 'oil'])
self.assertEqual(ret['status'], 'failed')

def test_should_return_error_for_a_traffic_fraction_off_the_charts(self):
session = sixpack.Session('runnerOsvaldo')
with self.assertRaises(ValueError):
Expand All @@ -95,3 +106,26 @@ def test_failure_on_bad_alt_names(self):
session = sixpack.Session('zack')
with self.assertRaises(ValueError):
session.participate('ipa', ['****', '1'])


def new_convert(*args, **kwargs):
m = Mock()
m.status_code = 200
m.content = '{"status": "ok"}'
return m


def new_participate(*args, **kwargs):
m = Mock()
m.status_code = 200
m.content = '{"status": "ok"}'

return m


def sixpack_unavailable(*args, **kwargs):
m = Mock()
m.status_code = 500
m.content = '{"status": "failed"}'

return m

0 comments on commit 9523641

Please sign in to comment.