Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ matrix:
python: 3.6

install:
- pip install -r test-requirements.txt
- pip install -r requirements/test.txt
- pip install -r requirements/sdk.txt

script:
- flake8 connectsdk
- flake8 connect
- pytest
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include requirements/sdk.txt
include connect/logger/config.json
include VERSION
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Connect Python SDK

[![Build Status](https://travis-ci.org/ingrammicro/connect-python-sdk.svg?branch=master)](https://travis-ci.org/ingrammicro/connect-python-sdk)
### Getting Started
---
### Class Features
Expand Down
10 changes: 10 additions & 0 deletions connect/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import resource

name = 'connect'

__all__ = [
'config',
'resource',
'models',
'logger',
]
12 changes: 9 additions & 3 deletions connectsdk/config.py → connect/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

import json
import os

Expand Down Expand Up @@ -86,9 +88,13 @@ def load_from_file(self, file):
raise TypeError('Invalid config file `{}`\n'
'ERROR: {}'.format(file, str(ex)))

(api_url, api_key, products) = (configs.get('apiEndpoint'),
configs.get('apiKey'),
configs.get('products'))
(api_url, api_key, products) = (configs.get('apiEndpoint', ''),
configs.get('apiKey', ''),
configs.get('products', ''))

products = products.encode('utf-8') if not isinstance(products, (str, list)) else products
api_url = api_url.encode('utf-8') if not isinstance(api_url, str) else api_url
api_key = api_key.encode('utf-8') if not isinstance(api_key, str) else api_key

self.check_credentials(api_url, api_key, products)
self._set_attr(api_url, api_key, products)
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion connectsdk/logger/logger.py → connect/logger/logger.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-

import json
import logging
import os
from logging.config import dictConfig

with open(os.path.join(os.path.dirname(__file__), 'config.json'), encoding="utf-8") as config_file:
with open(os.path.join(os.path.dirname(__file__), 'config.json')) as config_file:
config = json.load(config_file)

dictConfig(config['logging'])
Expand All @@ -20,4 +22,5 @@ def decorator(self, *args, **kwargs):
logger.debug(
'Function `{}.{}` return: {}'.format(self.__class__.__name__, func.__name__, result))
return result

return decorator
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .fulfilment_automation import FulfillmentAutomation
from .fulfillment_automation import FulfillmentAutomation
from .fulfillment import FulfillmentResource
from .template import TemplateResource

Expand Down
10 changes: 6 additions & 4 deletions connectsdk/resource/base.py → connect/resource/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-

import requests

from connectsdk.config import Config
from connectsdk.logger import function_log, logger
from connectsdk.models import BaseScheme, ServerErrorScheme
from connectsdk.models.exception import ServerErrorException
from connect.config import Config
from connect.logger import function_log, logger
from connect.models import BaseScheme, ServerErrorScheme
from connect.models.exception import ServerErrorException
from .utils import joinurl

config = Config()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# -*- coding: utf-8 -*-

import json

from connectsdk.config import Config
from connectsdk.models import FulfillmentScheme, Param
from connect.config import Config
from connect.logger import function_log
from connect.models import FulfillmentScheme, Param
from .base import BaseResource
from .template import TemplateResource
from .utils import joinurl
from connectsdk.logger import function_log


class FulfillmentResource(BaseResource):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from connectsdk.logger import logger
from connectsdk.models import ActivationTemplateResponse, ActivationTileResponse
from connectsdk.models.exception import FulfillmentFail, FulfillmentInquire, Skip
from connect.logger import logger
from connect.models import ActivationTemplateResponse, ActivationTileResponse
from connect.models.exception import FulfillmentFail, FulfillmentInquire, Skip
from .fulfillment import FulfillmentResource


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from connectsdk.models import ActivationTemplateResponse, ActivationTileResponse
from connect.models import ActivationTemplateResponse, ActivationTileResponse
from .base import BaseResource
from .utils import joinurl

Expand Down
2 changes: 2 additions & 0 deletions connectsdk/resource/utils.py → connect/resource/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

from requests.compat import urljoin


Expand Down
10 changes: 5 additions & 5 deletions example/example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from connectsdk.config import Config
from connectsdk.logger import logger
from connectsdk.models import ActivationTemplateResponse, ActivationTileResponse
from connectsdk.models.exception import FulfillmentFail, FulfillmentInquire, Skip
from connectsdk.resource import FulfillmentAutomation
from connect.config import Config
from connect.logger import logger
from connect.models import ActivationTemplateResponse, ActivationTileResponse
from connect.models.exception import FulfillmentFail, FulfillmentInquire, Skip
from connect.resource import FulfillmentAutomation

Config(file='config.json')

Expand Down
6 changes: 0 additions & 6 deletions requirements.txt

This file was deleted.

2 changes: 2 additions & 0 deletions requirements/sdk.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
marshmallow==2.18.0
requests==2.21.0
3 changes: 3 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flake8==3.7.5
pytest==4.2.0
mock==2.0.0
33 changes: 21 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
#!/usr/bin/env python

import os
from os.path import abspath, dirname, join
from setuptools import setup
from os.path import abspath, dirname, exists, join

from setuptools import find_packages, setup

try: # for pip >= 10
from pip._internal.req import parse_requirements
except ImportError: # for pip <= 9.0.3
from pip.req import parse_requirements

install_reqs = parse_requirements(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'requirements.txt'), session='None')

here = abspath(dirname(__file__))
install_reqs = parse_requirements(
join(
dirname(abspath(__file__)),
'requirements',
'sdk.txt',
), session='None')

here = dirname(abspath(__file__))
with open(join(here, 'VERSION')) as f:
VERSION = f.read()

packages = find_packages(exclude=['tests*'])

doc = ''
if exists('README.md'):
doc = open('README.md', 'r').read()

setup(
name='connectsdk',
name='connect-sdk',
author='Ingram Micro',
version=VERSION,
keywords='sdk connectsdk connect automation',
packages=['connectsdk'],
keywords='sdk connect connect automation',
packages=packages,
description='Connect Python SDK',
long_description='Documentation is described on '
'`GitHub <https://github.com/ingrammicro/connect-python-sdk>`_',
long_description=doc,
long_description_content_type='text/markdown',
url='https://github.com/ingrammicro/connect-python-sdk',
license='Apache Software License',
include_package_data=True,
Expand Down
1 change: 0 additions & 1 deletion test-requirements.txt

This file was deleted.

Empty file added tests/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

import json
from connect.config import Config
import os

conf_dict = {
'apiEndpoint': 'http://localhost:8080/api/public/v1/',
'apiKey': 'ApiKey XXXX:YYYYY',
'products': 'CN-631-322-000'
}
file_name = 'test_config.json'


def test_init_config_from_json_file():
file_path = os.path.join(os.path.dirname(__file__), file_name)
with open(file_path, 'w') as output:
output.write(json.dumps(conf_dict))

Config(file=file_path)

os.remove(file_path)

assert Config.api_key == conf_dict.get('apiKey')
assert Config.api_url == conf_dict.get('apiEndpoint')
assert Config.products == [conf_dict.get('products')]