From eecf9d8afaba646e5aaa7ba1493480a0a8e04b8b Mon Sep 17 00:00:00 2001 From: Henrik Blidh Date: Tue, 17 Nov 2015 22:46:17 +0100 Subject: [PATCH] Version 0.3.0 Refactoring som importing of bankid is sufficient. Preparation for PyPi deployment --- README.rst | 6 +++--- bankid/__init__.py | 39 ++++++++++++++++++++++----------------- bankid/testcert.py | 11 ++++++----- setup.py | 24 ++++++++++++++---------- tests/test_client.py | 10 ++++------ 5 files changed, 49 insertions(+), 41 deletions(-) diff --git a/README.rst b/README.rst index ec78857..545ef90 100644 --- a/README.rst +++ b/README.rst @@ -21,11 +21,11 @@ exists and can be found in deployed state on `Heroku >> from bankid.client import BankIDClient + >>> from bankid import BankIDClient >>> client = BankIDClient(certificates=('path/to/certificate.pem', 'path/to/key.pem')) diff --git a/bankid/__init__.py b/bankid/__init__.py index 010ad04..1306b4e 100644 --- a/bankid/__init__.py +++ b/bankid/__init__.py @@ -2,18 +2,24 @@ # -*- coding: utf-8 -*- """Release data for the PyBankID project.""" +from .client import BankIDClient +import bankid.exceptions as exceptions +from .testcert import create_bankid_test_server_cert_and_key + +__all__ = ['BankIDClient', 'exceptions', 'create_bankid_test_server_cert_and_key', 'version'] + # Name of the package for release purposes. This is the name which labels # the tarballs and RPMs made by distutils, so it's best to lowercase it. -name = 'pybankid' +_name = 'pybankid' # Version information. An empty _version_extra corresponds to a full # release. 'dev' as a _version_extra string means this is a development # version. _version_major = 0 -_version_minor = 2 -_version_patch = 2 +_version_minor = 3 +_version_patch = 0 # _version_extra = 'dev4' -# _version_extra = 'b2' +# _version_extra = 'a1' _version_extra = '' # Uncomment this for full releases # Construct full version string from these. @@ -26,9 +32,9 @@ version = __version__ # backwards compatibility name version_info = (_version_major, _version_minor, _version_patch, _version_extra) -description = "BankID client for Python" +_description = "BankID client for Python" -long_description = """ +_long_description = """ PyBankID is a client for performing BankID signing. The Swedish BankID solution for digital signing uses a SOAP @@ -38,24 +44,23 @@ The latest development version is available at the project's `GitHub site `_. - """ -license = 'MIT' +__license__ = 'MIT' -authors = { +_authors = { 'hbldh': ('Henrik Blidh', 'henrik.blidh@nedomkull.com'), } -author = 'Henrik Blidh' -author_email = 'henrik.blidh@nedomkull.com' -url = 'https://github.com/hbldh/pybankid/' -download_url = 'https://github.com/hbldh/pybankid/downloads' +_author = 'Henrik Blidh' +_author_email = 'henrik.blidh@nedomkull.com' +_url = 'https://github.com/hbldh/pybankid/' +_download_url = 'https://github.com/hbldh/pybankid/tarball/' + '.'.join(map(str, _ver)) -platforms = ['Linux', 'Mac OSX', 'Windows XP/Vista/7/8'] -keywords = ['BankID', 'SOAP'] -classifiers = [ +_platforms = ['Linux', 'Mac OSX', 'Windows XP/Vista/7/8'] +_keywords = ['BankID', 'SOAP'] +_classifiers = [ 'Programming Language :: Python', - 'Programming Language :: Python :: 2' + 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', diff --git a/bankid/testcert.py b/bankid/testcert.py index f75454e..5e3ddb1 100644 --- a/bankid/testcert.py +++ b/bankid/testcert.py @@ -19,7 +19,6 @@ from __future__ import absolute_import import os -import re import tempfile import subprocess import sys @@ -29,7 +28,7 @@ _TEST_CERT_URL = "https://www.bankid.com/assets/bankid/rp/FPTestcert2_20150818_102329.pfx" -def create_test_server_cert_and_key(destination_path): +def create_bankid_test_server_cert_and_key(destination_path): """Fetch the P12 certificate from BankID servers, split it into a certificate part and a key part and save them as separate files, stored in PEM format. @@ -48,8 +47,10 @@ def create_test_server_cert_and_key(destination_path): certificate, key = split_test_cert_and_key() # Paths to output files. - out_cert_path = os.path.join(os.path.abspath(destination_path), 'cert.pem') - out_key_path = os.path.join(os.path.abspath(destination_path), 'key.pem') + out_cert_path = os.path.join(os.path.abspath( + os.path.expanduser(destination_path)), 'cert.pem') + out_key_path = os.path.join(os.path.abspath( + os.path.expanduser(destination_path)), 'key.pem') with open(out_cert_path, 'wt') as f: f.write(certificate) @@ -120,7 +121,7 @@ def split_test_cert_and_key(): def main(): - paths = create_test_server_cert_and_key(os.path.expanduser('~')) + paths = create_bankid_test_server_cert_and_key(os.path.expanduser('~')) print('Saved certificate as {0}'.format(paths[0])) print('Saved key as {0}'.format(paths[1])) diff --git a/setup.py b/setup.py index 7b5869f..dcb6118 100644 --- a/setup.py +++ b/setup.py @@ -23,17 +23,21 @@ setup( name='pybankid', version=bankid.__version__, - author=bankid.author, - author_email=bankid.author_email, - description=bankid.description, - long_description=bankid.long_description, - license=bankid.license, - url=bankid.url, - classifiers=bankid.classifiers, - platforms=bankid.platforms, - packages=find_packages(), + author=bankid._author, + author_email=bankid._author_email, + description=bankid._description, + long_description=bankid._long_description, + license=bankid.__license__, + url=bankid._url, + classifiers=bankid._classifiers, + platforms=bankid._platforms, + packages=find_packages(exclude=('tests', )), package_data={'': ['*.pem']}, - install_requires=[line.strip() for line in open("requirements.txt")], + install_requires=[ + 'requests>=2.7.0', + 'suds-jurko>=0.6', + 'six>=1.9.0' + ], dependency_links=[], ext_modules=[], entry_points={ diff --git a/tests/test_client.py b/tests/test_client.py index 983c166..f096d31 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -26,9 +26,7 @@ from nose.tools import raises -import bankid.client -import bankid.testcert -import bankid.exceptions +import bankid def get_random_personal_number(): @@ -76,7 +74,7 @@ def __init__(self): self.key_file = None def setup(self): - certificate, key = bankid.testcert.create_test_server_cert_and_key(tempfile.gettempdir()) + certificate, key = bankid.create_bankid_test_server_cert_and_key(tempfile.gettempdir()) self.certificate_file = certificate self.key_file = key @@ -90,7 +88,7 @@ def teardown(self): def test_authentication_and_collect(self): """Authenticate call and then collect with the returned orderRef UUID.""" - c = bankid.client.BankIDClient(certificates=(self.certificate_file, self.key_file), test_server=True) + c = bankid.BankIDClient(certificates=(self.certificate_file, self.key_file), test_server=True) out = c.authenticate(get_random_personal_number()) assert isinstance(out, dict) # UUID.__init__ performs the UUID compliance assertion. @@ -100,7 +98,7 @@ def test_authentication_and_collect(self): @raises(bankid.exceptions.InvalidParametersError) def test_invalid_orderref_raises_error(self): - c = bankid.client.BankIDClient(certificates=(self.certificate_file, self.key_file), test_server=True) + c = bankid.BankIDClient(certificates=(self.certificate_file, self.key_file), test_server=True) collect_status = c.collect('invalid-uuid') @raises(bankid.exceptions.AlreadyInProgressError)