Skip to content

Commit

Permalink
Add Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
elizazhang committed Apr 7, 2018
1 parent fcf9543 commit ead84f4
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 11 deletions.
11 changes: 11 additions & 0 deletions .travis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sudo: false
language: python
python:
- '2.7'
- '3.4'
- '3.5'
- '3.6'
install: pip install tox-travis codecov
script: tox
after_success:
- codecov
27 changes: 22 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
from setuptools import setup

requirements = {
"package": [
'six',
'requests',
'yamlsettings>=1.0.1',
],
"setup": [
"pytest-runner",
],
"test": [
"responses",
"pytest",
"pytest-pudb",
],
}

requirements.update(all=sorted(set().union(*requirements.values())))

setup(
name='yamlsettings-requests',
version='1.0.0',
author='Kyle Walker',
author_email='KyleJamesWalker@gmail.com',
description='Quick Example',
py_modules=['yamlsettings_requests'],
install_requires=[
'requests',
'yamlsettings>=1.0.1',

],
extras_require=requirements,
install_requires=requirements['package'],
setup_requires=requirements['setup'],
tests_require=requirements['test'],
entry_points={
'yamlsettings10': [
'ext = yamlsettings_requests:RequestsExtension',
Expand Down
50 changes: 49 additions & 1 deletion test_yamlsettings_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def resps():
('http://test:foo@testing.com:99/foobar', {'test': 'win'})
],
)
def test_load(resps, url, obj):
def test_user_pass_combos(resps, url, obj):
"""Test loading with u/p urls"""
resps.add(responses.GET, url,
json=obj, status=200)
Expand Down Expand Up @@ -56,3 +56,51 @@ def test_auth_required(resps):
auth_header = resps.calls[0].request.__dict__['headers']['Authorization']
assert auth_header == "Basic QWxhZGRpbjpPcGVuU2VzYW1l"
assert config.secure is True


def test_no_raise_with_unexpected(resps):
"""Test Runtime Error when excepted status code"""
url = 'http://testing.com/one'
obj = {'error': True}
expected = 200
status = 500
raise_on = False

resps.add(responses.GET, url, json=obj, status=status)

# OSError means the file was not found, and when passing an array the
# library will keep looking
with pytest.raises(OSError):
config = yamlsettings.load(url,
expected_status_code=expected,
raise_on_status=raise_on)



def test_raise_with_unexpected(resps):
"""Test Runtime Error when excepted status code"""
url = 'http://testing.com/one'
obj = {'error': True}
expected = 200
status = 500
raise_on = True

resps.add(responses.GET, url, json=obj, status=status)

# RuntimeError stops yamlsettings from trying the next url
with pytest.raises(RuntimeError):
config = yamlsettings.load(url,
expected_status_code=expected,
raise_on_status=raise_on)


def test_not_found_ok(resps):
"""Test 404 can return data when expected"""
url = 'http://missing.com/data'
obj = {'hidden': 'treasure'}
expected = 404
status = 404

resps.add(responses.GET, url, json=obj, status=status)
config = yamlsettings.load(url, expected_status_code=expected)
assert config.hidden == 'treasure'
22 changes: 22 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[flake8]
max-line-length = 80
max-complexity = 20

[tox]
envlist = py27, py34, py35, py36

[testenv]
deps =
.[all]
pytest-cov
pytest-xdist
flake8
pbr
usedevelop = True
setenv =
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_ALL=en_US.UTF-8
commands =
py.test --cov-report=xml:coverage.xml --junitxml=results.xml --cov-report=term-missing --cov=yamlsettings_requests {posargs}
flake8
9 changes: 4 additions & 5 deletions yamlsettings_requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
import urllib

from six.moves import urllib
from yamlsettings.extensions.base import YamlSettingsExtension

# Example URL:
Expand Down Expand Up @@ -58,10 +59,8 @@ def load_target(cls, scheme, path, fragment, username,
raise_on_status = kwargs.pop('raise_on_status', True)

resp = requests.get(url, **kwargs)
if resp.status_code == 404:
raise IOError
elif resp.status_code != expected_status_code:
if raise_on_status:
if resp.status_code != expected_status_code:
if raise_on_status and resp.status_code != 404:
raise RuntimeError(resp.status_code)
else:
raise IOError
Expand Down

0 comments on commit ead84f4

Please sign in to comment.