-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from chrisleck/auto-lint-testing
Code cleanup in preparation for next release
- Loading branch information
Showing
9 changed files
with
310 additions
and
240 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
.DS_Store | ||
.cache/ | ||
.coverage | ||
build | ||
dist | ||
*.egg | ||
|
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,13 @@ | ||
machine: | ||
post: | ||
- pyenv global 2.7.11 3.4.4 | ||
|
||
dependencies: | ||
pre: | ||
- python2.7 setup.py install | ||
- python3.4 setup.py install | ||
|
||
test: | ||
override: | ||
- python2.7 setup.py test | ||
- python3.4 setup.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 |
---|---|---|
@@ -1,2 +1,13 @@ | ||
[wheel] | ||
universal = 1 | ||
|
||
[aliases] | ||
test = pytest | ||
|
||
[tool:pytest] | ||
addopts = --pylint --pylint-rcfile=setup.cfg | ||
|
||
[pylint] | ||
max-line-length = 120 | ||
known-standard-library = future | ||
disable = redefined-builtin,duplicate-code |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env python | ||
""" | ||
TinyCert | ||
-------- | ||
|
@@ -48,10 +49,15 @@ | |
'requests>=2.9.1' | ||
] | ||
|
||
SETUP_DEPS = [ | ||
'pytest-runner', | ||
'pytest-pylint', | ||
] | ||
|
||
TEST_DEPS = [ | ||
'mock>=1.3.0', | ||
'nose>=1.3.7', | ||
'pylint>=1.5.5', | ||
'pytest>=3.0.6', | ||
'requests-mock>=0.7.0' | ||
] | ||
|
||
|
@@ -63,13 +69,12 @@ | |
author='Christopher Eck', | ||
author_email='[email protected]', | ||
url='https://github.com/chrisleck/tinycert', | ||
bugtrack_url='https://github.com/chrisleck/tinycert/issues', | ||
license='MIT', | ||
long_description=__doc__, | ||
packages=['tinycert'], | ||
install_requires=INSTALL_DEPS, | ||
setup_requires=SETUP_DEPS, | ||
tests_require=TEST_DEPS, | ||
test_suite='nose.collector', | ||
platforms='any', | ||
zip_safe=True, | ||
classifiers=[ | ||
|
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 |
---|---|---|
@@ -1,79 +1,90 @@ | ||
"""Unit tests for the ca module.""" | ||
# pylint: disable=missing-docstring | ||
|
||
from __future__ import unicode_literals | ||
|
||
import unittest | ||
import mock | ||
import pytest | ||
|
||
from tinycert.ca import CertificateAuthorityApi | ||
|
||
|
||
class CertificateAuthorityApiTest(unittest.TestCase): | ||
"""Unit tests for the CertificateAuthorityApi class.""" | ||
def setUp(self): | ||
self.session = mock.MagicMock() | ||
self.session.request = mock.MagicMock() | ||
self.api = CertificateAuthorityApi(self.session) | ||
|
||
def list_test(self): | ||
expected_list = [ | ||
{'id': 123, 'name': 'test ca'}, | ||
{'id': 456, 'name': 'another test ca'} | ||
] | ||
self.session.request.return_value = expected_list | ||
|
||
result = self.api.list() | ||
self.assertEqual(result, expected_list) | ||
self.session.request.assert_called_with('ca/list') | ||
|
||
def details_test(self): | ||
expected_result = { | ||
'id': 123, | ||
'C': 'US', | ||
'ST': 'Washington', | ||
'L': 'Seattle', | ||
'O': 'Acme, Inc.', | ||
'OU': 'Secure Digital Certificate Signing', | ||
'CN': 'Acme, Inc. CA', | ||
'E': '[email protected]', | ||
'hash_alg': 'SHA256' | ||
} | ||
self.session.request.return_value = expected_result | ||
|
||
result = self.api.details(123) | ||
self.assertEqual(result, expected_result) | ||
self.session.request.assert_called_with('ca/details', {'ca_id': 123}) | ||
|
||
def get_test(self): | ||
expected_result = { | ||
'pem': ('-----BEGIN CERTIFICATE-----' | ||
'ABUNCHOFSTUFFHERE...' | ||
'-----END CERTIFICATE-----') | ||
} | ||
self.session.request.return_value = expected_result | ||
|
||
result = self.api.get(123) | ||
self.assertEqual(result, expected_result) | ||
self.session.request.assert_called_with('ca/get', {'ca_id': 123, 'what': 'cert'}) | ||
|
||
def delete_test(self): | ||
self.session.request.return_value = {} | ||
result = self.api.delete(123) | ||
self.assertEqual(result, {}) | ||
self.session.request.assert_called_with('ca/delete', {'ca_id': 123}) | ||
|
||
def create_test(self): | ||
expected_result = { | ||
'ca_id': 123 | ||
} | ||
self.session.request.return_value = expected_result | ||
|
||
create_detail = { | ||
'C': 'US', | ||
'O': 'Acme, Inc.', | ||
'L': 'Seattle', | ||
'ST': 'Washington', | ||
'hash_method': 'sha256' | ||
} | ||
result = self.api.create(create_detail) | ||
self.assertEqual(result, expected_result) | ||
self.session.request.assert_called_with('ca/new', create_detail) | ||
@pytest.fixture(name='session') | ||
def fixture_session(): | ||
fixture = mock.MagicMock() | ||
fixture.request = mock.MagicMock() | ||
return fixture | ||
|
||
|
||
@pytest.fixture(name='api') | ||
def fixture_api(session): | ||
return CertificateAuthorityApi(session) | ||
|
||
|
||
def list_test(session, api): | ||
expected_list = [ | ||
{'id': 123, 'name': 'test ca'}, | ||
{'id': 456, 'name': 'another test ca'} | ||
] | ||
session.request.return_value = expected_list | ||
|
||
result = api.list() | ||
assert result == expected_list | ||
session.request.assert_called_with('ca/list') | ||
|
||
|
||
def details_test(session, api): | ||
expected_result = { | ||
'id': 123, | ||
'C': 'US', | ||
'ST': 'Washington', | ||
'L': 'Seattle', | ||
'O': 'Acme, Inc.', | ||
'OU': 'Secure Digital Certificate Signing', | ||
'CN': 'Acme, Inc. CA', | ||
'E': '[email protected]', | ||
'hash_alg': 'SHA256' | ||
} | ||
session.request.return_value = expected_result | ||
|
||
result = api.details(123) | ||
assert result == expected_result | ||
session.request.assert_called_with('ca/details', {'ca_id': 123}) | ||
|
||
|
||
def get_test(session, api): | ||
expected_result = { | ||
'pem': ('-----BEGIN CERTIFICATE-----' | ||
'ABUNCHOFSTUFFHERE...' | ||
'-----END CERTIFICATE-----') | ||
} | ||
session.request.return_value = expected_result | ||
|
||
result = api.get(123) | ||
assert result == expected_result | ||
session.request.assert_called_with('ca/get', {'ca_id': 123, 'what': 'cert'}) | ||
|
||
|
||
def delete_test(session, api): | ||
session.request.return_value = {} | ||
result = api.delete(123) | ||
assert result == {} | ||
session.request.assert_called_with('ca/delete', {'ca_id': 123}) | ||
|
||
|
||
def create_test(session, api): | ||
expected_result = { | ||
'ca_id': 123 | ||
} | ||
session.request.return_value = expected_result | ||
|
||
create_detail = { | ||
'C': 'US', | ||
'O': 'Acme, Inc.', | ||
'L': 'Seattle', | ||
'ST': 'Washington', | ||
'hash_method': 'sha256' | ||
} | ||
result = api.create(create_detail) | ||
assert result == expected_result | ||
session.request.assert_called_with('ca/new', create_detail) |
Oops, something went wrong.