diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3698d8b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,67 @@ +name: ci + +on: + push: + branches: + - '**' + tags-ignore: + - '*.*' + pull_request: + +env: + RETAILCRM_URL: https://test.retailcrm.pro + RETAILCRM_KEY: key + +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.5, 3.6, 3.7] + include: + - python-version: '3.8' + coverage: 1 + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Cache pip + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --ignore=F401 + - name: Tests + env: + COVERAGE: ${{ matrix.coverage }} + if: env.COVERAGE != 1 + run: nosetests -v + - name: Tests with coverage + env: + COVERAGE: ${{ matrix.coverage }} + if: env.COVERAGE == 1 + run: | + nosetests -v --with-coverage --cover-xml + - name: Coverage + env: + COVERAGE: ${{ matrix.coverage }} + if: env.COVERAGE == 1 + run: | + bash <(curl -s https://codecov.io/bash) + rm .coverage coverage.xml diff --git a/.gitignore b/.gitignore index 20ba138..be9fa10 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,7 @@ /dist/ /venv/ /.vscode/ -/build/ \ No newline at end of file +/build/ +.python-version +.coverage +coverage.xml \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c91455d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: python -python: - - '3.4' - - '3.5' - - '3.6' - - '3.7' - - '3.8' -before_install: - - pip install -r requirements.txt -script: - - nosetests -v --with-coverage --cover-xml -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/retailcrm/versions/__init__.py b/retailcrm/versions/__init__.py index e0bcbc7..03645d0 100644 --- a/retailcrm/versions/__init__.py +++ b/retailcrm/versions/__init__.py @@ -2,4 +2,4 @@ """ Init -""" \ No newline at end of file +""" diff --git a/retailcrm/versions/v3.py b/retailcrm/versions/v3.py index bb9ba3e..36665a4 100644 --- a/retailcrm/versions/v3.py +++ b/retailcrm/versions/v3.py @@ -469,7 +469,7 @@ class Client(Base): """ if site is not None: self.parameters['site'] = site - + self.parameters['offers'] = json.dumps(offers) return self.post('/store/inventories/upload') @@ -532,5 +532,5 @@ class Client(Base): """ :return: Response """ - + return self.get('/statistic/update') diff --git a/retailcrm/versions/v5.py b/retailcrm/versions/v5.py index d3d76c5..55722e5 100644 --- a/retailcrm/versions/v5.py +++ b/retailcrm/versions/v5.py @@ -504,11 +504,15 @@ class Client(Base): if site is not None: self.parameters['site'] = site - return self.post('/customers-corporate/' + - str(uid_corporate) + - '/addresses/' + - str(address[entity_by]) + - '/edit') + return self.post("".join( + [ + '/customers-corporate/', + str(uid_corporate), + '/addresses/', + str(address[entity_by]), + '/edit' + ] + )) def customer_corporate_companies(self, uid, uid_type='externalId', limit=20, page=1, filters=None, site=None): """ @@ -575,8 +579,7 @@ class Client(Base): if site is not None: self.parameters['site'] = site - return self.post('/customers-corporate/' + - str(uid_corporate) + '/companies/' + str(company[entity_by]) + '/edit') + return self.post('/customers-corporate/' + str(uid_corporate) + '/companies/' + str(company[entity_by]) + '/edit') def customer_corporate_contacts(self, uid, uid_type='externalId', limit=20, page=1, filters=None, site=None): """ @@ -643,8 +646,7 @@ class Client(Base): if site is not None: self.parameters['site'] = site - return self.post('/customers-corporate/' + - str(uid_corporate) + '/contacts/' + str(contact[entity_by]) + '/edit') + return self.post('/customers-corporate/' + str(uid_corporate) + '/contacts/' + str(contact[entity_by]) + '/edit') def customer_corporate_edit(self, customer_corporate, uid_type='externalId', site=None): """ diff --git a/setup.py b/setup.py index a38d90a..87547b8 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ def read(filename): setup( name='retailcrm', - version='5.1.0', + version='5.1.1', description='RetailCRM API client', long_description=read('README'), url='https://github.com/retailcrm/api-client-python', @@ -34,7 +34,6 @@ setup( 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', diff --git a/tests/v3_tests.py b/tests/v3_tests.py index 19d1b70..9495536 100644 --- a/tests/v3_tests.py +++ b/tests/v3_tests.py @@ -111,8 +111,7 @@ class TestVersion3(unittest.TestCase): Setup """ - self.client = retailcrm.v3( - os.getenv('RETAILCRM_URL'), os.getenv('RETAILCRM_KEY')) + self.client = retailcrm.v3(os.getenv('RETAILCRM_URL'), os.getenv('RETAILCRM_KEY')) @staticmethod def dictionaryEncode(key, dictionary): @@ -1509,13 +1508,7 @@ class TestVersion3(unittest.TestCase): (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/telephony/call/event') .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) - .body(urlencode( - { - 'hangupStatus': 'busy', - 'phone': '+799999999', - 'code': 'c2321', - 'type': 'hangup' - })) + .body(urlencode({'hangupStatus': 'busy', 'phone': '+799999999', 'code': 'c2321', 'type': 'hangup'})) .reply(200) .headers(self.__header) .json({'success': 'true'}) @@ -1609,21 +1602,20 @@ class TestVersion3(unittest.TestCase): code = 'xxx' - (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/telephony/settings/' + code) - .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) - .body(urlencode( - { - 'code': code, - 'clientId': '123x', - 'makeCallUrl': 'url', - 'active': 'active', - 'name': 'name', - 'image': 'url_image' - })) - .reply(201) - .headers(self.__header) - .json({'success': 'true'}) - ) + ( + pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/telephony/settings/' + code) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(urlencode({ + 'code': code, + 'clientId': '123x', + 'makeCallUrl': 'url', + 'active': 'active', + 'name': 'name', + 'image': 'url_image'})) + .reply(201) + .headers(self.__header) + .json({'success': 'true'}) + ) response = self.client.telephony_settings(code, '123x', 'url', 'active', 'name', 'url_image') pook.off() diff --git a/tests/v4_tests.py b/tests/v4_tests.py index c055522..dd64542 100644 --- a/tests/v4_tests.py +++ b/tests/v4_tests.py @@ -107,8 +107,7 @@ class TestVersion4(unittest.TestCase): Setup """ - self.client = retailcrm.v4( - os.getenv('RETAILCRM_URL'), os.getenv('RETAILCRM_KEY')) + self.client = retailcrm.v4(os.getenv('RETAILCRM_URL'), os.getenv('RETAILCRM_KEY')) @staticmethod def dictionaryEncode(key, dictionary): @@ -310,11 +309,11 @@ class TestVersion4(unittest.TestCase): ) response = self.client.customers_history( - { - 'sinceId': '1111', - 'startDate': '2016-01-07', - 'endDate': '2020-04-12' - } + { + 'sinceId': '1111', + 'startDate': '2016-01-07', + 'endDate': '2020-04-12' + } ) pook.off() @@ -710,11 +709,11 @@ class TestVersion4(unittest.TestCase): ) response = self.client.orders_history( - { - 'sinceId': '1111', - 'startDate': '2016-01-07', - 'endDate': '2020-04-12' - } + { + 'sinceId': '1111', + 'startDate': '2016-01-07', + 'endDate': '2020-04-12' + } ) pook.off() diff --git a/tests/v5_tests.py b/tests/v5_tests.py index f1c4f37..ed93a13 100644 --- a/tests/v5_tests.py +++ b/tests/v5_tests.py @@ -1,6 +1,5 @@ # coding=utf-8 - """ RetailCRM API client v5 tests """ @@ -189,8 +188,7 @@ class TestVersion5(unittest.TestCase): Setup """ - self.client = retailcrm.v5( - os.getenv('RETAILCRM_URL'), os.getenv('RETAILCRM_KEY')) + self.client = retailcrm.v5(os.getenv('RETAILCRM_URL'), os.getenv('RETAILCRM_KEY')) @staticmethod def dictionaryEncode(key, dictionary): @@ -413,7 +411,7 @@ class TestVersion5(unittest.TestCase): self.assertTrue(response.get_status_code() < 400, True) @pook.on - def test_costs_delete(self): + def test_costs_delete_v5(self): """ V5 Test method costs_delete """ @@ -617,17 +615,18 @@ class TestVersion5(unittest.TestCase): 'elements': [{'name': 'fear', 'code': 'e456'}] } - (pook.post( - os.getenv('RETAILCRM_URL') + - '/api/v5/custom-fields/dictionaries/' + - custom_dictionary['code'] + - '/edit') + (pook.post("".join( + [ + os.getenv('RETAILCRM_URL'), + '/api/v5/custom-fields/dictionaries/', + custom_dictionary['code'], + '/edit' + ])) .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) .body(self.dictionaryEncode('customDictionary', custom_dictionary)) .reply(200) .headers(self.__header) - .json({'success': 'true', 'code': 'test'}) - ) + .json({'success': 'true', 'code': 'test'})) response = self.client.custom_dictionary_edit(custom_dictionary) pook.off() @@ -883,12 +882,13 @@ class TestVersion5(unittest.TestCase): ) response = self.client.customers_history( - { - 'sinceId': '1111', - 'startDate': '2016-01-07', - 'endDate': '2020-04-12' - } + { + 'sinceId': '1111', + 'startDate': '2016-01-07', + 'endDate': '2020-04-12' + } ) + pook.off() self.assertTrue(response.is_successful(), True) @@ -1145,7 +1145,7 @@ class TestVersion5(unittest.TestCase): self.assertTrue(response.get_status_code() < 400, True) @pook.on - def test_customers_history(self): + def test_customers_history_v5(self): """ V5 Test method customers_corporate_history """ @@ -1199,11 +1199,11 @@ class TestVersion5(unittest.TestCase): ) response = self.client.customers_corporate_history( - { - 'sinceId': '1111', - 'startDate': '2016-01-07', - 'endDate': '2020-04-12' - } + { + 'sinceId': '1111', + 'startDate': '2016-01-07', + 'endDate': '2020-04-12' + } ) pook.off() @@ -1364,7 +1364,7 @@ class TestVersion5(unittest.TestCase): 'success': 'true', 'addresses': [{ 'id': 3995, - 'text': '123123, Russian Federation, Moscow, Kutuzovski 14', + 'text': '123123, Russian Federation, Moscow, Kubuntu 14', 'isMain': 'true', 'name': 'Test' }], @@ -1392,15 +1392,12 @@ class TestVersion5(unittest.TestCase): address = {'isMain': 'true', 'name': 'Test', 'externalId': 'cc_9'} - (pook.post( - os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + address[ - 'externalId'] + '/addresses/create') + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + address['externalId'] + '/addresses/create') .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) .body(self.dictionaryEncode('address', address)) .reply(200) .headers(self.__header) - .json({'success': 'true', 'id': 9717}) - ) + .json({'success': 'true', 'id': 9717})) response = self.client.customer_corporate_addresses_create(address) pook.off() @@ -1496,9 +1493,7 @@ class TestVersion5(unittest.TestCase): company = {'isMain': 'true', 'name': 'TestN', 'externalId': 'cc_9'} - (pook.post( - os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + company[ - 'externalId'] + '/companies/create') + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + company['externalId'] + '/companies/create') .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) .body(self.dictionaryEncode('company', company)) .reply(200) @@ -1588,9 +1583,7 @@ class TestVersion5(unittest.TestCase): contact = {'isMain': 'true', 'name': 'TestM', 'externalId': 'cc_9'} - (pook.post( - os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + contact[ - 'externalId'] + '/contacts/create') + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + contact['externalId'] + '/contacts/create') .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) .body(self.dictionaryEncode('contact', contact)) .reply(200) @@ -1670,8 +1663,7 @@ class TestVersion5(unittest.TestCase): (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/delivery/generic/' + code + '/tracking') .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) - .body(self.dictionaryEncode( - 'statusUpdate', delivery_id)) + .body(self.dictionaryEncode('statusUpdate', delivery_id)) .reply(200) .headers(self.__header) .json({'success': 'true'}) @@ -2007,30 +1999,29 @@ class TestVersion5(unittest.TestCase): 'currentPage': '1', 'totalPageCount': '87' }, - 'integrationModule': - { - 'success': 'true', - 'integrationModule': { - 'code': 'xxx', - 'integrationCode': 'xxx', - 'active': 'true', - 'freeze': 'false', - 'name': 'test', - 'native': 'false', - 'actions': {}, - 'availableCountries': [], - 'integrations': { - 'store': { - 'actions': [ - { - 'code': 'ccc', - 'url': 'https://test' - } - ] - } + 'integrationModule': { + 'success': 'true', + 'integrationModule': { + 'code': 'xxx', + 'integrationCode': 'xxx', + 'active': 'true', + 'freeze': 'false', + 'name': 'test', + 'native': 'false', + 'actions': {}, + 'availableCountries': [], + 'integrations': { + 'store': { + 'actions': [ + { + 'code': 'ccc', + 'url': 'https://test' + } + ] } } } + } } ) ) @@ -2262,11 +2253,11 @@ class TestVersion5(unittest.TestCase): ) response = self.client.orders_history( - { - 'sinceId': '1111', - 'startDate': '2016-01-07', - 'endDate': '2020-04-12' - } + { + 'sinceId': '1111', + 'startDate': '2016-01-07', + 'endDate': '2020-04-12' + } ) pook.off() @@ -2470,7 +2461,7 @@ class TestVersion5(unittest.TestCase): self.assertTrue(response.get_status_code() < 400, True) @pook.on - def test_orders_statuses(self): + def test_orders_statuses_v5(self): """ V5 Test method orders_statuses """ @@ -2502,7 +2493,7 @@ class TestVersion5(unittest.TestCase): self.assertTrue(response.get_status_code() < 400, True) @pook.on - def test_orders_upload(self): + def test_orders_upload_v5(self): """ V5 Test method orders_upload """ @@ -2533,7 +2524,7 @@ class TestVersion5(unittest.TestCase): self.assertTrue(response.get_status_code() < 400, True) @pook.on - def test_order(self): + def test_order_v5(self): """ V5 Test method order """ @@ -4670,11 +4661,10 @@ class TestVersion5(unittest.TestCase): """ (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/statistic/update') - .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) - .reply(200) - .headers(self.__header) - .json({'success': 'true'}) - ) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true'})) response = self.client.statistic_update() pook.off()