Skip to content

Commit d299c26

Browse files
committed
- refactor tests
- add initial NetLicensing class - refactor actions
1 parent 8aef7cf commit d299c26

18 files changed

Lines changed: 74 additions & 81 deletions

.github/workflows/netlicensing-publish-pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflows will upload a Python Package using Twine when a release is created
22
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
33

4-
name: Build & Publish to PyPI
4+
name: Publish to PyPI
55

66
on:
77
release:

.github/workflows/netlicensing-publish-testpypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflows will upload a Python Package using Twine when a release is created
22
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
33

4-
name: Build & Publish to TestPyPI
4+
name: Publish to TestPyPI
55

66
on:
77
release:

.github/workflows/netlicensing-python-package.yml renamed to .github/workflows/netlicensing-python-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
33

4-
name: Test Python Package
4+
name: Python Client CI
55

66
on:
77
push:

CHANGELOG.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

netlicensing/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
def about():
2-
return (u'Labs64 NetLicensing is a first-class solution in the Licensing-as-a-Service (LaaS) sector.'
3-
u'Based on open standards, it provides a cost-effective, integrated and scalable platform for software vendors and developers'
4-
u'who want to concentrate on their product’s core functionality instead of spending resources on developing an own license management software.')
1+
from .netlicensing import NetLicensing
2+
3+
__all__ = ['NetLicensing']

netlicensing/netlicensing.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import json
2+
import requests
3+
4+
__all__ = ['NLIC_API_URL', 'NetLicensing']
5+
6+
NLIC_API_URL = 'https://go.netlicensing.io/core/v2/rest/'
7+
8+
class NetLicensing:
9+
def __init__(self, imp_url=NLIC_API_URL):
10+
self.imp_url = imp_url
11+
requests_session = requests.Session()
12+
requests_adapters = requests.adapters.HTTPAdapter(max_retries=3)
13+
requests_session.mount('https://', requests_adapters)
14+
self.requests_session = requests_session
15+
16+
def about(self):
17+
return (u'Labs64 NetLicensing is a first-class solution in the Licensing-as-a-Service (LaaS) sector.'
18+
u'Based on open standards, it provides a cost-effective, integrated and scalable platform for software vendors and developers'
19+
u'who want to concentrate on their product’s core functionality instead of spending resources on developing an own license management software.')
20+
21+
class ResponseError(Exception):
22+
def __init__(self, code=None, message=None):
23+
self.code = code
24+
self.message = message
25+
26+
class HttpError(Exception):
27+
def __init__(self, code=None, reason=None):
28+
self.code = code
29+
self.reason = reason
30+
31+
@staticmethod
32+
def get_response(response):
33+
if response.status_code != requests.codes.ok:
34+
raise NetLicensing.HttpError(response.status_code, response.reason)
35+
result = response.json()
36+
if result['code'] != 0:
37+
raise NetLicensing.ResponseError(
38+
result.get('code'), result.get('message')
39+
)
40+
return result.get('response')
41+
42+
def get_headers(self):
43+
return {'Accept': 'application/json'}
44+
45+
def _post(self, url, payload=None):
46+
headers = self.get_headers()
47+
response = self.requests_session.post(url, headers=headers, data=payload)
48+
return self.get_response(response)
49+
50+
def validate(self, licensee_uid):
51+
url = f'{self.imp_url}licensee/{licensee_uid}/validate'
52+
payload = {'licensee_uid': licensee_uid, 'amount': licensee_uid}
53+
return self._post(url, payload)

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
flake8
12
pytest
23
pytest-cov
4+
requests

script/test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Test app
44
#
55

6-
pip install -r requirements.txt
6+
pip3 install -r requirements.txt
77

88
py.test
99

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# https://packaging.python.org/guides/distributing-packages-using-setuptools/#setup-args
44
setuptools.setup(name='netlicensing-python-client',
5-
version='0.0.1.dev3',
5+
version='0.0.2',
66
description='Python wrapper for Labs64 NetLicensing RESTful API',
77
long_description=open('README.md').read().strip(),
88
long_description_content_type="text/markdown",

tests/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +0,0 @@
1-
import pytest
2-
from tests.tests_helper import *
3-
import unittest
4-
from tests.helpers import *
5-
6-
__all__ = [
7-
'pytest',
8-
'unittest',
9-
'tests_helper'
10-
]

0 commit comments

Comments
 (0)