Skip to content

Commit

Permalink
Merge pull request #4 from chrisleck/auto-lint-testing
Browse files Browse the repository at this point in the history
Code cleanup in preparation for next release
  • Loading branch information
chrisleck authored Feb 14, 2017
2 parents 95d7ee4 + 88f7fc6 commit 8945737
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 240 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.DS_Store
.cache/
.coverage
build
dist
*.egg
Expand Down
13 changes: 13 additions & 0 deletions circle.yml
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
11 changes: 11 additions & 0 deletions setup.cfg
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
11 changes: 8 additions & 3 deletions setup.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
"""
TinyCert
--------
Expand Down Expand Up @@ -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'
]

Expand All @@ -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=[
Expand Down
153 changes: 82 additions & 71 deletions test/ca_test.py
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)
Loading

0 comments on commit 8945737

Please sign in to comment.