-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jarosław Śmiejczak
committed
Jan 31, 2017
1 parent
e34d8c3
commit 08a1325
Showing
9 changed files
with
88 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
sudo: false | ||
language: python | ||
python: | ||
- '2.7' | ||
install: | ||
- pip install -U --force setuptools pip | ||
- ./setup.py develop | ||
- pip install -e '.[tests]' | ||
|
||
script: | ||
- pylama | ||
- py.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[pylama] | ||
linters = pyflakes | ||
|
||
[pylama:doc/conf.py] | ||
skip = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from mock import patch | ||
import pytest | ||
|
||
from zapv2 import ZAPv2 | ||
|
||
@pytest.yield_fixture | ||
def zap(): | ||
""" | ||
All tests will be able to share the instance of client with the same settings.""" | ||
yield ZAPv2() | ||
|
||
|
||
@pytest.yield_fixture | ||
def urllib_mock(): | ||
"""Fixture create a mock for urllib library.""" | ||
with patch('zapv2.urllib.urlopen') as urllib_mock: | ||
yield urllib_mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
""" | ||
Tests related to the main Zap Client class | ||
""" | ||
from mock import call | ||
|
||
TEST_PROXIES = { | ||
'http': 'http://127.0.0.1:8080', | ||
'https': 'http://127.0.0.1:8080', | ||
} | ||
|
||
|
||
def test_urlopen_proxies(zap, urllib_mock): | ||
"""Check if Zap client passes proxy to urllib call.""" | ||
urllib_mock.return_value.read.return_value = 'contents' | ||
|
||
assert zap.urlopen() == 'contents' | ||
assert urllib_mock.mock_calls[0][2]['proxies'] == TEST_PROXIES | ||
|
||
|
||
def test_request_response(zap, urllib_mock): | ||
"""Request method should return a python object from parsed output""" | ||
urllib_mock.return_value.read.return_value = '{"testkey": "testvalue"}' | ||
|
||
assert zap._request('http://allizom.org', {'querykey': 'queryvalue'}) == {'testkey': 'testvalue'} | ||
assert urllib_mock.mock_calls == [ | ||
call('http://allizom.org?querykey=queryvalue', proxies=TEST_PROXIES), | ||
call().read() | ||
] | ||
|
||
|
||
def test_request_other(zap, urllib_mock): | ||
"""_request_other should simply return a retrieved content.""" | ||
urllib_mock.return_value.read.return_value = '{"testkey": "testvalue"}' | ||
|
||
assert zap._request('http://allizom.org', {'querykey': 'queryvalue'}) == {'testkey': 'testvalue'} | ||
assert urllib_mock.mock_calls == [ | ||
call('http://allizom.org?querykey=queryvalue', proxies=TEST_PROXIES), | ||
call().read() | ||
] |