Skip to content

Commit

Permalink
Merge branch 'release/0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
andreygrechin committed Mar 10, 2018
2 parents a5bf1db + 048432b commit 27b2942
Show file tree
Hide file tree
Showing 17 changed files with 408 additions and 487 deletions.
46 changes: 46 additions & 0 deletions .appveyor.yml
@@ -0,0 +1,46 @@
# https://www.appveyor.com/docs/appveyor-yml/

version: '{build}'
max_jobs: 6
build: off
shallow_clone: true
# clone_depth: 1
environment:
fast_finish: true
matrix:

- PYTHON: "C:\\Python34"
PYTHON_VERSION: "3.4.4"
PYTHON_ARCH: "32"

- PYTHON: "C:\\Python34-x64"
PYTHON_VERSION: "3.4.4"
PYTHON_ARCH: "64"

- PYTHON: "C:\\Python35"
PYTHON_VERSION: "3.5.3"
PYTHON_ARCH: "32"

- PYTHON: "C:\\Python35-x64"
PYTHON_VERSION: "3.5.3"
PYTHON_ARCH: "64"

- PYTHON: "C:\\Python36"
PYTHON_VERSION: "3.6.4"
PYTHON_ARCH: "32"

- PYTHON: "C:\\Python36-x64"
PYTHON_VERSION: "3.6.4"
PYTHON_ARCH: "64"

init:
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
- "ECHO %PYTHON% %PYTHON_VERSION% %PYTHON_ARCH%"
- "python --version"
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""
install:
- "pip install --disable-pip-version-check --user --upgrade pip"
- "pip install -e ."
- "pip install -e .[dev]"
test_script:
- "%CMD_IN_ENV% python setup.py test"
9 changes: 7 additions & 2 deletions Makefile
Expand Up @@ -3,7 +3,7 @@ all: clear-all install-dev test-offline docs built upload coverage-offline

.PHONY: test
test: clear-all install-dev
pytest -q --cache-clear tests/
pytest -k '' -q --cache-clear tests/

