fix post methods bug

This commit is contained in:
Alex Lushpai 2018-04-22 21:39:27 +03:00
parent 85aaec98a7
commit cde242118b
5 changed files with 46 additions and 14 deletions

View File

@ -27,19 +27,19 @@ class Base(object):
:return: Response :return: Response
""" """
base_url = self.api_url + '/' + self.api_version if version else self.api_url base_url = self.api_url + '/' + self.api_version if version else self.api_url
requests_url = base_url + url if not self.parameters else base_url + \ requests_url = base_url + url if not self.parameters else base_url + url + "?" + query_builder(self.parameters)
url + "?" + query_builder(self.parameters)
response = requests.get(requests_url, headers={ response = requests.get(requests_url, headers={
'X-API-KEY': self.api_key}) 'X-API-KEY': self.api_key})
return Response(response.status_code, response.json()) return Response(response.status_code, response.json())
def post(self, url): def post(self, url, version=True):
""" """
Post request Post request
:return: Response :return: Response
""" """
requests_url = self.api_url + url base_url = self.api_url + '/' + self.api_version if version else self.api_url
requests_url = base_url + url
response = requests.post(requests_url, data=self.parameters, headers={ response = requests.post(requests_url, data=self.parameters, headers={
'X-API-KEY': self.api_key}) 'X-API-KEY': self.api_key})

View File

@ -312,7 +312,6 @@ class Client(Base):
def pack_edit(self, pack): def pack_edit(self, pack):
""" """
:param pack: :param pack:
:param uid:
:return: Response :return: Response
""" """
self.parameters['pack'] = json.dumps(pack) self.parameters['pack'] = json.dumps(pack)

View File

@ -170,7 +170,7 @@ class Client(Base):
code = str(field['code']) code = str(field['code'])
self.parameters['customField'] = json.dumps(field) self.parameters['customField'] = json.dumps(field)
return self.post('/custom-fields/' + entity + '/' + code + '/create') return self.post('/custom-fields/' + entity + '/' + code + '/create')
def customers(self, filters=None, limit=20, page=1): def customers(self, filters=None, limit=20, page=1):
""" """
@ -603,7 +603,6 @@ class Client(Base):
def pack_edit(self, pack): def pack_edit(self, pack):
""" """
:param pack: :param pack:
:param uid:
:return: Response :return: Response
""" """
self.parameters['pack'] = json.dumps(pack) self.parameters['pack'] = json.dumps(pack)
@ -1072,4 +1071,6 @@ class Client(Base):
:return: Response :return: Response
""" """
return self.post('/users/' + str(uid)) + '/' + status self.parameters['status'] = status
return self.post('/users/' + str(uid) + '/status')

View File

@ -8,14 +8,14 @@ import os
from setuptools import setup from setuptools import setup
def read(fname): def read(filename):
"""Read readme for long description""" """Read readme for long description"""
return open(os.path.join(os.path.dirname(__file__), fname)).read() return open(os.path.join(os.path.dirname(__file__), filename)).read()
setup( setup(
name='retailcrm', name='retailcrm',
version='5.0.2', version='5.0.3',
description='retailCRM API client', description='retailCRM API client',
long_description=read('README'), long_description=read('README'),
url='https://github.com/retailcrm/api-client-python', url='https://github.com/retailcrm/api-client-python',

View File

@ -27,7 +27,7 @@ class TestVersion5(unittest.TestCase):
V5 Test wrong api url V5 Test wrong api url
""" """
client = retailcrm.v5( client = retailcrm.v5(
'https://epoqwieqwpoieqpwoeiqpwoeiq.retailcrm.ru', '98sdf9sj8fsd9fjs9dfjs98') 'https://epoqwieqwpoieqpwoeiqpwoeiq.retailcrm.ru', '98sdf9sj8fsd9fjs9answer98')
response = client.statistic_update() response = client.statistic_update()
self.assertTrue(response.is_successful(), False) self.assertTrue(response.is_successful(), False)
@ -37,8 +37,7 @@ class TestVersion5(unittest.TestCase):
""" """
V5 Test wrong api key V5 Test wrong api key
""" """
client = retailcrm.v5(os.getenv('RETAILCRM_URL'), client = retailcrm.v5(os.getenv('RETAILCRM_URL'), '98sdf9sj8fsd9fjs9answer98')
'98sdf9sj8fsd9fjs9dfjs98')
response = client.statistic_update() response = client.statistic_update()
self.assertEqual(response.get_error_msg(), 'Wrong "apiKey" value.') self.assertEqual(response.get_error_msg(), 'Wrong "apiKey" value.')
@ -67,3 +66,36 @@ class TestVersion5(unittest.TestCase):
response = self.client.api_credentials() response = self.client.api_credentials()
self.assertTrue(response.is_successful(), True) self.assertTrue(response.is_successful(), True)
# def test_telephony_calls_upload(self):
# """
# V5 Test telephony calls upload
# """
#
# calls = [
# {
# 'date': '2018-04-20 22:10:00',
# 'type': 'in',
# 'phone': '+79999999999',
# 'userId': os.getenv('RETAILCRM_USER'),
# 'result': 'answered'
# },
# {
# 'date': '2018-04-20 22:10:00',
# 'type': 'out',
# 'phone': '+79999999999',
# 'userId': os.getenv('RETAILCRM_USER'),
# 'result': 'answered'
# }
# ]
#
# response = self.client.telephony_calls_upload(calls)
#
# self.assertTrue(response.is_successful(), True)
# self.assertTrue(response.get_status_code() < 400, True)
def test_set_user_status(self):
response = self.client.user_status(os.getenv('RETAILCRM_USER'), 'dinner')
self.assertTrue(response.is_successful(), True)
self.assertTrue(response.get_status_code() < 400, True)