.PHONY: test-online
test-online: clear-all install-dev
Expand All @@ -20,12 +20,17 @@ lint:
pep257 -s -e tests/
pep257 -s -e examples/
pep257 -s -e setup.py
pylint umbr_api/ tests/*.py examples/ setup.py
# flake8 --statistics --count --exclude venv

.PHONY: install-dev
install-dev:
pip install -q -e .[dev]

.PHONY: install-doc
install-doc:
pip install -q -e .[doc]

.PHONY: coverage-offline
coverage-offline: clear-pyc clear-cov
coverage run -m pytest -k 'not Online' -q --cache-clear tests/
Expand All @@ -46,7 +51,7 @@ upload: clear-all built
twine upload dist/*

.PHONY: docs
docs: clear-pyc install-dev
docs: clear-pyc install-dev install-doc
$(MAKE) -C docs html

.PHONY: built
Expand Down
7 changes: 6 additions & 1 deletion README.rst
Expand Up @@ -9,14 +9,19 @@ README
- | |docs|
* - Tests
- | |build1| |requires|
| |appveyor| |coveralls|
| |codacy| |codeclimate|
| |coveralls|
* - Package
- | |supported-versions| |supported-implementations|
| |dev-status| |pypi-version| |license|
* - GitHub
- | |gh-release| |gh-tag| |gh-issues|


.. |appveyor| image:: https://ci.appveyor.com/api/projects/status/hptdwfa7mcsu5tla/branch/master?svg=true
:target: https://ci.appveyor.com/project/kolatz/umbr-api/
:alt: Appveyor Build Status

.. |coveralls| image:: https://coveralls.io/repos/github/kolatz/umbr_api/badge.svg?branch=release%2F0.3
:target: https://coveralls.io/github/kolatz/umbr_api?branch=release%2F0.3
:alt: coveralls
Expand Down
68 changes: 37 additions & 31 deletions setup.py
Expand Up @@ -5,24 +5,28 @@
from setuptools import setup

with open(path.join(path.dirname(__file__), "README.rst")) as read_file:
long_description = read_file.read()
LONG_DESCRIPTION = read_file.read()

base_dir = path.dirname(__file__)
about = {}
with open(path.join(base_dir, "umbr_api", "__about__.py")) as py_file:
ABOUT = {}
# pylint: disable=C0330
with open(path.join(
path.dirname(__file__),
"umbr_api",
"__about__.py",
)) as py_file:
# pylint: disable=W0122
exec(py_file.read(), about)
exec(py_file.read(), ABOUT)

setup(
name=about["__title__"],
version=about["__version__"],
description=about["__summary__"],
long_description=long_description,
url=about["__uri__"],
author=about["__author__"],
author_email=about["__email__"],
name=ABOUT["__title__"],
version=ABOUT["__version__"],
description=ABOUT["__summary__"],
long_description=LONG_DESCRIPTION,
url=ABOUT["__uri__"],
author=ABOUT["__author__"],
author_email=ABOUT["__email__"],
platforms="Darwin",
license=about["__license__"],
license=ABOUT["__license__"],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Education",
Expand All @@ -40,45 +44,47 @@
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: Implementation :: CPython"
"Programming Language :: Python :: Implementation :: CPython",
],
keywords='cisco umbrella opendns security',
packages=['umbr_api'],
keywords="cisco umbrella opendns security",
packages=["umbr_api"],
install_requires=[
'requests >= 2.18',
'logzero >= 1.3.1',
'keyring >= 11.0.0',
"requests >= 2.18",
"logzero >= 1.3.1",
"keyring >= 11.0.0",
],
extras_require={
'dev': [
"dev": [
"coverage>=4.5.1",
"pytest>=3.4.1",
"setuptools>=38.5.1",
"twine>=1.9.1",
],
"doc": [
"Sphinx>=1.7.1",
"sphinx_rtd_theme>=0.2.4",
"twine>=1.9.1"
],
'dev_lint': [
"dev_lint": [
"autopep8>=1.3.4",
"pep257>=0.7.0",
"pycodestyle>=2.3.1",
"pydocstyle>=2.1.1",
"pylint>=1.8.2"
"pylint>=1.8.2",
],
},
package_data={
'umbr_api': ['data/customer_key_example.json'],
"umbr_api": ["data/customer_key_example.json"],
},
entry_points={
'console_scripts': [
'umbrella=umbr_api.umbrella:main',
"console_scripts": [
"umbrella=umbr_api.umbrella:main",
],
},
project_urls={
'Cisco Umbrella': 'https://umbrella.cisco.com/',
'Cisco Umbrella Enforcement API': 'https://docs.umbrella.com/'
'developer/enforcement-api/'
"Cisco Umbrella": "https://umbrella.cisco.com/",
"Cisco Umbrella Enforcement API": "https://docs.umbrella.com/"
"developer/enforcement-api/",
},
setup_requires=['pytest-runner'],
tests_require=['pytest'],
setup_requires=["pytest-runner"],
tests_require=["pytest"],
)
34 changes: 34 additions & 0 deletions tests/offline_utils.py
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
# pylint: disable=R0201
"""Test unit."""

import unittest
from ast import literal_eval
import os


# pylint: disable=R0903
class FakeResponse():
"""To mimic ``requests`` response obj."""

def __init__(self, case_dir):
"""Create fake class."""
status_code_file = os.path.join(os.path.dirname(__file__),
case_dir,
'code.txt')
body_file = os.path.join(os.path.dirname(__file__),
case_dir,
'body.json')
headers_file = os.path.join(os.path.dirname(__file__),
case_dir,
'headers.json')
with open(status_code_file) as file:
self.status_code = int(file.read())
with open(headers_file) as file:
self.headers = literal_eval(file.read())
with open(body_file) as file:
self.text = file.read()


if __name__ == '__main__':
unittest.main()
78 changes: 9 additions & 69 deletions tests/test_offline_add.py
Expand Up @@ -3,23 +3,11 @@
"""Test unit."""

import unittest
from ast import literal_eval
import os
from offline_utils import FakeResponse

FAKE_KEY = 'YOUR-CUSTOMER-KEY-IS-HERE-0123456789'


# pylint: disable=R0903
class FakeResponse():
"""To mimic ``requests`` response obj."""

def __init__(self, code, headers, body_txt):
"""Create fake class."""
self.status_code = code
self.headers = headers
self.text = body_txt


class TestCaseMocking(unittest.TestCase):
"""Main class."""

Expand All @@ -28,25 +16,9 @@ def test_add_main(self):
from unittest import mock
from umbr_api.add import main

status_code_file = os.path.join(os.path.dirname(__file__),
'data/templates/add/case1',
'code.txt')
body_file = os.path.join(os.path.dirname(__file__),
'data/templates/add/case1',
'body.json')
headers_file = os.path.join(os.path.dirname(__file__),
'data/templates/add/case1',
'headers.json')
with open(status_code_file) as file:
status_code = int(file.read())
with open(headers_file) as file:
headers = literal_eval(file.read())
with open(body_file) as file:
body_text = file.read()
my_response = FakeResponse('data/templates/add/case1')

my_response = FakeResponse(status_code, headers, body_text)

with mock.patch('requests.post') as mock_requests_post:
with mock.patch('requests.request') as mock_requests_post:
mock_requests_post.return_value = my_response
main(test_key=FAKE_KEY)

Expand All @@ -55,60 +27,28 @@ def test_add(self):
from unittest import mock
import umbr_api

status_code_file = os.path.join(os.path.dirname(__file__),
'data/templates/add/case1',
'code.txt')
body_file = os.path.join(os.path.dirname(__file__),
'data/templates/add/case1',
'body.json')
headers_file = os.path.join(os.path.dirname(__file__),
'data/templates/add/case1',
'headers.json')
with open(status_code_file) as file:
status_code = int(file.read())
with open(headers_file) as file:
headers = literal_eval(file.read())
with open(body_file) as file:
body_text = file.read()

my_response = FakeResponse(status_code, headers, body_text)
my_response = FakeResponse('data/templates/add/case1')

with mock.patch('requests.post') as mock_requests_post:
with mock.patch('requests.request') as mock_requests_post:
mock_requests_post.return_value = my_response
response = umbr_api.add(domain='example.com', url='example.com',
key=FAKE_KEY,
bypass=False)
assert response.status_code == status_code
assert response.status_code == my_response.status_code

def test_add_fail(self):
"""Call add to fail."""
from unittest import mock
import umbr_api

status_code_file = os.path.join(os.path.dirname(__file__),
'data/templates/add/case2',
'code.txt')
body_file = os.path.join(os.path.dirname(__file__),
'data/templates/add/case2',
'body.json')
headers_file = os.path.join(os.path.dirname(__file__),
'data/templates/add/case2',
'headers.json')
with open(status_code_file) as file:
status_code = int(file.read())
with open(headers_file) as file:
headers = literal_eval(file.read())
with open(body_file) as file:
body_text = file.read()

my_response = FakeResponse(status_code, headers, body_text)
my_response = FakeResponse('data/templates/add/case2')

with mock.patch('requests.post') as mock_requests_post:
with mock.patch('requests.request') as mock_requests_post:
mock_requests_post.return_value = my_response
response = umbr_api.add(domain='example.com', url='2example.com',
key=FAKE_KEY,
bypass=True)
assert response.status_code == status_code
assert response.status_code == my_response.status_code


if __name__ == '__main__':
Expand Down

0 comments on commit 27b2942

Please sign in to comment.