From 12790245f939b38fb9383e8ff6a02efa31aef540 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Thu, 20 Aug 2020 14:44:41 +0300 Subject: [PATCH] Missed methods, tests (#19) --- .travis.yml | 1 + README | 4 +- README.md | 4 +- requirements.txt | 6 +- retailcrm/versions/v3.py | 131 +- retailcrm/versions/v4.py | 153 +- retailcrm/versions/v5.py | 734 ++++-- setup.py | 5 +- tests/v3_tests.py | 1594 ++++++++++++- tests/v4_tests.py | 2183 +++++++++++++++++- tests/v5_tests.py | 4636 +++++++++++++++++++++++++++++++++++++- 11 files changed, 9129 insertions(+), 322 deletions(-) diff --git a/.travis.yml b/.travis.yml index 216eef5..c91455d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ python: - '3.5' - '3.6' - '3.7' + - '3.8' before_install: - pip install -r requirements.txt script: diff --git a/README b/README index 41ff9a3..f69296c 100644 --- a/README +++ b/README @@ -75,5 +75,5 @@ Documentation - `English`_ - `Russian`_ -.. _English: http://www.retailcrm.pro/docs/Developers/Index -.. _Russian: http://www.retailcrm.ru/docs/Developers/Index \ No newline at end of file +.. _English: https://help.retailcrm.pro/Developers/Index +.. _Russian: https://help.retailcrm.ru/Developers/Index diff --git a/README.md b/README.md index 6ef288c..74480a9 100644 --- a/README.md +++ b/README.md @@ -77,5 +77,5 @@ result = client.task_create(task, site) ## Documentation -* [English](http://www.retailcrm.pro/docs/Developers/Index) -* [Russian](http://www.retailcrm.ru/docs/Developers/Index) +* [English](https://help.retailcrm.pro/Developers/Index) +* [Russian](https://help.retailcrm.ru/Developers/Index) diff --git a/requirements.txt b/requirements.txt index 871dfba..a724468 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ multidimensional-urlencode==0.0.4 nose==1.3.7 -requests==2.20.0 -coverage==4.5.4 +requests==2.24.0 +coverage==5.2.1 +pook==1.0.1 +setuptools==49.6.0 diff --git a/retailcrm/versions/v3.py b/retailcrm/versions/v3.py index cc9409d..d248343 100644 --- a/retailcrm/versions/v3.py +++ b/retailcrm/versions/v3.py @@ -19,9 +19,9 @@ class Client(Base): def customers(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -32,8 +32,8 @@ class Client(Base): def customer_create(self, customer, site=None): """ - :param customer: - :param site: + :param customer: object + :param site: string :return: Response """ self.parameters['customer'] = json.dumps(customer) @@ -45,8 +45,8 @@ class Client(Base): def customers_fix_external_ids(self, customers, site=None): """ - :param customers: - :param site: + :param customers: object + :param site: string :return: Response """ self.parameters['customers'] = json.dumps(customers) @@ -58,8 +58,8 @@ class Client(Base): def customers_upload(self, customers, site=None): """ - :param customers: - :param site: + :param customers: array of objects + :param site: string :return: Response """ self.parameters['customers'] = json.dumps(customers) @@ -71,9 +71,9 @@ class Client(Base): def customer(self, uid, uid_type='externalId', site=None): """ - :param uid: - :param uid_type: - :param site: + :param uid: string + :param uid_type: string + :param site: string :return: Response """ if uid_type != 'externalId': @@ -86,9 +86,9 @@ class Client(Base): def customer_edit(self, customer, uid_type='externalId', site=None): """ - :param customer: - :param uid_type: - :param site: + :param customer: object + :param uid_type: string + :param site: string :return: Response """ self.parameters['customer'] = json.dumps(customer) @@ -103,7 +103,7 @@ class Client(Base): def orders(self, filters=None, limit=20, page=1): """ - :param filters: array + :param filters: object :param limit: integer :param page: integer :return: Response @@ -142,11 +142,11 @@ class Client(Base): def orders_history(self, start=None, end=None, limit=100, offset=0, skip=True): """ - :param start: - :param end: - :param limit: - :param offset: - :param skip: + :param start: DateTime + :param end: DateTime + :param limit: integer + :param offset: integer + :param skip: boolean :return: Response """ self.parameters['startDate'] = start @@ -215,9 +215,9 @@ class Client(Base): def packs(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -228,7 +228,7 @@ class Client(Base): def pack_create(self, pack): """ - :param pack: + :param pack: object :return: Response """ self.parameters['pack'] = json.dumps(pack) @@ -237,9 +237,9 @@ class Client(Base): def packs_history(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -250,7 +250,7 @@ class Client(Base): def pack(self, uid): """ - :param uid: + :param uid: integer :return: Response """ @@ -258,7 +258,7 @@ class Client(Base): def pack_delete(self, uid): """ - :param uid: + :param uid: integer :return: Response """ @@ -266,7 +266,7 @@ class Client(Base): def pack_edit(self, pack): """ - :param pack: + :param pack: object :return: Response """ self.parameters['pack'] = json.dumps(pack) @@ -289,7 +289,7 @@ class Client(Base): def delivery_services_edit(self, delivery_service): """ - :param delivery_service: + :param delivery_service: object :return: Response """ self.parameters['deliveryService'] = json.dumps(delivery_service) @@ -305,7 +305,7 @@ class Client(Base): def delivery_types_edit(self, delivery_type): """ - :param delivery_type: + :param delivery_type: object :return: Response """ self.parameters['deliveryType'] = json.dumps(delivery_type) @@ -322,7 +322,7 @@ class Client(Base): def order_methods_edit(self, order_method): """ - :param order_method: + :param order_method: object :return: Response """ self.parameters['orderMethod'] = json.dumps(order_method) @@ -338,7 +338,7 @@ class Client(Base): def order_types_edit(self, order_type): """ - :param order_type: + :param order_type: object :return: Response """ self.parameters['orderType'] = json.dumps(order_type) @@ -354,7 +354,7 @@ class Client(Base): def payment_statuses_edit(self, payment_status): """ - :param payment_status: + :param payment_status: object :return: Response """ self.parameters['paymentStatus'] = json.dumps(payment_status) @@ -370,7 +370,7 @@ class Client(Base): def payment_types_edit(self, payment_type): """ - :param payment_type: + :param payment_type: object :return: Response """ self.parameters['paymentType'] = json.dumps(payment_type) @@ -386,7 +386,7 @@ class Client(Base): def product_statuses_edit(self, product_status): """ - :param product_status: + :param product_status: object :return: Response """ self.parameters['productStatus'] = json.dumps(product_status) @@ -402,7 +402,7 @@ class Client(Base): def sites_edit(self, site): """ - :param site: + :param site: object :return: Response """ self.parameters['site'] = json.dumps(site) @@ -411,7 +411,7 @@ class Client(Base): def status_groups(self): """ - :return + :return: Response """ return self.get('/reference/status-groups') @@ -425,7 +425,7 @@ class Client(Base): def statuses_edit(self, status): """ - :param status: + :param status: object :return: Response """ self.parameters['status'] = json.dumps(status) @@ -441,18 +441,18 @@ class Client(Base): def stores_edit(self, store): """ - :param store: + :param store: object :return: Response """ - self.parameters['status'] = json.dumps(store) + self.parameters['store'] = json.dumps(store) return self.post('/reference/stores/' + store['code'] + '/edit') def inventories(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -463,8 +463,8 @@ class Client(Base): def inventories_upload(self, offers, site=None): """ - :param offers: - :param site: + :param offers: array of objects + :param site: string :return: Response """ if site is not None: @@ -476,10 +476,10 @@ class Client(Base): def telephony_call_event(self, phone, call_type, code, status): """ - :param phone: - :param call_type: - :param code: - :param status: + :param phone: string + :param call_type: string + :param code: string + :param status: string :return: Response """ self.parameters['hangupStatus'] = status @@ -491,7 +491,7 @@ class Client(Base): def telephony_calls_upload(self, calls): """ - :param calls: + :param calls: array of objects :return: Response """ self.parameters['calls'] = json.dumps(calls) @@ -500,9 +500,9 @@ class Client(Base): def telephony_manager(self, phone, details=True): """ - :param phone: - :param details: - :return: Response + :param phone: string + :param details: string + :return: Response string """ self.parameters['phone'] = phone self.parameters['details'] = details @@ -511,12 +511,12 @@ class Client(Base): def telephony_settings(self, code, client_id, make_call_url, active, name, image): """ - :param code: - :param client_id: - :param make_call_url: - :param active: - :param name: - :param image: + :param code: string + :param client_id: string + :param make_call_url: string + :param active: string + :param name: string + :param image: string :return: Response """ self.parameters['code'] = code @@ -527,3 +527,10 @@ class Client(Base): self.parameters['image'] = image return self.post('/telephony/settings/' + str(code)) + + def statistic_update(self): + """ + :return: Response + """ + + return self.get('/statistic/update') diff --git a/retailcrm/versions/v4.py b/retailcrm/versions/v4.py index 91b028d..6c357d7 100644 --- a/retailcrm/versions/v4.py +++ b/retailcrm/versions/v4.py @@ -19,9 +19,9 @@ class Client(Base): def customers(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -32,8 +32,8 @@ class Client(Base): def customer_create(self, customer, site=None): """ - :param customer: - :param site: + :param customer: object + :param site: string :return: Response """ self.parameters['customer'] = json.dumps(customer) @@ -45,8 +45,8 @@ class Client(Base): def customers_fix_external_ids(self, customers, site=None): """ - :param customers: - :param site: + :param customers: array of objects + :param site: string :return: Response """ self.parameters['customers'] = json.dumps(customers) @@ -58,9 +58,9 @@ class Client(Base): def customers_history(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -71,8 +71,8 @@ class Client(Base): def customers_upload(self, customers, site=None): """ - :param customers: - :param site: + :param customers: array of objects + :param site: string :return: Response """ self.parameters['customers'] = json.dumps(customers) @@ -84,9 +84,9 @@ class Client(Base): def customer(self, uid, uid_type='externalId', site=None): """ - :param uid: - :param uid_type: - :param site: + :param uid: string + :param uid_type: string + :param site: string :return: Response """ if uid_type != 'externalId': @@ -99,9 +99,9 @@ class Client(Base): def customer_edit(self, customer, uid_type='externalId', site=None): """ - :param customer: - :param uid_type: - :param site: + :param customer: object + :param uid_type: string + :param site: string :return: Response """ self.parameters['customer'] = json.dumps(customer) @@ -116,7 +116,7 @@ class Client(Base): def delivery_setting(self, code): """ - :param code: + :param code: string :return: Response """ @@ -124,17 +124,17 @@ class Client(Base): def delivery_setting_edit(self, configuration): """ - :param configuration:: + :param configuration: object :return: Response """ self.parameters['configuration'] = json.dumps(configuration) - return self.post('/delivery/generic/setting/' + str(configuration['code'])) + '/edit' + return self.post('/delivery/generic/setting/' + str(configuration['code']) + '/edit') def delivery_tracking(self, code, status_update): """ - :param code: - :param status_update: + :param code: string + :param status_update: array of objects :return: Response """ self.parameters['statusUpdate'] = json.dumps(status_update) @@ -143,16 +143,16 @@ class Client(Base): def marketplace_setting_edit(self, configuration): """ - :param configuration:: + :param configuration: object :return: Response """ self.parameters['configuration'] = json.dumps(configuration) - return self.post('/marketplace/external/setting/' + str(configuration['code'])) + '/edit' + return self.post('/marketplace/external/setting/' + str(configuration['code']) + '/edit') def orders(self, filters=None, limit=20, page=1): """ - :param filters: array + :param filters: object :param limit: integer :param page: integer :return: Response @@ -178,7 +178,7 @@ class Client(Base): def orders_fix_external_ids(self, orders, site=None): """ - :param orders: object + :param orders: array of objects :param site: string :return: Response """ @@ -191,9 +191,9 @@ class Client(Base): def orders_history(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -215,7 +215,7 @@ class Client(Base): def orders_upload(self, orders, site=None): """ - :param orders: object + :param orders: array of objects :param site: string :return: Response """ @@ -260,9 +260,9 @@ class Client(Base): def packs(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -273,7 +273,7 @@ class Client(Base): def pack_create(self, pack): """ - :param pack: + :param pack: object :return: Response """ self.parameters['pack'] = json.dumps(pack) @@ -282,9 +282,9 @@ class Client(Base): def packs_history(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -295,7 +295,7 @@ class Client(Base): def pack(self, uid): """ - :param uid: + :param uid: integer :return: Response """ @@ -303,7 +303,7 @@ class Client(Base): def pack_delete(self, uid): """ - :param uid: + :param uid: integer :return: Response """ @@ -311,7 +311,7 @@ class Client(Base): def pack_edit(self, pack): """ - :param pack: + :param pack: object :return: Response """ self.parameters['pack'] = json.dumps(pack) @@ -334,7 +334,7 @@ class Client(Base): def delivery_services_edit(self, delivery_service): """ - :param delivery_service: + :param delivery_service: object :return: Response """ self.parameters['deliveryService'] = json.dumps(delivery_service) @@ -350,7 +350,7 @@ class Client(Base): def delivery_types_edit(self, delivery_type): """ - :param delivery_type: + :param delivery_type: object :return: Response """ self.parameters['deliveryType'] = json.dumps(delivery_type) @@ -367,7 +367,7 @@ class Client(Base): def order_methods_edit(self, order_method): """ - :param order_method: + :param order_method: object :return: Response """ self.parameters['orderMethod'] = json.dumps(order_method) @@ -383,7 +383,7 @@ class Client(Base): def order_types_edit(self, order_type): """ - :param order_type: + :param order_type: object :return: Response """ self.parameters['orderType'] = json.dumps(order_type) @@ -399,7 +399,7 @@ class Client(Base): def payment_statuses_edit(self, payment_status): """ - :param payment_status: + :param payment_status: object :return: Response """ self.parameters['paymentStatus'] = json.dumps(payment_status) @@ -431,7 +431,7 @@ class Client(Base): def price_types_edit(self, price_type): """ - :param price_type: + :param price_type: object :return: Response """ self.parameters['priceType'] = json.dumps(price_type) @@ -447,7 +447,7 @@ class Client(Base): def product_statuses_edit(self, product_status): """ - :param product_status: + :param product_status: object :return: Response """ self.parameters['productStatus'] = json.dumps(product_status) @@ -463,7 +463,7 @@ class Client(Base): def sites_edit(self, site): """ - :param site: + :param site: object :return: Response """ self.parameters['site'] = json.dumps(site) @@ -486,7 +486,7 @@ class Client(Base): def statuses_edit(self, status): """ - :param status: + :param status: object :return: Response """ self.parameters['status'] = json.dumps(status) @@ -502,18 +502,18 @@ class Client(Base): def stores_edit(self, store): """ - :param store: + :param store: object :return: Response """ - self.parameters['status'] = json.dumps(store) + self.parameters['store'] = json.dumps(store) return self.post('/reference/stores/' + store['code'] + '/edit') def inventories(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -524,8 +524,8 @@ class Client(Base): def inventories_upload(self, offers, site=None): """ - :param offers: - :param site: + :param offers: array of objects + :param site: string :return: Response """ if site is not None: @@ -537,7 +537,7 @@ class Client(Base): def prices_upload(self, prices): """ - :param prices: + :param prices: array of objects :return: Response """ self.parameters['prices'] = json.dumps(prices) @@ -546,7 +546,7 @@ class Client(Base): def products(self, filters=None, limit=20, page=1): """ - :param filters: array + :param filters: object :param limit: integer :param page: integer :return: Response @@ -559,7 +559,7 @@ class Client(Base): def store_setting(self, code): """ - :param code: + :param code: string :return: Response """ @@ -567,16 +567,16 @@ class Client(Base): def store_setting_edit(self, configuration): """ - :param configuration:: + :param configuration: object :return: Response """ self.parameters['configuration'] = json.dumps(configuration) - return self.post('/store/setting/' + str(configuration['code'])) + '/edit' + return self.post('/store/setting/' + str(configuration['code']) + '/edit') def telephony_call_event(self, event): """ - :param event: + :param event: object :return: Response """ self.parameters['event'] = json.dumps(event) @@ -585,27 +585,29 @@ class Client(Base): def telephony_calls_upload(self, calls): """ - :param calls: + :param calls: array of objects :return: Response """ self.parameters['calls'] = json.dumps(calls) return self.post('/telephony/calls/upload') - def telephony_manager(self, phone, details=True): + def telephony_manager(self, phone, details=True, ignore_status=False): """ - :param phone: - :param details: + :param phone: string + :param details: string + :param ignore_status: string :return: Response """ self.parameters['phone'] = phone self.parameters['details'] = details + self.parameters['ignoreStatus'] = ignore_status return self.get('/telephony/manager') def telephony_setting(self, code): """ - :param code: + :param code: string :return: Response """ @@ -613,12 +615,12 @@ class Client(Base): def telephony_setting_edit(self, configuration): """ - :param configuration:: + :param configuration: object :return: Response """ self.parameters['configuration'] = json.dumps(configuration) - return self.post('/telephony/setting/' + str(configuration['code'])) + '/edit' + return self.post('/telephony/setting/' + str(configuration['code']) + '/edit') def user_groups(self, limit=20, page=1): """ @@ -633,7 +635,7 @@ class Client(Base): def users(self, filters=None, limit=20, page=1): """ - :param filters: array + :param filters: object :param limit: integer :param page: integer :return: Response @@ -646,8 +648,15 @@ class Client(Base): def user(self, uid): """ - :param uid: + :param uid: integer :return: Response """ return self.get('/users/' + str(uid)) + + def statistic_update(self): + """ + :return: Response + """ + + return self.get('/statistic/update') diff --git a/retailcrm/versions/v5.py b/retailcrm/versions/v5.py index e7d7f47..8819bcd 100644 --- a/retailcrm/versions/v5.py +++ b/retailcrm/versions/v5.py @@ -19,9 +19,9 @@ class Client(Base): def costs(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -32,8 +32,8 @@ class Client(Base): def cost_create(self, cost, site=None): """ - :param cost: - :param site: + :param cost: object + :param site: string :return: Response """ self.parameters['cost'] = json.dumps(cost) @@ -45,7 +45,7 @@ class Client(Base): def costs_delete(self, ids): """ - :param ids: + :param ids: array of integers :return: Response """ self.parameters['ids'] = json.dumps(ids) @@ -54,7 +54,7 @@ class Client(Base): def costs_upload(self, costs): """ - :param costs: + :param costs: array of objects :return: Response """ self.parameters['costs'] = json.dumps(costs) @@ -63,7 +63,7 @@ class Client(Base): def cost(self, uid): """ - :param uid: + :param uid: string :return: Response """ @@ -71,7 +71,7 @@ class Client(Base): def cost_delete(self, uid): """ - :param uid: + :param uid: string :return: Response """ @@ -79,8 +79,8 @@ class Client(Base): def cost_edit(self, cost, site=None): """ - :param cost: - :param site: + :param cost: object + :param site: string :return: Response """ self.parameters['cost'] = json.dumps(cost) @@ -92,9 +92,9 @@ class Client(Base): def custom_fields(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -105,9 +105,9 @@ class Client(Base): def custom_dictionaries(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -118,7 +118,7 @@ class Client(Base): def custom_dictionary_create(self, dictionary): """ - :param dictionary: + :param dictionary: object :return: Response """ self.parameters['customDictionary'] = json.dumps(dictionary) @@ -127,7 +127,7 @@ class Client(Base): def custom_dictionary(self, code): """ - :param code: + :param code: string :return: Response """ @@ -135,16 +135,16 @@ class Client(Base): def custom_dictionary_edit(self, dictionary): """ - :param dictionary: + :param dictionary: object :return: Response """ self.parameters['customDictionary'] = json.dumps(dictionary) - return self.post('/custom-fields/dictionaries/' + str(dictionary['code']) + '/create') + return self.post('/custom-fields/dictionaries/' + str(dictionary['code']) + '/edit') def custom_field_create(self, field): """ - :param field: + :param field: object :return: Response """ self.parameters['customField'] = json.dumps(field) @@ -153,8 +153,8 @@ class Client(Base): def custom_field(self, code, entity): """ - :param code: - :param entity: + :param code: string + :param entity: string :return: Response """ @@ -162,7 +162,7 @@ class Client(Base): def custom_field_edit(self, field): """ - :param field: + :param field: object :return: Response """ @@ -170,13 +170,13 @@ class Client(Base): code = str(field['code']) self.parameters['customField'] = json.dumps(field) - return self.post('/custom-fields/' + entity + '/' + code + '/create') + return self.post('/custom-fields/' + entity + '/' + code + '/edit') def customers(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -198,8 +198,8 @@ class Client(Base): def customer_create(self, customer, site=None): """ - :param customer: - :param site: + :param customer: object + :param site: string :return: Response """ self.parameters['customer'] = json.dumps(customer) @@ -211,8 +211,8 @@ class Client(Base): def customers_fix_external_ids(self, customers, site=None): """ - :param customers: - :param site: + :param customers: array of objects + :param site: string :return: Response """ self.parameters['customers'] = json.dumps(customers) @@ -224,9 +224,9 @@ class Client(Base): def customers_history(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -237,9 +237,9 @@ class Client(Base): def customer_notes(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -263,7 +263,7 @@ class Client(Base): def customer_note_delete(self, uid): """ - :param uid: string + :param uid: integer :return: Response """ @@ -271,8 +271,8 @@ class Client(Base): def customers_upload(self, customers, site=None): """ - :param customers: - :param site: + :param customers: array of objects + :param site: string :return: Response """ self.parameters['customers'] = json.dumps(customers) @@ -284,9 +284,9 @@ class Client(Base): def customer(self, uid, uid_type='externalId', site=None): """ - :param uid: - :param uid_type: - :param site: + :param uid: string + :param uid_type: string + :param site: string :return: Response """ if uid_type != 'externalId': @@ -299,9 +299,9 @@ class Client(Base): def customer_edit(self, customer, uid_type='externalId', site=None): """ - :param customer: - :param uid_type: - :param site: + :param customer: object + :param uid_type: string + :param site: string :return: Response """ self.parameters['customer'] = json.dumps(customer) @@ -314,10 +314,359 @@ class Client(Base): return self.post('/customers/' + str(customer[uid_type]) + '/edit') + def customers_corporate(self, filters=None, limit=20, page=1): + """ + :param filters: object + :param limit: integer + :param page: integer + :return: Response + """ + self.parameters['filter'] = filters + self.parameters['limit'] = limit + self.parameters['page'] = page + + return self.get('/customers-corporate') + + def customers_combine_corporate(self, customers, result): + """ + :param customers: array of object + :param result: object + :return: Response + """ + self.parameters['customers'] = json.dumps(customers) + self.parameters['resultCustomer'] = json.dumps(result) + + return self.post('/customers-corporate/combine') + + def customer_corporate_create(self, customer_corporate, site=None): + """ + :param customer_corporate: object + :param site: string + :return: Response + """ + self.parameters['customerCorporate'] = json.dumps(customer_corporate) + + if site is not None: + self.parameters['site'] = site + + return self.post('/customers-corporate/create') + + def customers_corporate_fix_external_ids(self, customers_corporate, site=None): + """ + :param customers_corporate: array of objects + :param site: string + :return: Response + """ + self.parameters['customersCorporate'] = json.dumps(customers_corporate) + + if site is not None: + self.parameters['site'] = site + + return self.post('/customers-corporate/fix-external-ids') + + def customers_corporate_history(self, filters=None, limit=20, page=1): + """ + :param filters: object + :param limit: integer + :param page: integer + :return: Response + """ + self.parameters['filter'] = filters + self.parameters['limit'] = limit + self.parameters['page'] = page + + return self.get('/customers-corporate/history') + + def customer_corporate_notes(self, filters=None, limit=20, page=1): + """ + :param filters: object + :param limit: integer + :param page: integer + :return: Response + """ + self.parameters['filter'] = filters + self.parameters['limit'] = limit + self.parameters['page'] = page + + return self.get('/customers-corporate/notes') + + def customer_corporate_note_create(self, note, site=None): + """ + :param note: object + :param site: string + :return: Response + """ + self.parameters['note'] = json.dumps(note) + + if site is not None: + self.parameters['site'] = site + + return self.post('/customers-corporate/notes/create') + + def customer_corporate_note_delete(self, uid): + """ + :param uid: integer + :return: Response + """ + + return self.post('/customers-corporate/notes/' + str(uid) + '/delete') + + def customers_corporate_upload(self, customers_corporate, site=None): + """ + :param customers_corporate: array of objects + :param site: string + :return: Response + """ + self.parameters['customersCorporate'] = json.dumps(customers_corporate) + + if site is not None: + self.parameters['site'] = site + + return self.post('/customers-corporate/upload') + + def customer_corporate(self, uid, uid_type='externalId', site=None): + """ + :param uid: string + :param uid_type: string + :param site: string + :return: Response + """ + if uid_type != 'externalId': + self.parameters['by'] = uid_type + + if site is not None: + self.parameters['site'] = site + + return self.get('/customers-corporate/' + str(uid)) + + def customer_corporate_addresses(self, uid, uid_type='externalId', limit=20, page=1, filters=None, site=None): + """ + :param filters: object + :param uid: string + :param uid_type: string + :param site: string + :param limit: integer + :param page: integer + :return: Response + """ + + if uid_type != 'externalId': + self.parameters['by'] = uid_type + + if site is not None: + self.parameters['site'] = site + + self.parameters['filter'] = filters + self.parameters['limit'] = limit + self.parameters['page'] = page + + return self.get('/customers-corporate/' + str(uid) + '/addresses') + + def customer_corporate_addresses_create(self, address, uid_type='externalId', site=None): + """ + :param address: object + :param uid_type: string + :param site: string + :return: Response + """ + self.parameters['address'] = json.dumps(address) + + if uid_type != 'externalId': + self.parameters['by'] = uid_type + + if site is not None: + self.parameters['site'] = site + + return self.post('/customers-corporate/' + str(address[uid_type]) + '/addresses/create') + + def customer_corporate_addresses_edit(self, + uid_corporate, + address, + uid_type='externalId', + entity_by='externalId', + site=None): + """ + :param address: object + :param uid_corporate: string + :param uid_type: string + :param entity_by: string + :param site: string + :return: Response + """ + self.parameters['address'] = json.dumps(address) + + if uid_type != 'externalId': + self.parameters['by'] = uid_type + + if entity_by != 'externalId': + self.parameters['entityBy'] = entity_by + + if site is not None: + self.parameters['site'] = site + + return self.post('/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): + """ + :param filters: object + :param uid: string + :param uid_type: string + :param site: string + :param limit: integer + :param page: integer + :return: Response + """ + + if uid_type != 'externalId': + self.parameters['by'] = uid_type + + if site is not None: + self.parameters['site'] = site + + self.parameters['filter'] = filters + self.parameters['limit'] = limit + self.parameters['page'] = page + + return self.get('/customers-corporate/' + str(uid) + '/companies') + + def customer_corporate_companies_create(self, company, uid_type='externalId', site=None): + """ + :param company: object + :param uid_type: string + :param site: string + :return: Response + """ + self.parameters['company'] = json.dumps(company) + + if uid_type != 'externalId': + self.parameters['by'] = uid_type + + if site is not None: + self.parameters['site'] = site + + return self.post('/customers-corporate/' + str(company[uid_type]) + '/companies/create') + + def customer_corporate_companies_edit(self, + uid_corporate, + company, + uid_type='externalId', + entity_by='externalId', + site=None): + """ + :param company: object + :param uid_corporate: string + :param uid_type: string + :param entity_by: string + :param site: string + :return: Response + """ + self.parameters['company'] = json.dumps(company) + + if uid_type != 'externalId': + self.parameters['by'] = uid_type + + if entity_by != 'externalId': + self.parameters['entityBy'] = entity_by + + if site is not None: + self.parameters['site'] = site + + 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): + """ + :param filters: object + :param uid: string + :param uid_type: string + :param site: string + :param limit: integer + :param page: integer + :return: Response + """ + + if uid_type != 'externalId': + self.parameters['by'] = uid_type + + if site is not None: + self.parameters['site'] = site + + self.parameters['filter'] = filters + self.parameters['limit'] = limit + self.parameters['page'] = page + + return self.get('/customers-corporate/' + str(uid) + '/contacts') + + def customer_corporate_contacts_create(self, contact, uid_type='externalId', site=None): + """ + :param contact: object + :param uid_type: string + :param site: string + :return: Response + """ + self.parameters['contact'] = json.dumps(contact) + + if uid_type != 'externalId': + self.parameters['by'] = uid_type + + if site is not None: + self.parameters['site'] = site + + return self.post('/customers-corporate/' + str(contact[uid_type]) + '/contacts/create') + + def customer_corporate_contacts_edit(self, + uid_corporate, + contact, + uid_type='externalId', + entity_by='externalId', + site=None): + """ + :param contact: object + :param uid_corporate: string + :param uid_type: string + :param entity_by: string + :param site: string + :return: Response + """ + self.parameters['contact'] = json.dumps(contact) + + if uid_type != 'externalId': + self.parameters['by'] = uid_type + + if entity_by != 'externalId': + self.parameters['entityBy'] = entity_by + + if site is not None: + self.parameters['site'] = site + + 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): + """ + :param customer_corporate: object + :param uid_type: string + :param site: string + :return: Response + """ + self.parameters['customersCorporate'] = json.dumps(customer_corporate) + + if uid_type != 'externalId': + self.parameters['by'] = uid_type + + if site is not None: + self.parameters['site'] = site + + return self.post('/customers-corporate/' + str(customer_corporate[uid_type]) + '/edit') + def delivery_tracking(self, code, status_update): """ - :param code: - :param status_update: + :param code: string + :param status_update: array of objects :return: Response """ self.parameters['statusUpdate'] = json.dumps(status_update) @@ -326,9 +675,9 @@ class Client(Base): def delivery_shipments(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -337,24 +686,22 @@ class Client(Base): return self.get('/delivery/shipments') - def delivery_shipment_create(self, shipment, delivery_type, site=None): + def delivery_shipment_create(self, shipment, site=None): """ - :param shipment: - :param delivery_type: - :param site: + :param shipment: object + :param site: string :return: Response """ self.parameters['deliveryShipment'] = json.dumps(shipment) - self.parameters['deliveryType'] = delivery_type if site is not None: self.parameters['site'] = site - return self.post('/delivery/shipment/create') + return self.post('/delivery/shipments/create') def delivery_shipment(self, uid): """ - :param uid: + :param uid: string :return: Response """ @@ -362,8 +709,8 @@ class Client(Base): def delivery_shipment_edit(self, shipment, site=None): """ - :param shipment: - :param site: + :param shipment: object + :param site: string :return: Response """ self.parameters['deliveryShipment'] = json.dumps(shipment) @@ -371,11 +718,70 @@ class Client(Base): if site is not None: self.parameters['site'] = site - return self.post('/delivery/shipment/' + shipment['id'] + '/edit') + return self.post('/delivery/shipment/' + str(shipment['id']) + '/edit') + + def files(self, filters=None, limit=20, page=1): + """ + :param filters: object + :param limit: integer + :param page: integer + :return: Response + """ + self.parameters['filter'] = filters + self.parameters['limit'] = limit + self.parameters['page'] = page + + return self.get('/files') + + def files_upload(self, file, site=None): + """ + :param file: objects + :param site: string + :return: Response + """ + + self.parameters['file'] = json.dumps(file) + + if site is not None: + self.parameters['site'] = site + + return self.post('/files/upload') + + def file(self, uid): + """ + :param uid: integer + :return: Response + """ + return self.get('/files/' + str(uid)) + + def files_delete(self, uid): + """ + :param uid: integer + :return: Response + """ + + return self.post('/files/' + str(uid) + '/delete') + + def files_download(self, uid): + """ + :param uid: integer + :return: Response + """ + + return self.get('/files/' + str(uid) + '/download') + + def files_edit(self, file): + """ + :param file: object + :return: Response + """ + self.parameters['file'] = json.dumps(file) + + return self.post('/files/' + str(file['id']) + '/edit') def integration_module(self, code): """ - :param code: + :param code: integer :return: Response """ @@ -383,16 +789,16 @@ class Client(Base): def integration_module_edit(self, configuration): """ - :param configuration:: + :param configuration: object :return: Response """ self.parameters['integrationModule'] = json.dumps(configuration) - return self.post('/integration-modules/' + str(configuration['code'])) + '/edit' + return self.post('/integration-modules/' + str(configuration['code']) + '/edit') def orders(self, filters=None, limit=20, page=1): """ - :param filters: array + :param filters: object :param limit: integer :param page: integer :return: Response @@ -444,9 +850,9 @@ class Client(Base): def orders_history(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -455,6 +861,19 @@ class Client(Base): return self.get('/orders/history') + def order_links_create(self, link, site=None): + """ + :param link: object + :param site: string + :return: Response + """ + self.parameters['link'] = json.dumps(link) + + if site is not None: + self.parameters['site'] = site + + return self.post('/orders/links/create') + def order_payment_create(self, payment, site=None): """ :param payment: object @@ -476,7 +895,7 @@ class Client(Base): return self.post('/orders/payments/' + str(uid) + '/delete') - def order_payment_edit(self, payment, uid_type='id', site=None): + def order_payment_edit(self, payment, uid_type='externalId', site=None): """ :param payment: object :param uid_type: string @@ -484,7 +903,8 @@ class Client(Base): :return: Response """ self.parameters['payment'] = json.dumps(payment) - self.parameters['by'] = uid_type + if uid_type != 'externalId': + self.parameters['by'] = uid_type if site is not None: self.parameters['site'] = site @@ -548,9 +968,9 @@ class Client(Base): def packs(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -561,7 +981,7 @@ class Client(Base): def pack_create(self, pack): """ - :param pack: + :param pack: object :return: Response """ self.parameters['pack'] = json.dumps(pack) @@ -570,9 +990,9 @@ class Client(Base): def packs_history(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -583,7 +1003,7 @@ class Client(Base): def pack(self, uid): """ - :param uid: + :param uid: integer :return: Response """ @@ -591,15 +1011,42 @@ class Client(Base): def pack_delete(self, uid): """ - :param uid: + :param uid: integer :return: Response """ return self.post('/orders/packs/' + str(uid) + '/delete') + def payment_check(self, check): + """ + :param check: object + :return: Response + """ + self.parameters['check'] = json.dumps(check) + + return self.post('/payment/check') + + def payment_create_invoice(self, create_invoice): + """ + :param create_invoice: object + :return: Response + """ + self.parameters['createInvoice'] = json.dumps(create_invoice) + + return self.post('/payment/create-invoice') + + def payment_update_invoice(self, update_invoice): + """ + :param update_invoice: object + :return: Response + """ + self.parameters['updateInvoice'] = json.dumps(update_invoice) + + return self.post('/payment/update-invoice') + def pack_edit(self, pack): """ - :param pack: + :param pack: object :return: Response """ self.parameters['pack'] = json.dumps(pack) @@ -615,7 +1062,7 @@ class Client(Base): def cost_groups_edit(self, cost_group): """ - :param cost_group: + :param cost_group: array of objects :return: Response """ self.parameters['costGroup'] = json.dumps(cost_group) @@ -631,12 +1078,12 @@ class Client(Base): def cost_items_edit(self, cost_item): """ - :param cost_item: + :param cost_item: array of objects :return: Response """ self.parameters['costItem'] = json.dumps(cost_item) - return self.post('/reference/delivery-services/' + cost_item['code'] + '/edit') + return self.post('/reference/cost-groups/' + cost_item['code'] + '/edit') def countries(self): """ @@ -654,7 +1101,7 @@ class Client(Base): def couriers_create(self, courier): """ - :param courier: + :param courier: array of objects :return: Response """ self.parameters['courier'] = json.dumps(courier) @@ -663,12 +1110,12 @@ class Client(Base): def couriers_edit(self, courier): """ - :param courier: + :param courier: object :return: Response """ self.parameters['courier'] = json.dumps(courier) - return self.post('/reference/couriers/' + courier['code'] + '/edit') + return self.post('/reference/couriers/' + str(courier['id']) + '/edit') def delivery_services(self): """ @@ -695,7 +1142,7 @@ class Client(Base): def delivery_types_edit(self, delivery_type): """ - :param delivery_type: + :param delivery_type: object :return: Response """ self.parameters['deliveryType'] = json.dumps(delivery_type) @@ -711,13 +1158,20 @@ class Client(Base): def legal_entities_edit(self, legal_entity): """ - :param legal_entity: + :param legal_entity: object :return: Response """ self.parameters['legalEntity'] = json.dumps(legal_entity) return self.post('/reference/legal-entities/' + legal_entity['code'] + '/edit') + def mg_channels(self): + """ + :return: Response + """ + + return self.get('/reference/mg-channels') + def order_methods(self): """ :return: Response @@ -728,7 +1182,7 @@ class Client(Base): def order_methods_edit(self, order_method): """ - :param order_method: + :param order_method: object :return: Response """ self.parameters['orderMethod'] = json.dumps(order_method) @@ -744,7 +1198,7 @@ class Client(Base): def order_types_edit(self, order_type): """ - :param order_type: + :param order_type: object :return: Response """ self.parameters['orderType'] = json.dumps(order_type) @@ -760,7 +1214,7 @@ class Client(Base): def payment_statuses_edit(self, payment_status): """ - :param payment_status: + :param payment_status: object :return: Response """ self.parameters['paymentStatus'] = json.dumps(payment_status) @@ -776,7 +1230,7 @@ class Client(Base): def payment_types_edit(self, payment_type): """ - :param payment_type: + :param payment_type: object :return: Response """ self.parameters['paymentType'] = json.dumps(payment_type) @@ -792,10 +1246,10 @@ class Client(Base): def price_types_edit(self, price_type): """ - :param price_type: + :param price_type: object :return: Response """ - self.parameters['priceType'] = json.dumps(price_type) + self.parameters['priceTypes'] = json.dumps(price_type) return self.post('/reference/price-types/' + price_type['code'] + '/edit') @@ -808,7 +1262,7 @@ class Client(Base): def product_statuses_edit(self, product_status): """ - :param product_status: + :param product_status: object :return: Response """ self.parameters['productStatus'] = json.dumps(product_status) @@ -824,7 +1278,7 @@ class Client(Base): def sites_edit(self, site): """ - :param site: + :param site: object :return: Response """ self.parameters['site'] = json.dumps(site) @@ -833,7 +1287,7 @@ class Client(Base): def status_groups(self): """ - :return + :return Response """ return self.get('/reference/status-groups') @@ -847,7 +1301,7 @@ class Client(Base): def statuses_edit(self, status): """ - :param status: + :param status: object :return: Response """ self.parameters['status'] = json.dumps(status) @@ -863,18 +1317,34 @@ class Client(Base): def stores_edit(self, store): """ - :param store: + :param store: object :return: Response """ - self.parameters['status'] = json.dumps(store) + self.parameters['store'] = json.dumps(store) return self.post('/reference/stores/' + store['code'] + '/edit') + def units(self): + """ + :return: Response + """ + + return self.get('/reference/units') + + def units_edit(self, units): + """ + :param units: object + :return: Response + """ + self.parameters['units'] = json.dumps(units) + + return self.post('/reference/units/' + units['code'] + '/edit') + def segments(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -885,9 +1355,9 @@ class Client(Base): def inventories(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -898,21 +1368,20 @@ class Client(Base): def inventories_upload(self, offers, site=None): """ - :param offers: - :param site: + :param offers: array of objects + :param site: string :return: Response """ if site is not None: self.parameters['site'] = site - - self.parameters['offers'] = json.dumps(offers) + self.parameters['offers'] = json.dumps(offers) return self.post('/store/inventories/upload') def prices_upload(self, prices): """ - :param prices: + :param prices: array of objects :return: Response """ self.parameters['prices'] = json.dumps(prices) @@ -921,7 +1390,7 @@ class Client(Base): def product_groups(self, filters=None, limit=20, page=1): """ - :param filters: array + :param filters: object :param limit: integer :param page: integer :return: Response @@ -934,7 +1403,7 @@ class Client(Base): def products(self, filters=None, limit=20, page=1): """ - :param filters: array + :param filters: object :param limit: integer :param page: integer :return: Response @@ -947,7 +1416,7 @@ class Client(Base): def products_properties(self, filters=None, limit=20, page=1): """ - :param filters: array + :param filters: object :param limit: integer :param page: integer :return: Response @@ -960,9 +1429,9 @@ class Client(Base): def tasks(self, filters=None, limit=20, page=1): """ - :param filters: - :param limit: - :param page: + :param filters: object + :param limit: integer + :param page: integer :return: Response """ self.parameters['filter'] = filters @@ -1007,7 +1476,7 @@ class Client(Base): def telephony_call_event(self, event): """ - :param event: + :param event: object :return: Response """ self.parameters['event'] = json.dumps(event) @@ -1016,21 +1485,23 @@ class Client(Base): def telephony_calls_upload(self, calls): """ - :param calls: + :param calls: array of objects :return: Response """ self.parameters['calls'] = json.dumps(calls) return self.post('/telephony/calls/upload') - def telephony_manager(self, phone, details=True): + def telephony_manager(self, phone, details=True, ignore_status=True): """ - :param phone: - :param details: + :param phone: string + :param details: string + :param ignore_status: string :return: Response """ self.parameters['phone'] = phone self.parameters['details'] = details + self.parameters['ignoreStatus'] = ignore_status return self.get('/telephony/manager') @@ -1047,7 +1518,7 @@ class Client(Base): def users(self, filters=None, limit=20, page=1): """ - :param filters: array + :param filters: object :param limit: integer :param page: integer :return: Response @@ -1060,7 +1531,7 @@ class Client(Base): def user(self, uid): """ - :param uid: + :param uid: integer :return: Response """ @@ -1068,11 +1539,18 @@ class Client(Base): def user_status(self, uid, status): """ - :param uid: - :param status: + :param uid: integer + :param status: string :return: Response """ self.parameters['status'] = status return self.post('/users/' + str(uid) + '/status') + + def statistic_update(self): + """ + :return: Response + """ + + return self.get('/statistic/update') diff --git a/setup.py b/setup.py index 43fc55f..1aeb58e 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ def read(filename): setup( name='retailcrm', - version='5.0.3', + version='5.1.0', description='retailCRM API client', long_description=read('README'), url='https://github.com/retailcrm/api-client-python', @@ -25,7 +25,7 @@ setup( license='MIT', packages=['retailcrm', 'retailcrm/versions'], package_data={}, - install_requires=['requests', 'multidimensional_urlencode', 'nose'], + install_requires=['requests', 'multidimensional_urlencode', 'nose', 'coverage', 'pook', 'setuptools'], classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Other Environment', @@ -38,6 +38,7 @@ setup( 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3 :: Only', 'Topic :: Software Development :: Libraries :: Python Modules', ] diff --git a/tests/v3_tests.py b/tests/v3_tests.py index 39b34e0..70465a9 100644 --- a/tests/v3_tests.py +++ b/tests/v3_tests.py @@ -5,9 +5,12 @@ retailCRM API client v3 tests """ +from urllib.parse import urlencode import unittest import os import retailcrm +import pook +import json class TestVersion3(unittest.TestCase): @@ -15,55 +18,1634 @@ class TestVersion3(unittest.TestCase): TestClass for v3 """ + __header = {'Server': 'nginx/1.16.0', 'Content-Type': 'application/json; charset=UTF-8'} + + __customer = { + 'id': 9717, + 'externalId': 'c-111111111', + 'createdAt': '2020-04-09 16:55:59', + 'vip': 'false', + 'bad': 'false', + 'site': 'test-org', + 'marginSumm': 28180, + 'totalSumm': 28180, + 'averageSumm': 28180, + 'ordersCount': 1, + 'customFields': [], + 'personalDiscount': 0, + 'address': { + 'id': 5667, + 'text': 'MAY' + }, + 'firstName': 'Аа', + 'lastName': 'Аа', + 'phones': [], + 'contragentType': 'individual' + } + + __order = { + 'slug': 5604, + 'summ': 0, + 'id': 5604, + 'number': '5604A', + 'externalId': '5603', + 'orderType': 's789', + 'orderMethod': 'shopping-cart', + 'countryIso': 'RU', + 'createdAt': '2020-04-07 15:44:24', + 'statusUpdatedAt': '2020-04-07 15:44:24', + 'totalSumm': 0, + 'prepaySum': 0, + 'purchaseSumm': 0, + 'markDatetime': '2020-04-07 15:44:24', + 'call': 'false', + 'expired': 'false', + 'customer': { + 'id': 9711, + 'createdAt': '2020-04-07 15:44:24', + 'vip': 'false', + 'bad': 'false', + 'site': '127-0-0-1-8080', + 'marginSumm': 0, + 'totalSumm': 0, + 'averageSumm': 0, + 'ordersCount': 1, + 'customFields': [], + 'personalDiscount': 0, + 'email': '', + 'phones': [], + 'contragentType': 'individual' + }, + 'contragentType': 'individual', + 'delivery': { + 'cost': 0, + 'netCost': 0, + 'address': {} + }, + 'site': '127-0-0-1-8080', + 'status': 'new', + 'items': [], + 'fromApi': 'true', + 'shipped': 'false', + 'customFields': [] + } + + __pack = { + 'id': 122, + 'purchasePrice': 0, + 'quantity': 1, + 'store': '7777z', + 'item': { + 'id': 7632, + 'order': { + 'id': 5608 + }, + 'offer': { + 'externalId': 's789' + } + } + } + def setUp(self): """ 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): + return urlencode({key: json.dumps(dictionary)}) + + @pook.on def test_wrong_api_url(self): """ V3 Test wrong api url """ - client = retailcrm.v3( - 'https://epoqwieqwpoieqpwoeiqpwoeiq.retailcrm.ru', '98sdf9sj8fsd9fjs9dfjs98') + + (pook.get('https://epoqq.retailcrm.ru' + '/api/v3/statistic/update') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(404) + .headers(self.__header) + .json( + { + 'success': 'true', + 'errorMsg': 'Account does not exist.' + } + ) + ) + + client = retailcrm.v3('https://epoqq.retailcrm.ru', os.getenv('RETAILCRM_KEY')) response = client.statistic_update() + pook.off() self.assertIsNot(response.is_successful(), True) self.assertEqual(response.get_error_msg(), 'Account does not exist.') + @pook.on def test_wrong_api_key(self): """ V3 Test wrong api key """ - client = retailcrm.v3(os.getenv('RETAILCRM_URL'), - '98sdf9sj8fsd9fjs9dfjs98') + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/statistic/update') + .headers({'X-API-KEY': 'XXXX'}) + .reply(200) + .headers(self.__header) + .json({'errorMsg': 'Wrong "apiKey" value.'}) + ) + + client = retailcrm.v3(os.getenv('RETAILCRM_URL'), 'XXXX') response = client.statistic_update() + pook.off() self.assertEqual(response.get_error_msg(), 'Wrong "apiKey" value.') + @pook.on def test_missing_api_key(self): """ V3 Test missing api key """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/statistic/update') + .headers({'X-API-KEY': None}) + .reply(200) + .headers(self.__header) + .json({'errorMsg': '"apiKey" is missing.'}) + ) + client = retailcrm.v3(os.getenv('RETAILCRM_URL'), None) response = client.statistic_update() + pook.off() self.assertEqual(response.get_error_msg(), '"apiKey" is missing.') + @pook.on def test_api_versions(self): """ V3 Test api-versions method """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/api-versions') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'versions': ['3.0', '4.0', '5.0']}) + ) + response = self.client.api_versions() + pook.off() self.assertTrue(response.is_successful(), True) + @pook.on def test_api_credentials(self): """ V3 Test api-credentials method """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/credentials') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'credentials': [], 'siteAccess': 'access_full'}) + ) + response = self.client.api_credentials() + pook.off() self.assertTrue(response.is_successful(), True) + + @pook.on + def test_customers(self): + """ + V3 Test method customers + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/customers') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[bad]': 'false', 'filter[contragentType]': 'individual'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 4342, + 'currentPage': 1, + 'totalPageCount': 87 + }, + 'customers': [self.__customer] + } + ) + ) + + response = self.client.customers({'bad': 'false', 'contragentType': 'individual'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_create(self): + """ + V3 Test method customers_create + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/customers/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customer', self.__customer)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': 7777}) + ) + + response = self.client.customer_create(self.__customer) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_fix_external_ids(self): + """ + V3 Test method customers_fix_external_ids + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/customers/fix-external-ids') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customers', self.__customer['externalId'])) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.customers_fix_external_ids(self.__customer['externalId']) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_upload(self): + """ + V3 Test method customers_upload + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/customers/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customers', self.__customer)) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'uploadedCustomers': [ + { + 'id': 9717, + 'externalId': 'c-983344770' + } + ] + } + ) + ) + + response = self.client.customers_upload(self.__customer) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer(self): + """ + V3 Test method customer + """ + + uid = str(self.__customer['externalId']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/customers/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'customers': self.__customer}) + ) + + response = self.client.customer(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_edit(self): + """ + V3 Test method customers_edit + """ + + uid = str(self.__customer['externalId']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/customers/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customer', self.__customer)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 9717}) + ) + + response = self.client.customer_edit(self.__customer) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders(self): + """ + V3 Test method orders + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/orders') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[bad]': 'false', 'filter[contragentType]': 'individual'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 2444, + 'currentPage': 1, + 'totalPageCount': 49 + }, + 'orders': [self.__order] + } + ) + ) + + response = self.client.orders({'bad': 'false', 'contragentType': 'individual'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_create(self): + """ + V3 Test method orders_create + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/orders/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('order', self.__order)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': 7777, 'order': self.__order}) + ) + + response = self.client.order_create(self.__order) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_fix_external_ids(self): + """ + V3 Test method orders_fix_external_ids + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/orders/fix-external-ids') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('orders', self.__order['externalId'])) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.orders_fix_external_ids(self.__order['externalId']) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_history(self): + """ + V3 Test method orders_history + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/orders/history') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'startDate': '2020-01-07', 'endDate': '2020-04-12'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'generatedAt': '2020-04-12 15:44:24', + 'orders': [self.__order] + } + ) + ) + + response = self.client.orders_history('2020-01-07', '2020-04-12') + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_statuses(self): + """ + V3 Test method orders_statuses + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/orders/statuses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'ids[]': '5604', 'externalIds[]': '5603'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'orders': [ + { + 'id': 5604, + 'externalId': '5603', + 'status': 'new', + 'group': 'new' + } + ] + } + ) + ) + + response = self.client.orders_statuses([5604], [5603]) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_upload(self): + """ + V3 Test method orders_upload + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/orders/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('orders', self.__order)) + .reply(201) + .headers(self.__header) + .json( + { + 'success': 'true', + 'uploadedOrders': [ + { + 'id': 5604, + 'externalId': '5603' + } + ], + 'orders': [self.__order] + } + ) + ) + + response = self.client.orders_upload(self.__order) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order(self): + """ + V3 Test method order + """ + + uid = str(self.__order['externalId']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/orders/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'orders': self.__order}) + ) + + response = self.client.order(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_edit(self): + """ + V3 Test method orders_edit + """ + + uid = str(self.__order['externalId']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/orders/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('order', self.__order)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 5604, 'order': self.__order}) + ) + + response = self.client.order_edit(self.__order) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_packs(self): + """ + V3 Test method packs + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/orders/packs') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[store]': '7777z'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 1, + 'currentPage': 1, + 'totalPageCount': 1 + }, + 'packs': [self.__pack] + } + ) + ) + + response = self.client.packs({'store': '7777z'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_packs_create(self): + """ + V3 Test method packs_create + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/orders/packs/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('pack', {'store': '7777z', 'quantity': 1, 'itemId': 7632})) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': 7777}) + ) + + response = self.client.pack_create({'store': '7777z', 'quantity': 1, 'itemId': 7632}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_packs_history(self): + """ + V3 Test method packs_history + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/orders/packs/history') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[startDate]': '2016-01-07', 'filter[endDate]': '2020-04-12'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'generatedAt': '2020-04-17 13:08:48', + 'history': [ + { + 'id': 777, + 'createdAt': '2018-04-13 15:46:06', + 'created': 'true', + 'field': 'store', + 'newValue': { + 'code': 'zzz' + }, + 'pack': { + 'id': 678, + 'quantity': 1, + 'store': {'code': 'zzz'}, + 'item': { + 'id': 222, + 'order': {'id': 6677}, + 'offer': {'externalId': '333'} + } + }, + 'source': 'api' + } + ] + } + ) + ) + + response = self.client.packs_history({'startDate': '2016-01-07', 'endDate': '2020-04-12'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_pack(self): + """ + V3 Test method pack + """ + + uid = str(self.__pack['id']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/orders/packs/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'pack': self.__pack}) + ) + + response = self.client.pack(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_packs_delete(self): + """ + V3 Test method packs_delete + """ + + uid = str(self.__pack['id']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/orders/packs/' + uid + '/delete') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.pack_delete(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_pack_edit(self): + """ + V3 Test method pack_edit + """ + + uid = str(self.__pack['id']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/orders/packs/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('pack', self.__pack)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 5604}) + ) + + response = self.client.pack_edit(self.__pack) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_countries(self): + """ + V3 Test method countries + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/reference/countries') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'countriesIso': ['RU', 'UA', 'BY', 'KZ']}) + ) + + response = self.client.countries() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_services(self): + """ + V3 Test method delivery_services + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/reference/delivery-services') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'deliveryServices': { + '0tq6d': { + 'name': '57jij', + 'code': '0tq6d' + }, + 'a080k': { + 'name': 's789', + 'code': 'a080k' + }, + 'a6zgf': { + 'name': 'eu8ss', + 'code': 'a6zgf' + } + } + } + ) + ) + + response = self.client.delivery_services() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_services_edit(self): + """ + V3 Test method delivery_services_edit + """ + + service = {'code': 'a080k', 'name': 's789'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/reference/delivery-services/' + service['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('deliveryService', service)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.delivery_services_edit(service) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_types(self): + """ + V3 Test method delivery_types + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/reference/delivery-types') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(201) + .headers(self.__header) + .json( + { + 'success': 'true', + 'deliveryTypes': { + '1kp52': { + 'name': 's789', + 'code': '1kp52', + 'defaultCost': 300, + 'defaultNetCost': 0, + 'paymentTypes': [ + 'cash', + 'bank-card' + ], + 'deliveryServices': [], + 'defaultForCrm': 'false' + }, + 's789': { + 'name': '1s0ei', + 'code': 's789', + 'defaultCost': 300, + 'defaultNetCost': 0, + 'paymentTypes': [ + 'cash', + 'bank-card' + ], + 'deliveryServices': [], + 'defaultForCrm': 'false' + } + } + } + ) + ) + + response = self.client.delivery_types() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_types_edit(self): + """ + V3 Test method delivery_types_edit + """ + + delivery_type = {'code': 's789', 'name': '1s0ei'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/reference/delivery-types/' + delivery_type['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('deliveryType', delivery_type)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.delivery_types_edit(delivery_type) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_methods(self): + """ + V3 Test method order_methods + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/reference/order-methods') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'orderMethods': { + '1b4os': { + 'name': '19le4', + 'code': '1b4os', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'isFromPos': 'false' + }, + '44cmd': { + 'name': '1tdf4', + 'code': '44cmd', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'isFromPos': 'false' + }, + 'zoc5q': { + 'name': '1y0cp', + 'code': 'zoc5q', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'isFromPos': 'false' + } + } + } + ) + ) + + response = self.client.order_methods() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_methods_edit(self): + """ + V3 Test method order_methods_edit + """ + + method = {'code': 'zoc5q', 'name': '1y0cp'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/reference/order-methods/' + method['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('orderMethod', method)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.order_methods_edit(method) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_types(self): + """ + V3 Test method order_types + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/reference/order-types') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'orderTypes': { + 's789': { + 'name': 'test', + 'code': 's789', + 'defaultForCrm': 'true', + 'defaultForApi': 'true', + 'ordering': 990 + }, + 'b7e20': { + 'name': 'vwt5f', + 'code': 'b7e20', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'ordering': 990 + } + } + } + ) + ) + + response = self.client.order_types() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_types_edit(self): + """ + V3 Test method order_types_edit + """ + + order_type = {'code': 's789', 'name': 'test'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/reference/order-types/' + order_type['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('orderType', order_type)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.order_types_edit(order_type) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_statuses(self): + """ + V3 Test method payment_statuses + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/reference/payment-statuses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'paymentStatuses': { + 'invoice': { + 'name': 'Выставлен счет', + 'code': 'invoice', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'paymentComplete': 'false', + 'ordering': 20, + 'paymentTypes': [ + 'bank-card', + 'bank-transfer', + 'credit', + 'cash', + 'e-money' + ] + }, + 'payment-start': { + 'name': 'Платеж проведен', + 'code': 'payment-start', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'paymentComplete': 'false', + 'ordering': 30, + 'paymentTypes': [ + 'bank-card', + 'bank-transfer', + 'credit', + 'cash', + 'e-money' + ] + } + } + } + ) + ) + + response = self.client.payment_statuses() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_statuses_edit(self): + """ + V3 Test method payment_statuses_edit + """ + + status = {'code': 'payment-start', 'name': 'Платеж проведен'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/reference/payment-statuses/' + status['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('paymentStatus', status)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.payment_statuses_edit(status) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_types(self): + """ + V3 Test method payment_types + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/reference/payment-types') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'paymentTypes': { + '056a3e': { + 'name': 'TestPaymentType-056a3e', + 'code': '056a3e', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'deliveryTypes': [], + 'paymentStatuses': [] + }, + '238c06': { + 'name': 'TestPaymentType-238c06', + 'code': '238c06', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'deliveryTypes': [], + 'paymentStatuses': [] + } + } + } + ) + ) + + response = self.client.payment_types() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_types_edit(self): + """ + V3 Test method payment_types_edit + """ + + payment_type = {'code': '238c06', 'name': 'TestPaymentType-238c06'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/reference/payment-types/' + payment_type['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('paymentType', payment_type)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.payment_types_edit(payment_type) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_product_statuses(self): + """ + V3 Test method product_statuses + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/reference/product-statuses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'productStatuses': { + 'confirming': { + 'code': 'confirming', + 'ordering': 20, + 'createdAt': '2018-04-10 12:33:58', + 'cancelStatus': 'false', + 'name': 'Подтверждение наличия' + }, + 'in-reserve': { + 'code': 'in-reserve', + 'ordering': 30, + 'createdAt': '2018-04-10 12:33:58', + 'cancelStatus': 'false', + 'name': 'В резерве' + } + } + } + ) + ) + + response = self.client.product_statuses() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_product_statuses_edit(self): + """ + V3 Test method product_statuses_edit + """ + + status = {'code': 'in-reserve', 'name': 'В резерве'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/reference/product-statuses/' + status['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('productStatus', status)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.product_statuses_edit(status) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_sites(self): + """ + V3 Test method sites + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/reference/sites') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'sites': { + 'sites': { + 'name': 'XXX', + 'url': 'http://url', + 'code': 'code', + 'defaultForCrm': 'false', + 'ymlUrl': 'http://url', + 'loadFromYml': 'true', + 'catalogUpdatedAt': '2020-04-03 13:56:26', + 'catalogLoadingAt': '2020-04-13 08:50:55', + 'countryIso': 'RU' + } + } + } + ) + ) + + response = self.client.sites() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_sites_edit(self): + """ + V3 Test method sites_edit + """ + + site = {'code': 'code', 'name': 'XXX'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/reference/sites/' + site['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('site', site)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.sites_edit(site) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_status_groups(self): + """ + V3 Test method status_groups + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/reference/status-groups') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'statusGroups': { + 'new': { + 'name': 'Новый', + 'code': 'new', + 'ordering': 10, + 'process': 'false', + 'statuses': [ + 'new', + 'rake-status' + ] + }, + 'approval': { + 'name': 'Согласование', + 'code': 'approval', + 'ordering': 20, + 'process': 'true', + 'statuses': [ + 'availability-confirmed', + 'offer-analog', + 'client-confirmed', + 'prepayed' + ] + } + } + } + ) + ) + + response = self.client.status_groups() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_statuses(self): + """ + V3 Test method statuses + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/reference/statuses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'statuses': { + 'new': { + 'name': 'Новый', + 'code': 'new', + 'ordering': 10, + 'group': 'new' + }, + 'rake-status': { + 'name': 'Rake status', + 'code': 'rake-status', + 'ordering': 990, + 'group': 'new' + } + } + } + ) + ) + + response = self.client.statuses() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_statuses_edit(self): + """ + V3 Test method statuses_edit + """ + + status = {'code': 'new', 'name': 'Новый'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/reference/statuses/' + status['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('status', status)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.statuses_edit(status) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_stores(self): + """ + V3 Test method stores + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/reference/stores') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'stores': [ + { + 'type': 'store-type-warehouse', + 'inventoryType': 'integer', + 'code': 'lca46', + 'name': 'new' + }, + { + 'type': 'store-type-warehouse', + 'inventoryType': 'integer', + 'code': 'q6w5i', + 'name': 's789' + } + ] + } + ) + ) + + response = self.client.stores() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_stores_edit(self): + """ + V3 Test method stores_edit + """ + + store = {'code': 'q6w5i', 'name': 's789'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/reference/stores/' + store['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('store', store)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.stores_edit(store) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_inventories(self): + """ + V3 Test method inventories + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/store/inventories') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[site]': 'https://help.ru'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': + { + 'limit': 20, + 'totalCount': 34, + 'currentPage': 1, + 'totalPageCount': 2 + }, + 'offers': [ + { + 'externalId': 'werew', + 'quantity': 102 + }, + { + 'externalId': '46', + 'quantity': 0 + }, + { + 'externalId': '33', + 'quantity': 0 + }] + } + ) + ) + + response = self.client.inventories({'site': 'https://help.ru'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_inventories_upload(self): + """ + V3 Test method inventories_upload + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/store/inventories/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('offers', {'externalId': 's789', 'id': 5603})) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'processedOffersCount': 0, + 'notFoundOffers': { + 'externalId': 's789', + 'xmlId': 9999 + } + } + ) + ) + + response = self.client.inventories_upload({'externalId': 's789', 'id': 5603}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_telephony_call_event(self): + """ + V3 Test method telephony_call_event + """ + + (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' + })) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.telephony_call_event('+799999999', 'hangup', 'c2321', 'busy') + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_telephony_calls_upload(self): + """ + V3 Test method telephony_calls_upload + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v3/telephony/calls/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('calls', {})) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'processedCallsCount': 5555, + 'duplicateCalls': [] + } + ) + ) + + response = self.client.telephony_calls_upload({}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_telephony_manager(self): + """ + V3 Test method telephony_manager + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v3/telephony/manager') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'phone': '+79999999999'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'manager': { + 'id': 777, + 'firstName': 'yyy', + 'lastName': 'xxxx', + 'patronymic': 's789', + 'email': 'mail@retailcrm.ru', + 'code': 'ccc7' + }, + 'customer': { + 'id': 888, + 'externalId': '5406', + 'firstName': 'ccc', + 'lastName': 's789', + 'patronymic': 's789', + 'email': 'mail@retailcrm.ru', + 'code': 'ccc7', + 'phones': [{'number': '+71111111111'}] + }, + 'links': { + 'newOrderLink': 'https://newOrderLink.ru', + 'lastOrderLink': 'https://lastOrderLink.ru', + 'newCustomerLink': 'https://newCustomerLink.ru', + 'customerLink': 'https://customerLink.ru', + } + } + ) + ) + + response = self.client.telephony_manager('+79999999999') + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_telephony_settings(self): + """ + V3 Test method telephony_settings + """ + + 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'}) + ) + + response = self.client.telephony_settings(code, '123x', 'url', 'active', 'name', 'url_image') + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def statistic_update(self): + """ + V3 Test method statistic_update + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/statistic/update') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.statistic_update() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) diff --git a/tests/v4_tests.py b/tests/v4_tests.py index 87a3c27..96069ce 100644 --- a/tests/v4_tests.py +++ b/tests/v4_tests.py @@ -5,65 +5,2224 @@ retailCRM API client v4 tests """ +from urllib.parse import urlencode import unittest import os import retailcrm +import pook +import json class TestVersion4(unittest.TestCase): """ TestClass for v4 """ + __header = {'Server': 'nginx/1.16.0', 'Content-Type': 'application/json; charset=UTF-8'} + + __customer = { + 'id': 9717, + 'externalId': 'c-34234', + 'createdAt': '2020-04-09 16:55:59', + 'vip': 'false', + 'bad': 'false', + 'site': 'test-org', + 'marginSumm': 28180, + 'totalSumm': 28180, + 'averageSumm': 28180, + 'ordersCount': 1, + 'customFields': [], + 'personalDiscount': 0, + 'address': { + 'id': 5667, + 'text': 'MAY' + }, + 'firstName': 'Аа', + 'lastName': 'Аа', + 'phones': [], + 'contragentType': 'individual' + } + + __order = { + 'slug': 3425, + 'summ': 0, + 'id': 3425, + 'number': '5604A', + 'externalId': '5603', + 'orderType': 'individual', + 'orderMethod': 'shopping-cart', + 'countryIso': 'RU', + 'createdAt': '2020-04-07 15:44:24', + 'statusUpdatedAt': '2020-04-07 15:44:24', + 'totalSumm': 0, + 'prepaySum': 0, + 'purchaseSumm': 0, + 'markDatetime': '2020-04-07 15:44:24', + 'call': 'false', + 'expired': 'false', + 'customer': { + 'id': 9711, + 'createdAt': '2020-04-07 15:44:24', + 'vip': 'false', + 'bad': 'false', + 'site': '127-0-0-1-8080', + 'ordersCount': 1, + 'customFields': [], + 'personalDiscount': 0, + 'email': '', + 'phones': [], + 'contragentType': 'individual' + }, + 'contragentType': 'individual', + 'delivery': { + 'cost': 0, + 'netCost': 0, + 'address': {} + }, + 'site': '127-0-0-1-8080', + 'status': 'new', + 'items': [], + 'fromApi': 'true', + 'shipped': 'false', + 'customFields': [] + } + + __pack = { + 'id': 122, + 'purchasePrice': 0, + 'quantity': 1, + 'store': '7777z', + 'item': { + 'id': 7632, + 'order': { + 'id': 5608 + }, + 'offer': { + 'externalId': 'x2342' + } + } + } def setUp(self): """ 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): + return urlencode({key: json.dumps(dictionary)}) + + @pook.on def test_wrong_api_url(self): """ V4 Test wrong api url """ - client = retailcrm.v4( - 'https://epoqwieqwpoieqpwoeiqpwoeiq.retailcrm.ru', '98sdf9sj8fsd9fjs9dfjs98') + + (pook.get('https://epoqq.retailcrm.ru' + '/api/v4/statistic/update') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(404) + .headers(self.__header) + .json( + { + 'success': 'true', + 'errorMsg': 'Account does not exist.' + } + ) + ) + + client = retailcrm.v4('https://epoqq.retailcrm.ru', os.getenv('RETAILCRM_KEY')) response = client.statistic_update() + pook.off() self.assertIsNot(response.is_successful(), True) self.assertEqual(response.get_error_msg(), 'Account does not exist.') + @pook.on def test_wrong_api_key(self): """ V4 Test wrong api key """ - client = retailcrm.v3(os.getenv('RETAILCRM_URL'), - '98sdf9sj8fsd9fjs9dfjs98') + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/statistic/update') + .headers({'X-API-KEY': 'XXXX'}) + .reply(200) + .headers(self.__header) + .json({'errorMsg': 'Wrong "apiKey" value.'}) + ) + + client = retailcrm.v4(os.getenv('RETAILCRM_URL'), 'XXXX') response = client.statistic_update() + pook.off() self.assertEqual(response.get_error_msg(), 'Wrong "apiKey" value.') + @pook.on def test_missing_api_key(self): """ V4 Test missing api key """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/statistic/update') + .headers({'X-API-KEY': None}) + .reply(200) + .headers(self.__header) + .json({'errorMsg': '"apiKey" is missing.'}) + ) + client = retailcrm.v4(os.getenv('RETAILCRM_URL'), None) response = client.statistic_update() + pook.off() self.assertEqual(response.get_error_msg(), '"apiKey" is missing.') - def test_api_versions(self): + @pook.on + def test_customers(self): """ - V4 Test api-versions method + V4 Test method customers """ - response = self.client.api_versions() + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/customers') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[online]': 'No', 'filter[contragentType]': 'individual'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 4347, + 'currentPage': 1, + 'totalPageCount': 87 + }, + 'customers': [self.__customer] + } + ) + ) + + response = self.client.customers({'online': 'No', 'contragentType': 'individual'}) + pook.off() self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) - def test_api_credentials(self): + @pook.on + def test_customers_create(self): """ - V4 Test api-credentials method + V4 Test method customers_create """ - response = self.client.api_credentials() + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/customers/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customer', self.__customer)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': 7117}) + ) + + response = self.client.customer_create(self.__customer) + pook.off() self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_fix_external_ids(self): + """ + V4 Test method customers_fix_external_ids + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/customers/fix-external-ids') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customers', self.__customer['externalId'])) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.customers_fix_external_ids(self.__customer['externalId']) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_history(self): + """ + V4 Test method customers_history + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/customers/history') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params( + { + 'filter[sinceId]': '1111', + 'filter[startDate]': '2016-01-07', + 'filter[endDate]': '2020-04-12' + } + ) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'generatedAt': '2020-04-15 17:43:12', + 'history': [ + { + 'id': 7018, + 'createdAt': '2018-04-11 09:01:26', + 'created': 'true', + 'source': 'api', + 'field': 'id', + 'apiKey': { + 'current': 'false' + }, + 'oldValue': 'null', + 'newValue': 4949, + 'customer': { + 'id': 4949, + 'externalId': 'x2342', + 'createdAt': '2018-04-11 09:01:26', + 'vip': 'false', + 'bad': 'false', + 'site': 'retailcrm-ru', + 'contragent': { + 'contragentType': 'individual' + }, + 'marginSumm': 0, + 'totalSumm': 0, + 'averageSumm': 0, + 'ordersCount': 0, + 'customFields': [], + 'personalDiscount': 0, + 'cumulativeDiscount': 0, + 'firstName': 'XXX', + 'lastName': 'XXX', + 'patronymic': 'XXX', + 'email': 'xxx@example.com' + } + } + ] + } + ) + ) + + response = self.client.customers_history( + { + 'sinceId': '1111', + 'startDate': '2016-01-07', + 'endDate': '2020-04-12' + } + ) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_upload(self): + """ + V4 Test method customers_upload + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/customers/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customers', self.__customer)) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'uploadedCustomers': [ + { + 'id': 9717, + 'externalId': 'c-983344770' + } + ] + } + ) + ) + + response = self.client.customers_upload(self.__customer) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer(self): + """ + V4 Test method customer + """ + + uid = str(self.__customer['externalId']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/customers/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'customers': self.__customer}) + ) + + response = self.client.customer(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_edit(self): + """ + V4 Test method customers_edit + """ + + uid = str(self.__customer['externalId']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/customers/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customer', self.__customer)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 9717}) + ) + + response = self.client.customer_edit(self.__customer) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_setting(self): + """ + V4 Test method delivery_setting + """ + + code = 'zzz' + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/delivery/generic/setting/' + code) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'configuration': { + 'actions': {}, + 'payerType': [ + 'sender' + ], + 'platePrintLimit': 100, + 'rateDeliveryCost': 'true', + 'allowPackages': 'false', + 'codAvailable': 'false', + 'selfShipmentAvailable': 'false', + 'duplicateOrderProductSupported': 'false', + 'availableCountries': [], + 'requiredFields': [], + 'statusList': [ + { + 'code': 's789', + 'name': 'sss', + 'isEditable': 'true' + }, + { + 'code': 'crmDeleted', + 'name': 'Удален', + 'isEditable': 'false' + } + ], + 'name': 'test', + 'code': 'zzz', + 'availableShipmentCountries': [] + } + } + ) + ) + + response = self.client.delivery_setting(code) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_setting_edit(self): + """ + V4 Test method delivery_setting_edit + """ + + configuration = { + 'payerType': ['sender'], + 'statusList': [ + { + 'code': 's789', + 'name': 'sss', + 'isEditable': 'true' + } + ], + 'name': 'test', + 'code': 'zzz' + } + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/delivery/generic/setting/' + configuration['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('configuration', configuration)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'code': 'generic.zzz'}) + ) + + response = self.client.delivery_setting_edit(configuration) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_tracking(self): + """ + V4 Test method delivery_tracking + """ + + code = 'zzz' + tracking = { + 'deliveryId': '777z', + 'history': [ + { + 'code': '888', + 'updatedAt': '2020-04-12', + 'comment': 'Good' + } + ] + } + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/delivery/generic/' + code + '/tracking') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('statusUpdate', tracking)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.delivery_tracking(code, tracking) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_marketplace_setting_edit(self): + """ + V4 Test method marketplace_setting_edit + """ + + code = 'May' + configuration = {'name': 'Test123', 'code': code, 'configurationUrl': 'https://may.cat.ru'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/marketplace/external/setting/' + code + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('configuration', configuration)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + self.client.marketplace_setting_edit(configuration) + pook.off() + + @pook.on + def test_orders(self): + """ + V4 Test method orders + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/orders') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[city]': 'Moscow', 'filter[contragentType]': 'individual'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 2464, + 'currentPage': 1, + 'totalPageCount': 50 + }, + 'orders': [self.__order] + } + ) + ) + + response = self.client.orders({'city': 'Moscow', 'contragentType': 'individual'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_create(self): + """ + V4 Test method orders_create + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/orders/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('order', self.__order)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': 8888, 'order': self.__order}) + ) + + response = self.client.order_create(self.__order) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_fix_external_ids(self): + """ + V4 Test method orders_fix_external_ids + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/orders/fix-external-ids') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('orders', (self.__order['externalId']))) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.orders_fix_external_ids(self.__order['externalId']) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_history(self): + """ + V4 Test method orders_history + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/orders/history') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params( + { + 'filter[sinceId]': '1111', + 'filter[startDate]': '2016-01-07', + 'filter[endDate]': '2020-04-12' + } + ) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'generatedAt': '2020-04-16 11:03:00', + 'history': [ + { + 'id': 7887, + 'createdAt': '2018-04-11 09:01:29', + 'created': 'true', + 'source': 'api', + 'field': 'status', + 'apiKey': { + 'current': 'false' + }, + 'oldValue': 'null', + 'newValue': { + 'code': 'new' + }, + 'order': { + 'slug': 9090, + 'summ': 0, + 'id': 9090, + 'number': '9090A', + 'externalId': 'x353', + 'orderType': 'eshop-individual', + 'orderMethod': 'shopping-cart', + 'createdAt': '2018-04-11 09:01:29', + 'statusUpdatedAt': '2018-04-11 09:01:29', + 'totalSumm': 0, + 'prepaySum': 0, + 'purchaseSumm': 0, + 'markDatetime': '2018-04-11 09:01:29', + 'lastName': 'xxxx', + 'firstName': 'xxxx', + 'patronymic': 'xxxx', + 'email': 'maymayslt@example.com', + 'call': 'false', + 'expired': 'false', + 'customer': { + 'id': 5544, + 'isContact': 'false', + 'createdAt': '2018-04-11 09:01:29', + 'vip': 'false', + 'bad': 'false', + 'site': 'retailcrm-ru', + 'contragent': { + 'contragentType': 'individual' + }, + 'marginSumm': 0, + 'totalSumm': 0, + 'averageSumm': 0, + 'ordersCount': 1, + 'customFields': [], + 'personalDiscount': 0, + 'cumulativeDiscount': 0, + 'address': { + 'id': 3322 + }, + 'lastName': 'xxxx', + 'firstName': 'xxxx', + 'patronymic': 'xxxx', + 'email': 'maymays@example.com', + 'phones': [] + }, + 'contragent': { + 'contragentType': 'individual' + }, + 'delivery': { + 'cost': 0, + 'netCost': 0, + 'address': { + 'id': 2477, + 'countryIso': '' + } + }, + 'site': 'retailcrm-ru', + 'status': 'new', + 'items': [], + 'fromApi': 'true', + 'shipped': 'false', + 'customFields': [] + } + } + ] + } + ) + ) + + response = self.client.orders_history( + { + 'sinceId': '1111', + 'startDate': '2016-01-07', + 'endDate': '2020-04-12' + } + ) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_statuses(self): + """ + V4 Test method orders_statuses + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/orders/statuses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'ids[]': '5604', 'externalIds[]': '5603'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'orders': [ + { + 'id': 5604, + 'externalId': '5603', + 'status': 'new', + 'group': 'new' + } + ] + } + ) + ) + + response = self.client.orders_statuses([5604], [5603]) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_upload(self): + """ + V4 Test method orders_upload + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/orders/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('orders', self.__order)) + .reply(201) + .headers(self.__header) + .json( + { + 'success': 'true', + 'uploadedOrders': [ + { + 'id': 5604, + 'externalId': '5603' + } + ], + 'orders': [self.__order] + } + ) + ) + + response = self.client.orders_upload(self.__order) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order(self): + """ + V4 Test method order + """ + + uid = str(self.__order['externalId']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/orders/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'orders': self.__order}) + ) + + response = self.client.order(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_edit(self): + """ + V4 Test method orders_edit + """ + + uid = str(self.__order['externalId']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/orders/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('order', self.__order)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 5604, 'order': self.__order}) + ) + + response = self.client.order_edit(self.__order) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_packs(self): + """ + V4 Test method packs + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/orders/packs') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[store]': '7777z'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 1, + 'currentPage': 1, + 'totalPageCount': 1 + }, + 'packs': [self.__pack] + } + ) + ) + + response = self.client.packs({'store': '7777z'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_packs_create(self): + """ + V4 Test method packs_create + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/orders/packs/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('pack', self.__pack)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': 7777}) + ) + + response = self.client.pack_create(self.__pack) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_packs_history(self): + """ + V4 Test method packs_history + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/orders/packs/history') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[startDate]': '2016-01-07', 'filter[endDate]': '2020-04-12'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'generatedAt': '2020-04-17 13:08:48', + 'history': [ + { + 'id': 777, + 'createdAt': '2018-04-13 15:46:06', + 'created': 'true', + 'field': 'store', + 'newValue': { + 'code': 'eee' + }, + 'pack': { + 'id': 678, + 'quantity': 1, + 'store': {'code': 'eee'}, + 'item': { + 'id': 222, + 'order': {'id': 6677}, + 'offer': {'externalId': '333'} + } + }, + 'source': 'api' + } + ] + } + ) + ) + + response = self.client.packs_history({'startDate': '2016-01-07', 'endDate': '2020-04-12'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_pack(self): + """ + V4 Test method pack + """ + + uid = str(self.__pack['id']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/orders/packs/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'pack': self.__pack}) + ) + + response = self.client.pack(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_packs_delete(self): + """ + V4 Test method packs_delete + """ + + uid = '7777' + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/orders/packs/' + uid + '/delete') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.pack_delete(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_pack_edit(self): + """ + V4 Test method pack_edit + """ + + uid = str(self.__pack['id']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/orders/packs/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('pack', self.__pack)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 5604}) + ) + + response = self.client.pack_edit(self.__pack) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_countries(self): + """ + V4 Test method countries + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/reference/countries') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'countriesIso': ['RU', 'UA', 'BY', 'KZ']}) + ) + + response = self.client.countries() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_services(self): + """ + V4 Test method delivery_services + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/reference/delivery-services') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'deliveryServices': { + 'hp5kc': { + 'name': '8305u', + 'code': 'hp5kc', + 'active': 'true' + }, + 'hmo8s': { + 'name': 'j456', + 'code': 'hmo8s', + 'active': 'true' + } + } + } + ) + ) + + response = self.client.delivery_services() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_services_edit(self): + """ + V4 Test method delivery_services_edit + """ + + service = {'code': 'hmo8s', 'name': 'g4562'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/reference/delivery-services/' + service['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('deliveryService', service)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.delivery_services_edit(service) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_types(self): + """ + V4 Test method delivery_types + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/reference/delivery-types') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(201) + .headers(self.__header) + .json( + { + 'success': 'true', + 'deliveryTypes': { + '1kp52': { + 'name': 'xas', + 'code': '1kp52', + 'defaultCost': 300, + 'defaultNetCost': 0, + 'paymentTypes': [ + 'cash', + 'bank-card' + ], + 'deliveryServices': [], + 'defaultForCrm': 'false' + }, + 'wer': { + 'name': '1s0ei', + 'code': 'd452', + 'defaultCost': 300, + 'defaultNetCost': 0, + 'paymentTypes': [ + 'cash', + 'bank-card' + ], + 'deliveryServices': [], + 'defaultForCrm': 'false' + } + } + } + ) + ) + + response = self.client.delivery_types() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_types_edit(self): + """ + V4 Test method delivery_types_edit + """ + + delivery_type = {'code': 'x345', 'name': '1s0ei'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/reference/delivery-types/' + delivery_type['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('deliveryType', delivery_type)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.delivery_types_edit(delivery_type) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_methods(self): + """ + V4 Test method order_methods + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/reference/order-methods') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'orderMethods': { + '44cmd': { + 'name': '1tdf4', + 'code': '44cmd', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'isFromPos': 'false' + }, + 'zoc5q': { + 'name': '1y0cp', + 'code': 'zoc5q', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'isFromPos': 'false' + } + } + } + ) + ) + + response = self.client.order_methods() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_methods_edit(self): + """ + V4 Test method order_methods_edit + """ + + method = {'code': 'zoc5q', 'name': '1y0cp'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/reference/order-methods/' + method['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('orderMethod', method)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.order_methods_edit(method) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_types(self): + """ + V4 Test method order_types + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/reference/order-types') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'orderTypes': { + 's234': { + 'name': 'test', + 'code': 's234', + 'defaultForCrm': 'true', + 'defaultForApi': 'true', + 'ordering': 990 + }, + 'b7e20': { + 'name': 'vwt5f', + 'code': 'b7e20', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'ordering': 990 + } + } + } + ) + ) + + response = self.client.order_types() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_types_edit(self): + """ + V4 Test method order_types_edit + """ + + order_type = {'code': 's234', 'name': 'test'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/reference/order-types/' + order_type['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('orderType', order_type)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.order_types_edit(order_type) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_statuses(self): + """ + V4 Test method payment_statuses + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/reference/payment-statuses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'paymentStatuses': { + 'invoice': { + 'name': 'Выставлен счет', + 'code': 'invoice', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'paymentComplete': 'false', + 'ordering': 14, + 'paymentTypes': [ + 'bank-card', + 'bank-transfer', + 'credit', + 'cash', + 'e-money' + ] + }, + 'payment-start': { + 'name': 'Платеж проведен', + 'code': 'payment-start', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'paymentComplete': 'false', + 'ordering': 30, + 'paymentTypes': [ + 'bank-card', + 'bank-transfer', + 'credit', + 'cash', + 'e-money' + ] + } + } + } + ) + ) + + response = self.client.payment_statuses() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_statuses_edit(self): + """ + V4 Test method payment_statuses_edit + """ + + status = {'code': 'payment-start', 'name': 'Платеж проведен'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/reference/payment-statuses/' + status['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('paymentStatus', status)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.payment_statuses_edit(status) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_types(self): + """ + V4 Test method payment_types + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/reference/payment-types') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'paymentTypes': { + '056a3e': { + 'name': 'TestPaymentType-056a3e', + 'code': '2345', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'deliveryTypes': [], + 'paymentStatuses': [] + }, + '238c06': { + 'name': 'TestPaymentType-238c06', + 'code': '238c06', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'deliveryTypes': [], + 'paymentStatuses': [] + } + } + } + ) + ) + + response = self.client.payment_types() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_types_edit(self): + """ + V4 Test method payment_types_edit + """ + + payment_type = {'code': '238c06', 'name': 'TestPaymentType-238c06'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/reference/payment-types/' + payment_type['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('paymentType', payment_type)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.payment_types_edit(payment_type) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_product_statuses(self): + """ + V4 Test method product_statuses + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/reference/product-statuses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'productStatuses': { + 'confirming': { + 'code': 'confirming', + 'ordering': 20, + 'createdAt': '2018-04-10 12:33:58', + 'cancelStatus': 'false', + 'name': 'Подтверждение наличия' + }, + 'in-reserve': { + 'code': 'in-reserve', + 'ordering': 30, + 'createdAt': '2018-04-10 12:33:58', + 'cancelStatus': 'false', + 'name': 'В резерве' + } + } + } + ) + ) + + response = self.client.product_statuses() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_product_statuses_edit(self): + """ + V4 Test method product_statuses_edit + """ + + status = {'code': 'in-reserve', 'name': 'В резерве'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/reference/product-statuses/' + status['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('productStatus', status)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.product_statuses_edit(status) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_sites(self): + """ + V4 Test method sites + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/reference/sites') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'sites': { + 'sites': { + 'name': 'XXX', + 'url': 'http://url', + 'code': 'code', + 'defaultForCrm': 'false', + 'ymlUrl': 'http://url', + 'loadFromYml': 'true', + 'catalogUpdatedAt': '2020-04-03 13:56:26', + 'catalogLoadingAt': '2020-04-13 08:50:55', + 'countryIso': 'RU' + } + } + } + ) + ) + + response = self.client.sites() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_sites_edit(self): + """ + V4 Test method sites_edit + """ + + site = {'code': 'code', 'name': 'XXX'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/reference/sites/' + site['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('site', site)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.sites_edit(site) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_status_groups(self): + """ + V4 Test method status_groups + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/reference/status-groups') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'statusGroups': { + 'new': { + 'name': 'Новый', + 'code': 'new', + 'ordering': 23, + 'process': 'false', + 'statuses': [ + 'new', + 'rake-status' + ] + }, + 'approval': { + 'name': 'Согласование', + 'code': 'approval', + 'ordering': 20, + 'process': 'true', + 'statuses': [ + 'availability-confirmed', + 'offer-analog', + 'client-confirmed', + 'prepayed' + ] + } + } + } + ) + ) + + response = self.client.status_groups() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_statuses(self): + """ + V4 Test method statuses + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/reference/statuses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'statuses': { + 'new': { + 'name': 'Новый', + 'code': 'new', + 'ordering': 10, + 'group': 'new' + }, + 'rake-status': { + 'name': 'Rake status', + 'code': 'rake-status', + 'ordering': 990, + 'group': 'new' + } + } + } + ) + ) + + response = self.client.statuses() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_statuses_edit(self): + """ + V4 Test method statuses_edit + """ + + status = {'code': 'new', 'name': 'Новый'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/reference/statuses/' + status['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('status', status)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.statuses_edit(status) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_stores(self): + """ + V4 Test method stores + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/reference/stores') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'stores': [ + { + 'type': 'store-type-warehouse', + 'inventoryType': 'integer', + 'code': 'lca46', + 'name': 'new' + }, + { + 'type': 'store-type-warehouse', + 'inventoryType': 'integer', + 'code': 'q6w5i', + 'name': 'u532' + } + ] + } + ) + ) + + response = self.client.stores() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_stores_edit(self): + """ + V4 Test method stores_edit + """ + + store = {'code': 'q6w5i', 'name': 'u245'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/reference/stores/' + store['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('store', store)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.stores_edit(store) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_inventories(self): + """ + V4 Test method inventories + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/store/inventories') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[site]': 'https://retailcrm.ru'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 621, + 'currentPage': 1, + 'totalPageCount': 32 + }, + 'offers': [ + { + 'id': 33937, + 'externalId': 'werew', + 'site': 'https://retailcrm.ru', + 'quantity': 102 + }, + { + 'id': 33933, + 'externalId': '46', + 'site': 'https://retailcrm.ru', + 'quantity': 0 + } + ] + } + ) + ) + + response = self.client.inventories({'site': 'https://retailcrm.ru'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_inventories_upload(self): + """ + V4 Test method inventories_upload + """ + + inventories = {'externalId': '5603', 'id': 5603} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/store/inventories/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('offers', inventories)) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'processedOffersCount': 0, + 'notFoundOffers': { + 'externalId': 'u234', + 'xmlId': 9999 + } + } + ) + ) + + response = self.client.inventories_upload(inventories) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_prices_upload(self): + """ + V4 Test method prices_upload + """ + + price = [{'price': 999, 'externalId': 'werew'}] + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/store/prices/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('prices', price)) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'processedOffersCount': 0, + 'notFoundOffers': [ + { + 'externalId': 'werew' + } + ] + } + ) + ) + + response = self.client.prices_upload(price) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_products(self): + """ + V4 Test method products + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/store/products') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[priceType]': 'base', 'filter[active]': '1'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 558, + 'currentPage': 1, + 'totalPageCount': 28 + }, + 'products': [ + { + 'minPrice': 100, + 'maxPrice': 100, + 'id': 25804, + 'name': 'sds', + 'manufacturer': 'asdas', + 'offers': [ + { + 'name': 'sdfsdf', + 'price': 100, + 'id': 33937, + 'externalId': 'werew', + 'article': 'ewrwrew', + 'prices': [ + { + 'priceType': 'base', + 'price': 100, + 'ordering': 991 + } + ], + 'weight': 44 + } + ], + 'active': 'true', + 'quantity': 102, + 'markable': 'false' + } + ] + } + ) + ) + + response = self.client.products({'priceType': 'base', 'active': 1}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_store_setting(self): + """ + V4 Test method store_setting + """ + + code = 'xxx' + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/store/setting/' + code) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params(code) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'configuration': { + 'actions': [ + { + 'code': 'ccc', + 'url': 'https://test' + } + ], + 'code': 'xxx', + 'active': 'true', + 'name': 'test', + 'baseUrl': '/' + } + } + ) + ) + + response = self.client.store_setting(code) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_store_setting_edit(self): + """ + V4 Test method store_setting_edit + """ + + setting = { + 'code': 'xxx', + 'name': 'test', + 'actions': [ + { + 'code': 'ccc', + 'url': 'https://test' + } + ] + } + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/store/setting/' + setting['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('configuration', setting)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.store_setting_edit(setting) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_telephony_call_event(self): + """ + V4 Test method telephony_call_event + """ + + call_event = {'phone': '+799999999', 'type': 'out'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/telephony/call/event') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('event', call_event)) + .reply(200) + .headers(self.__header) + .json({'success': 'false', 'errorMsg': 'Telephony not enabled'}) + ) + + response = self.client.telephony_call_event(call_event) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_telephony_calls_upload(self): + """ + V4 Test method telephony_calls_upload + """ + + call = {'phone': '79999999999', 'type': 'out'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/telephony/calls/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('calls', call)) + .reply(200) + .headers(self.__header) + .json({'success': 'false', 'errorMsg': 'Telephony not enabled or not supports calls upload'} + ) + ) + + response = self.client.telephony_calls_upload(call) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_telephony_manager(self): + """ + V4 Test method telephony_manager + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/telephony/manager') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params('+79999999999') + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'manager': { + 'id': 777, + 'firstName': 'yyy', + 'lastName': 'xxxx', + 'patronymic': 'www', + 'email': 'mail@retailcrm.ru', + 'code': 'ccc7' + }, + 'customer': { + 'id': 888, + 'externalId': '5406', + 'firstName': 'ccc', + 'lastName': 'zzz', + 'patronymic': 'sss', + 'email': 'mail@retailcrm.ru', + 'code': 'ccc7', + 'phones': [{'number': '+71111111111'}] + }, + 'links': { + 'newOrderLink': 'https://newOrderLink.ru', + 'lastOrderLink': 'https://lastOrderLink.ru', + 'newCustomerLink': 'https://newCustomerLink.ru', + 'customerLink': 'https://customerLink.ru', + } + } + ) + ) + + response = self.client.telephony_manager('+79999999999') + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_telephony_setting(self): + """ + V4 Test method telephony_setting + """ + + code = 'www' + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/telephony/setting/' + code) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params(code) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'configuration': { + 'makeCallUrl': 'https://retailcrm.ru', + 'allowEdit': 'false', + 'inputEventSupported': 'false', + 'outputEventSupported': 'false', + 'additionalCodes': [], + 'externalPhones': [], + 'code': 'www', + 'active': 'false', + 'name': 'telephony.company.www' + } + } + ) + ) + + response = self.client.telephony_setting(code) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_telephony_setting_edit(self): + """ + V4 Test method telephony_setting_edit + """ + + configuration = { + 'code': 'www', + 'clientId': '5604', + 'makeCallUrl': 'https://retailcrm.ru' + } + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v4/telephony/setting/' + configuration['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('configuration', configuration)) + .reply(201) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.telephony_setting_edit(configuration) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_user_groups(self): + """ + V4 Test method user_groups + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/user-groups') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 2, + 'currentPage': 1, + 'totalPageCount': 1 + }, + 'groups': [ + { + 'name': 'Менеджеры', + 'code': 'manager', + 'isManager': 'true', + 'isPosManager': 'false', + 'isDeliveryMen': 'false', + 'deliveryTypes': [], + 'breakdownOrderTypes': ['xxx', 'yyy', 'zzz'], + }, + { + 'name': 'Руководители', + 'code': 'director', + 'isManager': 'false', + 'isPosManager': 'false', + 'isDeliveryMen': 'false', + 'deliveryTypes': ['xxx'], + 'breakdownOrderTypes': ['yyy'], + 'breakdownSites': [], + 'breakdownOrderMethods': ['zzz'], + 'grantedOrderTypes': ['ccc'] + } + ] + } + ) + ) + + response = self.client.user_groups() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_users(self): + """ + V4 Test method users + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/users') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[status]': 'online', 'filter[isManager]': 'false'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 7, + 'currentPage': 1, + 'totalPageCount': 1 + }, + 'users': [ + { + 'id': 777, + 'createdAt': '2020-04-05 11:23:46', + 'active': 'true', + 'email': 'mail@retailcrm.ru', + 'firstName': 'yyy', + 'lastName': 'xxxx', + 'status': 'free', + 'online': 'true', + 'isAdmin': 'true', + 'isManager': 'false', + 'groups': [] + } + ] + } + ) + ) + + response = self.client.users({'status': 'online', 'isManager': 'false'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_user(self): + """ + V4 Test method user + """ + + uid = 777 + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v4/users/' + str(uid)) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'user': { + 'id': 777, + 'createdAt': '2020-04-05 11:23:46', + 'active': 'true', + 'email': 'mail@retailcrm.ru', + 'firstName': 'yyy', + 'lastName': 'xxxx', + 'status': 'free', + 'online': 'true', + 'isAdmin': 'true', + 'isManager': 'false', + 'groups': [] + } + } + ) + ) + + response = self.client.user(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def statistic_update(self): + """ + V4 Test method statistic_update + """ + + (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'}) + ) + + response = self.client.statistic_update() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) diff --git a/tests/v5_tests.py b/tests/v5_tests.py index 4badebf..afdb5ab 100644 --- a/tests/v5_tests.py +++ b/tests/v5_tests.py @@ -5,10 +5,12 @@ retailCRM API client v5 tests """ +from urllib.parse import urlencode import unittest import os -import random import retailcrm +import pook +import json class TestVersion5(unittest.TestCase): @@ -16,100 +18,4666 @@ class TestVersion5(unittest.TestCase): TestClass for v5 """ + __header = {'Server': 'nginx/1.16.0', 'Content-Type': 'application/json; charset=UTF-8'} + + __customer = { + 'id': 9717, + 'externalId': 'c-111111111', + 'createdAt': '2020-04-09 16:55:59', + 'vip': 'false', + 'bad': 'false', + 'site': 'test-org', + 'marginSumm': 28180, + 'totalSumm': 28180, + 'averageSumm': 28180, + 'ordersCount': 1, + 'customFields': [], + 'personalDiscount': 0, + 'address': { + 'id': 5667, + 'text': 'MAY' + }, + 'firstName': 'Аа', + 'lastName': 'Аа', + 'phones': [], + 'contragentType': 'individual' + } + + __order = { + 'slug': 5604, + 'summ': 0, + 'id': 5604, + 'number': '5604A', + 'externalId': '5603', + 'orderType': 'individual', + 'orderMethod': 'shopping-cart', + 'countryIso': 'RU', + 'createdAt': '2020-04-07 15:44:24', + 'statusUpdatedAt': '2020-04-07 15:44:24', + 'totalSumm': 0, + 'prepaySum': 0, + 'purchaseSumm': 0, + 'markDatetime': '2020-04-07 15:44:24', + 'call': 'false', + 'expired': 'false', + 'customer': { + 'id': 9711, + 'createdAt': '2020-04-07 15:44:24', + 'vip': 'false', + 'bad': 'false', + 'site': '127-0-0-1-8080', + 'marginSumm': 0, + 'totalSumm': 0, + 'averageSumm': 0, + 'ordersCount': 1, + 'customFields': [], + 'personalDiscount': 0, + 'email': '', + 'phones': [], + 'contragentType': 'individual' + }, + 'contragentType': 'individual', + 'delivery': { + 'cost': 0, + 'netCost': 0, + 'address': {} + }, + 'site': '127-0-0-1-8080', + 'status': 'new', + 'items': [], + 'fromApi': 'true', + 'shipped': 'false', + 'customFields': [] + } + + __pack = { + 'id': 122, + 'purchasePrice': 0, + 'quantity': 1, + 'store': '7777z', + 'item': { + 'id': 7632, + 'order': { + 'id': 5608 + }, + 'offer': { + 'externalId': 'y6642' + } + } + } + + __cost = { + 'id': 635, + 'dateFrom': '2020-01-30', + 'dateTo': '2020-01-30', + 'summ': 2, + 'costItem': 'delivery-cost', + 'createdAt': '2020-01-30 16:43:36', + 'order': { + 'id': 4798, + 'number': '16', + 'externalId': '16' + }, + 'sites': [ + 'prestashop' + ] + } + + __file = { + 'id': 30, + 'filename': 'API upload 18-09-2019 13:14:00', + 'type': 'application/pdf', + 'createdAt': '2019-09-18 13:14:00', + 'size': 124225, + 'attachment': [ + { + 'order': { + 'id': 7777, + 'number': '7777A', + 'site': 'hhhh' + } + } + ] + } + + __customer_corporate = { + 'type': 'customer_corporate', + 'id': 9084, + 'externalId': 'cc_9', + 'nickName': 'Test', + 'mainAddress': { + 'id': 3995, + 'name': 'Test' + }, + 'createdAt': '2020-02-14 13:49:21', + 'vip': 'false', + 'bad': 'false', + 'site': 'opencart', + 'tags': [], + 'marginSumm': 0, + 'totalSumm': 0, + 'averageSumm': 0, + 'ordersCount': 0, + 'costSumm': 0, + 'customFields': [], + 'personalDiscount': 0, + 'ainCustomerContact': { + 'id': 33, + 'customer': { + 'id': 9083, + 'externalId': '9' + }, + 'companies': [] + }, + 'mainCompany': { + 'id': 31, + 'name': 'Test' + } + } + + __task = { + 'id': 433, + 'text': 'test task edited', + 'commentary': 'test commentary', + 'complete': 'false', + 'phone': '+79185550000', + 'performerId': 15 + } + def setUp(self): """ 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): + return urlencode({key: json.dumps(dictionary)}) + + @pook.on def test_wrong_api_url(self): """ V5 Test wrong api url """ - client = retailcrm.v5( - 'https://epoqwieqwpoieqpwoeiqpwoeiq.retailcrm.ru', '98sdf9sj8fsd9fjs9answer98') + + (pook.get('https://epoqq.retailcrm.ru' + '/api/v5/statistic/update') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(404) + .headers(self.__header) + .json( + { + 'success': 'true', + 'errorMsg': 'Account does not exist.' + } + ) + ) + + client = retailcrm.v5('https://epoqq.retailcrm.ru', os.getenv('RETAILCRM_KEY')) response = client.statistic_update() + pook.off() self.assertIsNot(response.is_successful(), True) self.assertEqual(response.get_error_msg(), 'Account does not exist.') + @pook.on def test_wrong_api_key(self): """ V5 Test wrong api key """ - client = retailcrm.v5(os.getenv('RETAILCRM_URL'), '98sdf9sj8fsd9fjs9answer98') + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/statistic/update') + .headers({'X-API-KEY': 'XXXX'}) + .reply(200) + .headers(self.__header) + .json({'errorMsg': 'Wrong "apiKey" value.'}) + ) + + client = retailcrm.v5(os.getenv('RETAILCRM_URL'), 'XXXX') response = client.statistic_update() + pook.off() self.assertEqual(response.get_error_msg(), 'Wrong "apiKey" value.') + @pook.on def test_missing_api_key(self): """ V5 Test missing api key """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/statistic/update') + .headers({'X-API-KEY': None}) + .reply(200) + .headers(self.__header) + .json({'errorMsg': '"apiKey" is missing.'}) + ) + client = retailcrm.v5(os.getenv('RETAILCRM_URL'), None) response = client.statistic_update() + pook.off() self.assertEqual(response.get_error_msg(), '"apiKey" is missing.') + @pook.on def test_api_versions(self): """ V5 Test api-versions method """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/api-versions') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'versions': ['3.0', '4.0', '5.0']}) + ) + response = self.client.api_versions() + pook.off() self.assertTrue(response.is_successful(), True) + @pook.on def test_api_credentials(self): """ V5 Test api-credentials method """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/credentials') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'credentials': [], 'siteAccess': 'access_full'}) + ) + response = self.client.api_credentials() + pook.off() self.assertTrue(response.is_successful(), True) - def test_set_user_status(self): - response = self.client.user_status(os.getenv('RETAILCRM_USER'), 'dinner') + @pook.on + def test_costs(self): + """ + V5 Test method costs + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/costs') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 6, + 'currentPage': 1, + 'totalPageCount': 1 + }, + 'costs': [self.__cost] + } + ) + ) + + response = self.client.costs() + pook.off() self.assertTrue(response.is_successful(), True) self.assertTrue(response.get_status_code() < 400, True) - def test_check_order_payment(self): - rand = random.randint(10000, 99999) - ex_id = 'test-case-payment' + str(rand) - order = { - 'firstName': 'John', - 'lastName': 'Doe', - 'phone': '+79000000000', - 'email': 'john@example.com', - 'orderMethod': 'call-request', - 'delivery': { - 'code': 'self-delivery' - }, - 'payments': [ + @pook.on + def test_costs_create(self): + """ + V5 Test method costs_create + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/costs/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('cost', self.__cost)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': 7117}) + ) + + response = self.client.cost_create(self.__cost) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_costs_delete(self): + """ + V5 Test method costs_delete + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/costs/delete') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('ids', [555, 666, 777])) + .reply(200) + .headers(self.__header) + .json( { - 'externalId': ex_id, - 'amount': 100, - 'type': 'cash' + 'success': 'true', + 'count': 3, + 'notRemovedIds': [] + } + ) + ) + + response = self.client.costs_delete([555, 666, 777]) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_costs_upload(self): + """ + V5 Test method costs_upload + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/costs/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('costs', [self.__cost])) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'uploadedCosts': [555]}) + ) + + response = self.client.costs_upload([self.__cost]) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_cost(self): + """ + V5 Test method cost + """ + + uid = str(self.__cost['id']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/costs/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'cost': self.__cost}) + ) + + response = self.client.cost(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_costs_delete(self): + """ + V5 Test method costs_delete + """ + + uid = '7777' + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/costs/' + uid + '/delete') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.cost_delete(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_costs_edit(self): + """ + V5 Test method cost_edit + """ + + uid = str(self.__cost['id']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/costs/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('cost', self.__cost)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 7777}) + ) + + response = self.client.cost_edit(self.__cost) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_custom_fields(self): + """ + V5 Test method custom_fields + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/custom-fields') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[entity]': 'customer'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 66, + 'currentPage': 1, + 'totalPageCount': 4 + }, + 'customFields': [ + { + 'name': 'xxxx', + 'code': 'test', + 'required': 'false', + 'inFilter': 'true', + 'inList': 'true', + 'inGroupActions': 'false', + 'type': 'text', + 'entity': 'order', + 'ordering': 50, + 'displayArea': 'delivery', + 'viewMode': 'editable' + } + ] + } + ) + ) + + response = self.client.custom_fields({'entity': 'customer'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_custom_dictionaries(self): + """ + V5 Test method custom_dictionaries + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/custom-fields/dictionaries') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[name]': 'test223'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 67, + 'currentPage': 1, + 'totalPageCount': 1 + }, + 'customDictionaries': [ + { + 'name': 'test223', + 'code': 'test2', + 'elements': [ + { + 'name': 'test3', + 'code': 'test3', + 'ordering': 50 + } + ] + } + ] + } + ) + ) + + response = self.client.custom_dictionaries({'name': 'test223'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_custom_dictionary_create(self): + """ + V5 Test method custom_dictionary_create + """ + + custom_dictionary = { + 'name': 'test', + 'code': 'test', + 'elements': [{'name': 'fear', 'code': 'e456'}] + } + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/custom-fields/dictionaries/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customDictionary', custom_dictionary)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'code': 'test'}) + ) + + response = self.client.custom_dictionary_create(custom_dictionary) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_custom_dictionary(self): + """ + V5 Test method custom_dictionary + """ + + uid = '777' + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/custom-fields/dictionaries/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'customDictionary': { + 'name': 'test223', + 'code': 'test2', + 'elements': [ + { + 'name': 'test3', + 'code': 'test3', + 'ordering': 50 + } + ] + } + } + ) + ) + + response = self.client.custom_dictionary(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_custom_dictionary_edit(self): + """ + V5 Test method custom_dictionary_edit + """ + + custom_dictionary = { + 'name': 'test', + 'code': 'test', + 'elements': [{'name': 'fear', 'code': 'e456'}] + } + + (pook.post( + 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'}) + ) + + response = self.client.custom_dictionary_edit(custom_dictionary) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_custom_field_create(self): + """ + V5 Test method custom_field_create + """ + + custom_field = { + 'name': 'test', + 'code': 'test', + 'type': 'text', + 'entity': 'customer' + } + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/custom-fields/' + custom_field['entity'] + '/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customField', custom_field)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'code': 'test'}) + ) + + response = self.client.custom_field_create(custom_field) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_custom_field(self): + """ + V5 Test method custom_field + """ + + entity = 'customer' + code = 'test' + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/custom-fields/' + entity + '/' + code) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'customField': { + 'name': 'test', + 'code': 'test', + 'required': 'false', + 'inFilter': 'true', + 'inList': 'true', + 'inGroupActions': 'false', + 'type': 'text', + 'entity': 'customer', + 'ordering': 50, + 'viewMode': 'editable' + } + } + ) + ) + + response = self.client.custom_field(code, entity) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_custom_field_edit(self): + """ + V5 Test method custom_field_edit + """ + + custom_field = { + 'name': 'test', + 'ordering': 5555, + 'displayArea': 'customer', + 'entity': 'customer', + 'code': 'test' + } + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/custom-fields/' + custom_field['entity'] + '/' + custom_field[ + 'code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customField', custom_field)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'code': 'test'}) + ) + + response = self.client.custom_field_edit(custom_field) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers(self): + """ + V5 Test method customers + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/customers') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[online]': 'No', 'filter[contragentType]': 'individual'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 4347, + 'currentPage': 1, + 'totalPageCount': 87 + }, + 'customers': [self.__customer] + } + ) + ) + + response = self.client.customers({'online': 'No', 'contragentType': 'individual'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_combine(self): + """ + V5 Test method customers_combine + """ + + customer = {'id': 5604} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers/combine') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.customers_combine(customer, customer) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_create(self): + """ + V5 Test method customers_create + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customer', self.__customer)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': 7117}) + ) + + response = self.client.customer_create(self.__customer) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_fix_external_ids(self): + """ + V5 Test method customers_fix_external_ids + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers/fix-external-ids') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customers', self.__customer['externalId'])) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.customers_fix_external_ids(self.__customer['externalId']) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_history(self): + """ + V5 Test method customers_history + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/customers/history') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params( + { + 'filter[sinceId]': '1111', + 'filter[startDate]': '2016-01-07', + 'filter[endDate]': '2020-04-12' + } + ) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'generatedAt': '2020-04-15 17:43:12', + 'history': [ + { + 'id': 7018, + 'createdAt': '2018-04-11 09:01:26', + 'created': 'true', + 'source': 'api', + 'field': 'id', + 'apiKey': { + 'current': 'false' + }, + 'oldValue': 'null', + 'newValue': 4949, + 'customer': { + 'id': 4949, + 'externalId': 'c456', + 'createdAt': '2018-04-11 09:01:26', + 'vip': 'false', + 'bad': 'false', + 'site': 'retailcrm-ru', + 'contragent': { + 'contragentType': 'individual' + }, + 'marginSumm': 0, + 'totalSumm': 0, + 'averageSumm': 0, + 'ordersCount': 0, + 'customFields': [], + 'personalDiscount': 0, + 'cumulativeDiscount': 0, + 'firstName': 'XXX', + 'lastName': 'XXX', + 'patronymic': 'XXX', + 'email': 'xxx@example.com' + } + } + ] + } + ) + ) + + response = self.client.customers_history( + { + 'sinceId': '1111', + 'startDate': '2016-01-07', + 'endDate': '2020-04-12' + } + ) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_notes(self): + """ + V5 Test method customers_notes + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/customers/notes') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[createdAtFrom]': '2020-04-18', 'filter[createdAtTo]': '2020-04-21'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 3, + 'currentPage': 1, + 'totalPageCount': 1 + }, + 'notes': [ + { + 'customer': { + 'site': 'retailcrm-ru', + 'id': 5604, + 'type': 'customer' + }, + 'id': 279, + 'text': 'test', + 'createdAt': '2020-04-20 13:02:35' + } + ] + } + ) + ) + + response = self.client.customer_notes({'createdAtFrom': '2020-04-18', 'createdAtTo': '2020-04-21'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_note_create(self): + """ + V5 Test method customer_note_create + """ + + note = {'managerId': 23, 'text': 'test', 'customer': {'id': 5604}} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers/notes/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('note', note)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 2222}) + ) + + response = self.client.customer_note_create(note) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_note_delete(self): + """ + V5 Test method customer_note_delete + """ + + uid = '279' + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers/notes/' + uid + '/delete') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.customer_note_delete(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_upload(self): + """ + V5 Test method customers_upload + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customers', self.__customer)) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'uploadedCustomers': [ + { + 'id': 9717, + 'externalId': 'c-983344770' + } + ] + } + ) + ) + + response = self.client.customers_upload(self.__customer) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer(self): + """ + V5 Test method customer + """ + + uid = str(self.__customer['externalId']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/customers/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'customers': self.__customer}) + ) + + response = self.client.customer(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_edit(self): + """ + V5 Test method customers_edit + """ + + uid = str(self.__customer['externalId']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customer', self.__customer)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 9717}) + ) + + response = self.client.customer_edit(self.__customer) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_corporate(self): + """ + V5 Test customers_corporate + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[vip]': 'false', 'filter[companyName]': 'Test'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 128, + 'currentPage': 1, + 'totalPageCount': 7 + }, + 'customersCorporate': [self.__customer_corporate] + } + ) + ) + + response = self.client.customers_corporate({'vip': 'false', 'companyName': 'Test'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_combine_corporate(self): + """ + V5 Test method customers_combine_corporate + """ + + customer = {'id': 5604} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/combine') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.customers_combine_corporate(customer, customer) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_create(self): + """ + V5 Test method customer_corporate_create + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customerCorporate', self.__customer_corporate)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': 7117}) + ) + + response = self.client.customer_corporate_create(self.__customer_corporate) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def customers_corporate_fix_external_ids(self): + """ + V5 Test method customers_corporate_fix_external_ids + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/fix-external-ids') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customerCorporate', self.__customer_corporate['externalId'])) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.customers_corporate_fix_external_ids(self.__customer_corporate['externalId']) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_history(self): + """ + V5 Test method customers_corporate_history + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/history') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params( + { + 'filter[sinceId]': '1111', + 'filter[startDate]': '2016-01-07', + 'filter[endDate]': '2020-04-12' + } + ) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'generatedAt': '2020-04-15 17:43:12', + 'history': [ + { + 'id': 1, + 'createdAt': '2019-10-14 14:57:21', + 'created': 'true', + 'source': 'user', + 'user': {'id': 15}, + 'field': 'id', + 'oldValue': 'null', + 'newValue': 7484, + 'customer': { + 'type': 'customer_corporate', + 'id': 7484, + 'nickName': 'Inventive', + 'createdAt': '2019-10-14 14:57:21', + 'managerId': 15, + 'vip': 'false', + 'bad': 'false', + 'site': 'samsung', + 'marginSumm': 0, + 'totalSumm': 0, + 'averageSumm': 0, + 'ordersCount': 0, + 'customFields': [], + 'personalDiscount': 0, + 'cumulativeDiscount': 0 + } + } + ] + } + ) + ) + + response = self.client.customers_corporate_history( + { + 'sinceId': '1111', + 'startDate': '2016-01-07', + 'endDate': '2020-04-12' + } + ) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_notes(self): + """ + V5 Test method customer_corporate_notes + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/notes') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[createdAtFrom]': '2020-04-18', 'filter[createdAtTo]': '2020-04-21'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 3, + 'currentPage': 1, + 'totalPageCount': 1 + }, + 'notes': [ + { + 'customer': { + 'site': 'retailcrm-ru', + 'id': 5604, + 'type': 'customer_corporate' + }, + 'id': 279, + 'text': 'test', + 'createdAt': '2020-04-29 13:02:35' + } + ] + } + ) + ) + + response = self.client.customer_corporate_notes({'createdAtFrom': '2020-04-18', 'createdAtTo': '2020-04-21'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_note_create(self): + """ + V5 Test method customer_corporate_note_create + """ + + note = {'managerId': 23, 'text': 'test', 'customer': {'id': 5604}} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/notes/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('note', note)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 2222}) + ) + + response = self.client.customer_corporate_note_create(note) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_note_delete(self): + """ + V5 Test method customer_corporate_note_delete + """ + + uid = '279' + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/notes/' + uid + '/delete') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.customer_corporate_note_delete(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customers_corporate_upload(self): + """ + V5 Test method customers_corporate_upload + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customersCorporate', self.__customer_corporate)) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'uploadedCustomers': [ + { + 'id': 9717, + 'externalId': 'c-983344770' + } + ] + } + ) + ) + + response = self.client.customers_corporate_upload(self.__customer_corporate) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate(self): + """ + V5 Test method customer_corporate + """ + + uid = str(self.__customer_corporate['externalId']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'customerCorporate': self.__customer_corporate}) + ) + + response = self.client.customer_corporate(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_addresses(self): + """ + V5 Test method customer_corporate_addresses + """ + + uid = str(self.__customer_corporate['externalId']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + uid + '/addresses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params(uid) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'addresses': [{ + 'id': 3995, + 'text': '123123, Russian Federation, Moscow, Kutuzovski 14', + 'isMain': 'true', + 'name': 'Test' + }], + 'pagination': { + 'limit': 20, + 'totalCount': 1, + 'currentPage': 1, + 'totalPageCount': 1 + } + } + ) + ) + + response = self.client.customer_corporate_addresses(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_addresses_create(self): + """ + V5 Test method customer_corporate_addresses_create + """ + + address = {'isMain': 'true', 'name': 'Test', 'externalId': 'cc_9'} + + (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}) + ) + + response = self.client.customer_corporate_addresses_create(address) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_addresses_edit(self): + """ + V5 Test method customer_corporate_addresses_edit + """ + + uid = str(self.__customer_corporate['externalId']) + address = {'isMain': 'true', 'name': 'Test', 'externalId': 'ccc8'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + uid + '/addresses/' + address[ + 'externalId'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('address', address)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': '7777'}) + ) + + response = self.client.customer_corporate_addresses_edit(uid, address) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_companies(self): + """ + V5 Test method customer_corporate_companies + """ + + uid = str(self.__customer_corporate['externalId']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + uid + '/companies') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params(uid) + .reply(200) + .headers(self.__header) + .json( + { + "success": 'true', + "companies": [ + { + "isMain": 'true', + "id": 31, + "customer": { + "site": "test", + "id": 9084, + "externalId": "cc_9", + "type": "customer_corporate" + }, + "active": 'true', + "name": "Test", + "createdAt": "2020-02-14 16:49:21", + "contragent": { + "contragentType": "legal-entity" + }, + "marginSumm": 0, + "totalSumm": 0, + "averageSumm": 0, + "ordersCount": 0, + "costSumm": 0, + "customFields": [] + } + ], + "pagination": { + "limit": 20, + "totalCount": 1, + "currentPage": 1, + "totalPageCount": 1 + } + } + ) + ) + + response = self.client.customer_corporate_companies(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_companies_create(self): + """ + V5 Test method customer_corporate_companies_create + """ + + company = {'isMain': 'true', 'name': 'TestN', 'externalId': 'cc_9'} + + (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) + .headers(self.__header) + .json({'success': 'true', 'id': 9717}) + ) + + response = self.client.customer_corporate_companies_create(company) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_companies_edit(self): + """ + V5 Test method customer_corporate_companies_edit + """ + + uid = str(self.__customer_corporate['externalId']) + company = {'isMain': 'true', 'name': 'TestN', 'externalId': 'ccc9'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + uid + '/companies/' + company[ + 'externalId'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('company', company)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 7777}) + ) + + response = self.client.customer_corporate_companies_edit(uid, company) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_contacts(self): + """ + V5 Test method customer_corporate_contacts + """ + + uid = str(self.__customer_corporate['externalId']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + uid + '/contacts') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params(uid) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'contacts': [ + { + 'isMain': 'true', + 'id': 33, + 'customer': { + 'id': 9083, + 'externalId': '9', + 'site': 'opencart' + }, + 'companies': [] + } + ], + 'pagination': { + 'limit': 20, + 'totalCount': 1, + 'currentPage': 1, + 'totalPageCount': 1 + } + } + ) + ) + + response = self.client.customer_corporate_contacts(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_contacts_create(self): + """ + V5 Test method customer_corporate_contacts_create + """ + + contact = {'isMain': 'true', 'name': 'TestM', 'externalId': 'cc_9'} + + (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) + .headers(self.__header) + .json({'success': 'true', 'id': 9717}) + ) + + response = self.client.customer_corporate_contacts_create(contact) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_contacts_edit(self): + """ + V5 Test method customer_corporate_contacts_edit + """ + + uid = str(self.__customer_corporate['externalId']) + contact = {'isMain': 'true', 'name': 'TestM', 'externalId': 'cc_10'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + uid + '/contacts/' + contact[ + 'externalId'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('contact', contact)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': '7777'}) + ) + + response = self.client.customer_corporate_contacts_edit(uid, contact) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_customer_corporate_edit(self): + """ + V5 Test method customer_corporate_edit + """ + + uid = str(self.__customer_corporate['externalId']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/customers-corporate/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('customersCorporate', self.__customer_corporate)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': '9717'}) + ) + + response = self.client.customer_corporate_edit(self.__customer_corporate) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_tracking(self): + """ + V5 Test method delivery_tracking + """ + + code = 'zzz' + delivery_id = { + 'deliveryId': '777z', + 'history': [ + { + 'code': '888', + 'updatedAt': '2020-04-12', + 'comment': 'Good' } ] } - response = self.client.order_create(order) + (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)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) - response_data = response.get_response() - payment_id = response_data['order']['payments'][0]['id'] - print(payment_id) + response = self.client.delivery_tracking(code, delivery_id) + pook.off() self.assertTrue(response.is_successful(), True) self.assertTrue(response.get_status_code() < 400, True) - payment_response = self.client.order_payment_edit({'externalId': ex_id, 'status': 'invoice'}, 'externalId') + @pook.on + def test_delivery_shipments(self): + """ + V5 Test delivery_shipments + """ - self.assertTrue(payment_response.is_successful(), True) - self.assertTrue(payment_response.get_status_code() < 400, True) + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/delivery/shipments') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[stores]': 'test'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 1, + 'currentPage': 1, + 'totalPageCount': 1 + }, + 'deliveryShipments': [ + { + 'integrationCode': 'xxx', + 'id': 1, + 'externalId': '10471460', + 'deliveryType': 'osj97', + 'store': 'test', + 'managerId': 23, + 'status': 'processing', + 'date': '2020-03-31', + 'time': { + 'from': '13:00', + 'to': '18:00' + }, + 'orders': [ + { + 'id': 5596, + 'number': '5596C' + } + ], + 'extraData': [] + } + ] + } + ) + ) - payment_response = self.client.order_payment_edit({'id': payment_id, 'status': 'paid'}) + response = self.client.delivery_shipments({'stores': 'test'}) + pook.off() - self.assertTrue(payment_response.is_successful(), True) - self.assertTrue(payment_response.get_status_code() < 400, True) + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_shipment_create(self): + """ + V5 Test method delivery_shipment_create + """ + + delivery_shipment = {'status': 'cancelled', 'store': 'test'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/delivery/shipments/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('deliveryShipment', delivery_shipment)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 5555, 'status': 'cancelled'}) + ) + + response = self.client.delivery_shipment_create(delivery_shipment) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_shipment(self): + """ + V5 Test method delivery_shipment + """ + + uid = '10471460' + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/delivery/shipments/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'deliveryShipments': + { + 'integrationCode': 'xxx', + 'id': 1, + 'externalId': '10471460', + 'deliveryType': 'osj97', + 'store': 'test', + 'managerId': 23, + 'status': 'processing', + 'date': '2020-03-31', + 'time': { + 'from': '13:00', + 'to': '18:00' + }, + 'orders': [ + { + 'id': 5596, + 'number': '5596C' + } + ], + 'extraData': [] + } + } + ) + ) + + response = self.client.delivery_shipment(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_shipment_edit(self): + """ + V5 Test method delivery_shipment_edit + """ + + delivery_shipment = { + 'integrationCode': 'xxx', + 'id': 1, + 'externalId': '10471460', + 'deliveryType': 'osj97', + 'store': 'test', + 'managerId': 23, + 'status': 'processing', + 'date': '2020-03-31', + 'time': { + 'from': '13:00', + 'to': '18:00' + }, + 'orders': [ + { + 'id': 5596, + 'number': '5596C' + } + ], + 'extraData': [] + } + uid = delivery_shipment['id'] + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/delivery/shipment/' + str(uid) + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('deliveryShipment', delivery_shipment)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 5555, 'status': 'cancelled'}) + ) + + response = self.client.delivery_shipment_edit(delivery_shipment) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_files(self): + """ + V5 Test method files + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/files') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[sizeFrom]': '1'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 1, + 'currentPage': 1, + 'totalPageCount': 1 + }, + 'files': [self.__file] + } + ) + ) + + response = self.client.files({'sizeFrom': '1'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_files_upload(self): + """ + V5 Test method files_upload + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/files/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('file', self.__file)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'file': {'id': 92}}) + ) + + response = self.client.files_upload(self.__file) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_file(self): + """ + V5 Test method file + """ + + uid = str(self.__file['id']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/files/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'file': self.__file}) + ) + + response = self.client.file(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_files_delete(self): + """ + V5 Test method files_delete + """ + + uid = '7777' + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/files/' + uid + '/delete') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.files_delete(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_files_download(self): + """ + V5 Test method files_download + """ + + uid = '7777' + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/files/' + uid + '/download') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params(uid) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.files_download(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_files_edit(self): + """ + V5 Test method files_edit + """ + + uid = '30' + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/files/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('file', self.__file)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.files_edit(self.__file) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_integration_module(self): + """ + V5 Test method integration_module + """ + + code = 'xxx' + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/integration-modules/' + code) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params(code) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': '20', + 'totalCount': '4347', + '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' + } + ] + } + } + } + } + } + ) + ) + + response = self.client.integration_module(code) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_integration_module_edit(self): + """ + V5 Test method integration_module_edit + """ + + integration_module = {'code': 'xxx', 'integrationCode': 'xxx'} + uid = 'xxx' + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/integration-modules/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('integrationModule', integration_module)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.integration_module_edit(integration_module) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders(self): + """ + V5 Test method orders + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/orders') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[city]': 'Moscow', 'filter[contragentType]': 'individual'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 2464, + 'currentPage': 1, + 'totalPageCount': 50 + }, + 'orders': [self.__order] + } + ) + ) + + response = self.client.orders({'city': 'Moscow', 'contragentType': 'individual'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_combine(self): + """ + V5 Test method orders_combine + """ + + order = {'id': 5604} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/orders/combine') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.orders_combine(order, order, 'merge') + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_create(self): + """ + V5 Test method orders_create + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/orders/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('order', self.__order)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': 8888, 'order': self.__order}) + ) + + response = self.client.order_create(self.__order) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_fix_external_ids(self): + """ + V5 Test method orders_fix_external_ids + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/orders/fix-external-ids') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('orders', self.__order['externalId'])) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.orders_fix_external_ids(self.__order['externalId']) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_history(self): + """ + V5 Test method orders_history + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/orders/history') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params( + { + 'filter[sinceId]': '1111', + 'filter[startDate]': '2016-01-07', + 'filter[endDate]': '2020-04-12' + } + ) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'generatedAt': '2020-04-16 11:03:00', + 'history': [ + { + 'id': 7887, + 'createdAt': '2018-04-11 09:01:29', + 'created': 'true', + 'source': 'api', + 'field': 'status', + 'apiKey': { + 'current': 'false' + }, + 'oldValue': 'null', + 'newValue': { + 'code': 'new' + }, + 'order': { + 'slug': 9090, + 'summ': 0, + 'id': 9090, + 'number': '9090A', + 'externalId': 'v4321', + 'orderType': 'eshop-individual', + 'orderMethod': 'shopping-cart', + 'createdAt': '2018-04-11 09:01:29', + 'statusUpdatedAt': '2018-04-11 09:01:29', + 'totalSumm': 0, + 'prepaySum': 0, + 'purchaseSumm': 0, + 'markDatetime': '2018-04-11 09:01:29', + 'lastName': 'xxxx', + 'firstName': 'xxxx', + 'patronymic': 'xxxx', + 'email': 'maymayslt@example.com', + 'call': 'false', + 'expired': 'false', + 'customer': { + 'id': 5544, + 'isContact': 'false', + 'createdAt': '2018-04-11 09:01:29', + 'vip': 'false', + 'bad': 'false', + 'site': 'retailcrm-ru', + 'contragent': { + 'contragentType': 'individual' + }, + 'marginSumm': 0, + 'totalSumm': 0, + 'averageSumm': 0, + 'ordersCount': 1, + 'customFields': [], + 'personalDiscount': 0, + 'cumulativeDiscount': 0, + 'address': { + 'id': 3322 + }, + 'lastName': 'xxxx', + 'firstName': 'xxxx', + 'patronymic': 'xxxx', + 'email': 'maymays@example.com', + 'phones': [] + }, + 'contragent': { + 'contragentType': 'individual' + }, + 'delivery': { + 'cost': 0, + 'netCost': 0, + 'address': { + 'id': 2477, + 'countryIso': '' + } + }, + 'site': 'retailcrm-ru', + 'status': 'new', + 'items': [], + 'fromApi': 'true', + 'shipped': 'false', + 'customFields': [] + } + } + ] + } + ) + ) + + response = self.client.orders_history( + { + 'sinceId': '1111', + 'startDate': '2016-01-07', + 'endDate': '2020-04-12' + } + ) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_statuses(self): + """ + V5 Test method orders_statuses + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/orders/statuses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'ids[]': '5604', 'externalIds[]': '5603'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'orders': [ + { + 'id': '5604', + 'externalId': '5603', + 'status': 'new', + 'group': 'new' + } + ] + } + ) + ) + + response = self.client.orders_statuses([5604], [5603]) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_upload(self): + """ + V5 Test method orders_upload + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/orders/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('orders', self.__order)) + .reply(201) + .headers(self.__header) + .json( + { + 'success': 'true', + 'uploadedOrders': [ + { + 'id': 5604, + 'externalId': '5603' + } + ], + 'orders': [self.__order] + } + ) + ) + + response = self.client.orders_upload(self.__order) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order(self): + """ + V5 Test method order + """ + + uid = str(self.__order['externalId']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/orders/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'orders': self.__order}) + ) + + response = self.client.order(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_links_create(self): + """ + V5 Test method order_links_create + """ + + link = { + "comment": "test", + "orders": [ + { + "id": 5604, + "externalId": 5603, + "number": 1 + }, + { + "id": 5605, + "externalId": 5601, + "number": 1 + } + ] + } + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/orders/links/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('link', link)) + .reply(201) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.order_links_create(link) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_payment_create(self): + """ + V5 Test method payment_create + """ + + payment = {'order': {'externalId': '5603'}, 'type': 'bank-card'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/orders/payments/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('payment', payment)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': 7777}) + ) + + response = self.client.order_payment_create(payment) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_payment_delete(self): + """ + V5 Test method order_payment_delete + """ + + uid = '7777' + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/orders/payments/' + uid + '/delete') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.order_payment_delete(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_payment_edit(self): + """ + V5 Test method order_payment_edit + """ + + payment = { + 'externalId': '5603', + 'order': [ + { + 'id': 5604, + 'externalId': '5603', + 'number': 1 + } + ], + 'type': 'bank-card' + } + uid = str(self.__order['externalId']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/orders/payments/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('payment', payment)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'payment': payment}) + ) + + response = self.client.order_payment_edit(payment) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_statuses(self): + """ + V5 Test method orders_statuses + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/orders/statuses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'ids[]': '5604', 'externalIds[]': '5603'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'orders': [ + { + 'id': 5604, + 'externalId': '5603', + 'status': 'new', + 'group': 'new' + } + ] + } + ) + ) + + response = self.client.orders_statuses([5604], [5603]) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_upload(self): + """ + V5 Test method orders_upload + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/orders/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('orders', self.__order)) + .reply(201) + .headers(self.__header) + .json( + { + 'success': 'true', + 'uploadedOrders': [ + { + 'id': 5604, + 'externalId': '5603' + } + ], + 'orders': [self.__order] + } + ) + ) + + response = self.client.orders_upload(self.__order) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order(self): + """ + V5 Test method order + """ + + uid = str(self.__order['externalId']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/orders/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'orders': self.__order}) + ) + + response = self.client.order(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_orders_edit(self): + """ + V5 Test method orders_edit + """ + + uid = str(self.__order['externalId']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/orders/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('order', self.__order)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 5604, 'order': self.__order}) + ) + + response = self.client.order_edit(self.__order) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_packs(self): + """ + V5 Test method packs + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/orders/packs') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[store]': '7777z'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 1, + 'currentPage': 1, + 'totalPageCount': 1 + }, + 'packs': [self.__pack] + } + ) + ) + + response = self.client.packs({'store': '7777z'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_packs_create(self): + """ + V5 Test method packs_create + """ + + packs_create = {'store': '7777z', 'quantity': 1, 'itemId': 7632} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/orders/packs/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('pack', packs_create)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': 7777}) + ) + + response = self.client.pack_create(packs_create) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_packs_history(self): + """ + V5 Test method packs_history + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/orders/packs/history') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[startDate]': '2016-01-07', 'filter[endDate]': '2020-04-12'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'generatedAt': '2020-04-17 13:08:48', + 'history': [ + { + 'id': 777, + 'createdAt': '2018-04-13 15:46:06', + 'created': 'true', + 'field': 'store', + 'newValue': { + 'code': 'zzz' + }, + 'pack': { + 'id': 678, + 'quantity': 1, + 'store': {'code': 'zzz'}, + 'item': { + 'id': 222, + 'order': {'id': 6677}, + 'offer': {'externalId': '333'} + } + }, + 'source': 'api' + } + ] + } + ) + ) + + response = self.client.packs_history({'startDate': '2016-01-07', 'endDate': '2020-04-12'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_pack(self): + """ + V5 Test method pack + """ + + uid = str(self.__pack['id']) + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/orders/packs/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'pack': self.__pack}) + ) + + response = self.client.pack(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_packs_delete(self): + """ + V5 Test method packs_delete + """ + + uid = '7777' + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/orders/packs/' + uid + '/delete') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.pack_delete(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_pack_edit(self): + """ + V5 Test method pack_edit + """ + + uid = str(self.__pack['id']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/orders/packs/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('pack', self.__pack)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': 5604}) + ) + + response = self.client.pack_edit(self.__pack) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_check(self): + """ + V5 Test method payment_check + """ + + check = {'invoiceUuid': '577', 'amount': 1, 'currency': 'RU'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/payment/check') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('check', check)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'result': {'success': 'true'}}) + ) + + response = self.client.payment_check(check) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_create_invoice(self): + """ + V5 Test method payment_create_invoice + """ + + create_invoice = {'paymentId': 578, 'returnUrl': 'https://test.ru'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/payment/create-invoice') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('createInvoice', create_invoice)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'result': {'link': 'https://test.ru'}}) + ) + + response = self.client.payment_create_invoice(create_invoice) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_update_invoice(self): + """ + V5 Test method payment_update_invoice + """ + + update_invoice = {'invoiceUuid': '577', 'paymentId': '5304'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/payment/update-invoice') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('updateInvoice', update_invoice)) + .reply(201) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.payment_update_invoice(update_invoice) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_cost_groups(self): + """ + V5 Test method cost_groups + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/cost-groups') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'costGroups': [ + { + 'code': 'cost-gr-example', + 'name': 'CostGroup-example', + 'ordering': 990, + 'active': 'true', + 'color': '#da5c98' + }, + { + 'code': 'cost-gr-lst7', + 'name': 'CostGroup-lst7', + 'ordering': 990, + 'active': 'true', + 'color': '#da5c98' + } + ] + } + ) + ) + + response = self.client.cost_groups() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_cost_groups_edit(self): + """ + V5 Test method cost_groups_edit + """ + + group = {'code': 'cost-gr-example', 'color': '#da5c98', 'ordering': 990, 'name': 'CostGroup-lst7'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/cost-groups/' + group['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('costGroup', group)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.cost_groups_edit(group) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_cost_items(self): + """ + V5 Test method cost_items + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/cost-items') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'costItems': [ + { + 'code': 'cost-it-example', + 'name': 'CostItem-example', + 'group': 'cost-gr-example', + 'ordering': 990, + 'active': 'true', + 'appliesToOrders': 'true', + 'type': 'const', + 'appliesToUsers': 'false' + }, + { + 'code': 'cost-it-1', + 'name': 'CostItem-1', + 'group': 'cost-gr-1', + 'ordering': 990, + 'active': 'true', + 'appliesToOrders': 'true', + 'type': 'const', + 'appliesToUsers': 'false' + } + ] + } + ) + ) + + response = self.client.cost_items() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_cost_items_edit(self): + """ + V5 Test method cost_items_edit + """ + + item = {'code': 'cost-it-example', 'name': 'CostItem-example', 'ordering': 990, 'active': 'true'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/cost-groups/' + item['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('costItem', item)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.cost_items_edit(item) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_countries(self): + """ + V5 Test method countries + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/countries') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'countriesIso': ['RU', 'UA', 'BY', 'KZ']}) + ) + + response = self.client.countries() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_couriers(self): + """ + V5 Test method couriers + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/couriers') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'couriers': [ + { + 'id': 55, + 'firstName': 'Jean', + 'lastName': 'Doe', + 'patronymic': 'M.', + 'active': 'true', + 'email': 'r9z4o@example.com' + }, + { + 'id': 57, + 'firstName': 'John', + 'lastName': 'Doe', + 'patronymic': 'H.', + 'active': 'true', + 'email': 'oflf9@example.com' + } + ] + } + ) + ) + + response = self.client.couriers() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_couriers_create(self): + """ + V5 Test method couriers_create + """ + + courier = { + 'id': 55, + 'firstName': 'John', + 'lastName': 'Doe', + 'patronymic': 'H.', + 'active': 'true', + 'email': 'r9z4o@example.com' + } + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/couriers/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('courier', courier)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': '8888'}) + ) + + response = self.client.couriers_create(courier) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_couriers_edit(self): + """ + V5 Test method couriers_edit + """ + + courier = { + 'id': 55, + 'firstName': 'John', + 'lastName': 'Doe', + 'patronymic': 'H.', + 'active': 'true', + 'email': 'r9z4o@example.com' + } + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/couriers/' + str(courier['id']) + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('courier', courier)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.couriers_edit(courier) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_services(self): + """ + V5 Test method delivery_services + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/delivery-services') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'deliveryServices': { + 'hp5kc': { + 'name': '8305u', + 'code': 'hp5kc', + 'active': 'true' + }, + 'hmo8s': { + 'name': 'k1233', + 'code': 'hmo8s', + 'active': 'true' + } + } + } + ) + ) + + response = self.client.delivery_services() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_services_edit(self): + """ + V5 Test method delivery_services_edit + """ + + service = {'code': 'hmo8s', 'name': 'x345'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/delivery-services/' + service['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('deliveryService', service)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.delivery_services_edit(service) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_types(self): + """ + V5 Test method delivery_types + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/delivery-types') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(201) + .headers(self.__header) + .json( + { + 'success': 'true', + 'deliveryTypes': { + '1kp52': { + 'name': 'c435', + 'code': 'd345', + 'defaultCost': 300, + 'defaultNetCost': 0, + 'paymentTypes': [ + 'cash', + 'bank-card' + ], + 'deliveryServices': [], + 'defaultForCrm': 'false' + }, + 'example-code': { + 'name': '1s0ei', + 'code': 'example-code', + 'defaultCost': 300, + 'defaultNetCost': 0, + 'paymentTypes': [ + 'cash', + 'bank-card' + ], + 'deliveryServices': [], + 'defaultForCrm': 'false' + } + } + } + ) + ) + + response = self.client.delivery_types() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_delivery_types_edit(self): + """ + V5 Test method delivery_types_edit + """ + + delivery_type = {'code': 'example-code', 'name': '1s0ei'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/delivery-types/' + delivery_type['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('deliveryType', delivery_type)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.delivery_types_edit(delivery_type) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_legal_entities(self): + """ + V5 Test method legal_entities + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/legal-entities') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'legalEntities': [ + { + 'contragentType': 'legal-entity', + 'legalName': 'Test LegalEntity-0aca34', + 'code': '0aca34', + 'countryIso': 'RU' + }, + { + 'contragentType': 'legal-entity', + 'legalName': 'Test LegalEntity-2e8913', + 'code': '2e8913', + 'countryIso': 'RU' + } + ] + } + ) + ) + + response = self.client.legal_entities() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_legal_entities_edit(self): + """ + V5 Test method legal_entities_edit + """ + + legal = { + 'contragentType': 'legal-entity', + 'legalName': 'Test LegalEntity-0aca34', + 'code': '0aca34', + 'countryIso': 'RU' + } + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/legal-entities/' + legal['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('legalEntity', legal)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.legal_entities_edit(legal) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_mg_channels(self): + """ + V5 Test method mg_channels + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/mg-channels') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'mgChannels': [ + { + 'id': 1, + 'externalId': 1, + 'type': 'telegram', + 'active': 'false' + }, + { + 'id': 2, + 'externalId': 268, + 'type': 'telegram', + 'active': 'false' + } + ] + } + ) + ) + + response = self.client.mg_channels() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_methods(self): + """ + V5 Test method order_methods + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/order-methods') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'orderMethods': { + '44cmd': { + 'name': '1tdf4', + 'code': '44cmd', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'isFromPos': 'false' + }, + 'zoc5q': { + 'name': '1y0cp', + 'code': 'zoc5q', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'isFromPos': 'false' + } + } + } + ) + ) + + response = self.client.order_methods() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_methods_edit(self): + """ + V5 Test method order_methods_edit + """ + + method = {'code': 'zoc5q', 'name': '1y0cp'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/order-methods/' + method['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('orderMethod', method)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.order_methods_edit(method) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_types(self): + """ + V5 Test method order_types + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/order-types') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'orderTypes': { + 'example-code': { + 'name': 'test', + 'code': 'example-code', + 'defaultForCrm': 'true', + 'defaultForApi': 'true', + 'ordering': 990 + }, + 'b7e20': { + 'name': 'vwt5f', + 'code': 'b7e20', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'ordering': 990 + } + } + } + ) + ) + + response = self.client.order_types() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_order_types_edit(self): + """ + V5 Test method order_types_edit + """ + + order_type = {'code': 'example-code', 'name': 'test'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/order-types/' + order_type['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('orderType', order_type)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.order_types_edit(order_type) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_statuses(self): + """ + V5 Test method payment_statuses + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/payment-statuses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'paymentStatuses': { + 'invoice': { + 'name': 'Выставлен счет', + 'code': 'invoice', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'paymentComplete': 'false', + 'ordering': 20, + 'paymentTypes': [ + 'bank-card', + 'bank-transfer', + 'credit', + 'cash', + 'e-money' + ] + }, + 'payment-start': { + 'name': 'Платеж проведен', + 'code': 'payment-start', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'paymentComplete': 'false', + 'ordering': 30, + 'paymentTypes': [ + 'bank-card', + 'bank-transfer', + 'credit', + 'cash', + 'e-money' + ] + } + } + } + ) + ) + + response = self.client.payment_statuses() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_statuses_edit(self): + """ + V5 Test method payment_statuses_edit + """ + + status = {'code': 'payment-start', 'name': 'Платеж проведен'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/payment-statuses/' + status['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('paymentStatus', status)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.payment_statuses_edit(status) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_types(self): + """ + V5 Test method payment_types + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/payment-types') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'paymentTypes': { + '056a3e': { + 'name': 'TestPaymentType-056a3e', + 'code': '056a3e', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'deliveryTypes': [], + 'paymentStatuses': [] + }, + '238c06': { + 'name': 'TestPaymentType-238c06', + 'code': '238c06', + 'defaultForCrm': 'false', + 'defaultForApi': 'false', + 'deliveryTypes': [], + 'paymentStatuses': [] + } + } + } + ) + ) + + response = self.client.payment_types() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_payment_types_edit(self): + """ + V5 Test method payment_types_edit + """ + + payment_type = {'code': '238c06', 'name': 'TestPaymentType-238c06'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/payment-types/' + payment_type['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('paymentType', payment_type)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.payment_types_edit(payment_type) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_price_types(self): + """ + V5 Test method price_types + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/price-types') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'priceTypes': [ + { + 'id': 174, + 'code': 'sample_v5_price_code', + 'name': 'Sample v5 price type', + 'active': 'true', + 'default': 'false', + 'geo': [], + 'groups': [], + 'ordering': 500 + }, + { + 'id': 170, + 'code': 'l6u5c', + 'name': 's50sa', + 'active': 'false', + 'default': 'false', + 'geo': [], + 'groups': [], + 'ordering': 990 + } + ] + } + ) + ) + + response = self.client.price_types() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_price_types_edit(self): + """ + V5 Test method price_types_edit + """ + + price_type = { + 'id': 174, + 'code': 'sample_v5_price_code', + 'name': 'Sample v5 price type', + 'active': 'true', + 'default': 'false', + 'geo': [], + 'groups': [], + 'ordering': 500 + } + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/price-types/' + price_type['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('priceTypes', price_type)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.price_types_edit(price_type) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_product_statuses(self): + """ + V5 Test method product_statuses + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/product-statuses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'productStatuses': { + 'confirming': { + 'code': 'confirming', + 'ordering': 20, + 'createdAt': '2018-04-10 12:33:58', + 'cancelStatus': 'false', + 'name': 'Подтверждение наличия' + }, + 'in-reserve': { + 'code': 'in-reserve', + 'ordering': 30, + 'createdAt': '2018-04-10 12:33:58', + 'cancelStatus': 'false', + 'name': 'В резерве' + } + } + } + ) + ) + + response = self.client.product_statuses() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_product_statuses_edit(self): + """ + V5 Test method product_statuses_edit + """ + + status = {'code': 'in-reserve', 'name': 'В резерве'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/product-statuses/' + status['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('productStatus', status)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.product_statuses_edit(status) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_sites(self): + """ + V5 Test method sites + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/sites') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'sites': { + 'sites': { + 'name': 'XXX', + 'url': 'http://url', + 'code': 'code', + 'defaultForCrm': 'false', + 'ymlUrl': 'http://url', + 'loadFromYml': 'true', + 'catalogUpdatedAt': '2020-04-03 13:56:26', + 'catalogLoadingAt': '2020-04-13 08:50:55', + 'countryIso': 'RU' + } + } + } + ) + ) + + response = self.client.sites() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_sites_edit(self): + """ + V5 Test method sites_edit + """ + + site = {'code': 'code', 'name': 'XXX'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/sites/' + site['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('site', site)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.sites_edit(site) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_status_groups(self): + """ + V5 Test method status_groups + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/status-groups') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'statusGroups': { + 'new': { + 'name': 'Новый', + 'code': 'new', + 'ordering': 10, + 'process': 'false', + 'statuses': [ + 'new', + 'rake-status' + ] + }, + 'approval': { + 'name': 'Согласование', + 'code': 'approval', + 'ordering': 20, + 'process': 'true', + 'statuses': [ + 'availability-confirmed', + 'offer-analog', + 'client-confirmed', + 'prepayed' + ] + } + } + } + ) + ) + + response = self.client.status_groups() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_statuses(self): + """ + V5 Test method statuses + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/statuses') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'statuses': { + 'new': { + 'name': 'Новый', + 'code': 'new', + 'ordering': 10, + 'group': 'new' + }, + 'rake-status': { + 'name': 'Rake status', + 'code': 'rake-status', + 'ordering': 990, + 'group': 'new' + } + } + } + ) + ) + + response = self.client.statuses() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_statuses_edit(self): + """ + V5 Test method statuses_edit + """ + + status = {'code': 'new', 'name': 'Новый'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/statuses/' + status['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('status', status)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.statuses_edit(status) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_stores(self): + """ + V5 Test method stores + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/stores') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'stores': [ + { + 'type': 'store-type-warehouse', + 'inventoryType': 'integer', + 'code': 'lca46', + 'name': 'new' + }, + { + 'type': 'store-type-warehouse', + 'inventoryType': 'integer', + 'code': 'q6w5i', + 'name': 's344' + } + ] + } + ) + ) + + response = self.client.stores() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_stores_edit(self): + """ + V5 Test method stores_edit + """ + + store = {'code': 'q6w5i', 'name': 's234f'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/stores/' + store['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('store', store)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.stores_edit(store) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_units(self): + """ + V5 Test method units + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/reference/units') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'units': { + 'pc': { + 'code': 'pc', + 'name': 'Штука', + 'sym': 'шт.', + 'default': 'true', + 'active': 'true' + }, + 'kg': { + 'code': 'kg', + 'name': 'Килограмм', + 'sym': 'кг', + 'default': 'false', + 'active': 'true' + } + } + } + ) + ) + + response = self.client.units() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_units_edit(self): + """ + V5 Test method units_edit + """ + + units = { + 'code': 'pc', + 'name': 'Штука', + 'sym': 'шт.', + 'default': 'true', + 'active': 'true' + } + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/reference/units/' + units['code'] + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('units', units)) + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.units_edit(units) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_segments(self): + """ + V5 Test method segments + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/segments') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[active]': 'true'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'segments': [ + { + 'id': 34, + 'code': 'no-sex', + 'name': 'Пол не указан', + 'createdAt': '2018-04-10 12:34:30', + 'isDynamic': 'true', + 'customersCount': 1290, + 'active': 'true' + }, + { + 'id': 33, + 'code': 'women', + 'name': 'Women', + 'createdAt': '2018-04-10 12:34:30', + 'isDynamic': 'true', + 'customersCount': 0, + 'active': 'true' + } + ] + } + ) + ) + + response = self.client.segments({'active': 'true'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_inventories(self): + """ + V5 Test method inventories + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/store/inventories') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[site]': 'https://retailcrm.ru'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 621, + 'currentPage': 1, + 'totalPageCount': 32 + }, + 'offers': [ + { + 'id': 33937, + 'externalId': '89387', + 'site': 'https://retailcrm.ru', + 'quantity': 102 + }, + { + 'id': 33933, + 'externalId': '46', + 'site': 'https://retailcrm.ru', + 'quantity': 0 + } + ] + } + ) + ) + + response = self.client.inventories({'site': 'https://retailcrm.ru'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_inventories_upload(self): + """ + V5 Test method inventories_upload + """ + + offer = {'externalId': '89387', 'id': 33937} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/store/inventories/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('offers', offer)) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'processedOffersCount': 0, + 'notFoundOffers': { + 'externalId': '89387', + 'id': 33937, + 'xmlId': 9999 + } + } + ) + ) + + response = self.client.inventories_upload(offer) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_prices_upload(self): + """ + V5 Test method prices_upload + """ + + price = [{'price': 999, 'externalId': '89387'}] + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/store/prices/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('prices', price)) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'processedOffersCount': 0, + 'notFoundOffers': [ + { + 'externalId': 'x2342' + } + ] + } + ) + ) + + response = self.client.prices_upload(price) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_product_groups(self): + """ + V5 Test method product_groups + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/store/product-groups') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[active]': 'true'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 115, + 'currentPage': 1, + 'totalPageCount': 6 + }, + 'productGroup': [ + { + 'site': '127-0-0-1-8080', + 'id': 2171, + 'name': 'Cameras', + 'externalId': '33', + 'active': 'true' + }, + { + 'site': 'localhost-8080', + 'id': 2133, + 'name': 'Cameras', + 'externalId': '33', + 'active': 'true' + } + ] + } + ) + ) + + response = self.client.product_groups({'active': 'true'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_products(self): + """ + V5 Test method products + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/store/products') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[active]': 'true'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 558, + 'currentPage': 1, + 'totalPageCount': 28 + }, + 'products': [ + { + 'minPrice': 100, + 'maxPrice': 100, + 'id': 25804, + 'name': 'sds', + 'groups': [ + { + 'id': 2171, + 'externalId': '33' + } + ], + 'manufacturer': 'asdas', + 'offers': [ + { + 'name': 'example', + 'price': 100, + 'images': [], + 'id': 33937, + 'externalId': '89387', + 'article': 'x3421', + 'prices': [ + { + 'priceType': 'base', + 'price': 100, + 'ordering': 991 + } + ], + 'weight': 44, + 'length': 324, + 'width': 33, + 'height': 432, + 'unit': { + 'code': 'pc', + 'name': 'Штука', + 'sym': 'шт.' + } + } + ], + 'active': 'true', + 'quantity': 102, + 'markable': 'false' + } + ] + } + ) + ) + + response = self.client.products({'active': 'true'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_products_properties(self): + """ + V5 Test method products_properties + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/store/products/properties') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[active]': 'true'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 24, + 'currentPage': 1, + 'totalPageCount': 2 + }, + 'properties': [ + { + 'sites': [ + 'samsung' + ], + 'code': 'type', + 'name': 'Тип' + }, + { + 'sites': [ + 'samsung' + ], + 'code': 'vendor_country', + 'name': 'Страна производителя' + }, + { + 'sites': [ + 'samsung' + ], + 'code': 'vendor_address', + 'name': 'Юр. адрес производителя' + }, + { + 'sites': [ + 'samsung' + ], + 'code': 'color', + 'name': 'color' + } + ] + } + ) + ) + + response = self.client.products_properties({'active': 'true'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + + @pook.on + def test_tasks(self): + """ + V5 Test method tasks + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/tasks') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[performers]': '15'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 139, + 'currentPage': 1, + 'totalPageCount': 7 + }, + 'tasks': [ + { + 'id': 433, + 'text': 'test task edited', + 'commentary': 'test commentary', + 'datetime': '2020-02-20 05:01', + 'createdAt': '2020-02-20 01:01:28', + 'complete': 'false', + 'performer': 15, + 'performerType': 'user' + }, + { + 'id': 432, + 'text': 'test task edited', + 'commentary': 'test commentary', + 'datetime': '2020-02-20 05:00', + 'createdAt': '2020-02-20 01:00:07', + 'complete': 'false', + 'performer': 15, + 'performerType': 'user' + } + ] + } + ) + ) + + response = self.client.tasks({'performers': '15'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + + @pook.on + def test_task_create(self): + """ + V5 Test method task_create + """ + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/tasks/create') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('task', self.__task)) + .reply(201) + .headers(self.__header) + .json({'success': 'true', 'id': 434}) + ) + + response = self.client.task_create(self.__task) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_task(self): + """ + V5 Test method task + """ + + uid = str(self.__task['id']) + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/tasks/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'task': self.__task}) + ) + + response = self.client.task(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_task_edit(self): + """ + V5 Test method task_edit + """ + + uid = str(self.__task['id']) + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/tasks/' + uid + '/edit') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('task', self.__task)) + .reply(200) + .headers(self.__header) + .json({'success': 'true', 'id': '433', 'task': self.__task}) + ) + + response = self.client.task_edit(self.__task) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_telephony_call_event(self): + """ + V5 Test method telephony_call_event + """ + + call_event = {'phone': '+799999999', 'type': 'out'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/telephony/call/event') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('event', call_event)) + .reply(200) + .headers(self.__header) + .json({'success': 'false', 'errorMsg': 'Telephony not enabled'}) + ) + + response = self.client.telephony_call_event(call_event) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_telephony_calls_upload(self): + """ + V5 Test method telephony_calls_upload + """ + + call = {'phone': '79999999999', 'type': 'out'} + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/telephony/calls/upload') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body(self.dictionaryEncode('calls', call)) + .reply(200) + .headers(self.__header) + .json({'success': 'false', 'errorMsg': 'Telephony not enabled or not supports calls upload'} + ) + ) + + response = self.client.telephony_calls_upload(call) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_telephony_manager(self): + """ + V5 Test method telephony_manager + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/telephony/manager') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params('+79999999999') + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'manager': { + 'id': 777, + 'firstName': 'John', + 'lastName': 'Doe', + 'patronymic': 'H.', + 'email': 'mail@retailcrm.ru', + 'code': 'ccc7' + }, + 'customer': { + 'id': 888, + 'externalId': '5406', + 'firstName': 'John', + 'lastName': 'Doe', + 'patronymic': 'H.', + 'email': 'mail@retailcrm.ru', + 'code': 'ccc7', + 'phones': [{'number': '+71111111111'}] + }, + 'links': { + 'newOrderLink': 'https://newOrderLink.ru', + 'lastOrderLink': 'https://lastOrderLink.ru', + 'newCustomerLink': 'https://newCustomerLink.ru', + 'customerLink': 'https://customerLink.ru', + } + } + ) + ) + + response = self.client.telephony_manager('+79999999999') + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_user_groups(self): + """ + V5 Test method user_groups + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/user-groups') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 2, + 'currentPage': 1, + 'totalPageCount': 1 + }, + 'groups': [ + { + 'name': 'Менеджеры', + 'code': 'manager', + 'isManager': 'true', + 'isPosManager': 'false', + 'isDeliveryMen': 'false', + 'deliveryTypes': [], + 'breakdownOrderTypes': ['xxx', 'yyy', 'zzz'], + }, + { + 'name': 'Руководители', + 'code': 'director', + 'isManager': 'false', + 'isPosManager': 'false', + 'isDeliveryMen': 'false', + 'deliveryTypes': ['xxx'], + 'breakdownOrderTypes': ['yyy'], + 'breakdownSites': [], + 'breakdownOrderMethods': ['zzz'], + 'grantedOrderTypes': ['ccc'] + } + ] + } + ) + ) + + response = self.client.user_groups() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_users(self): + """ + V5 Test method users + """ + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/users') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .params({'filter[status]': 'online', 'filter[isManager]': 'false'}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'pagination': { + 'limit': 20, + 'totalCount': 7, + 'currentPage': 1, + 'totalPageCount': 1 + }, + 'users': [ + { + 'id': 777, + 'createdAt': '2020-04-05 11:23:46', + 'active': 'true', + 'email': 'mail@retailcrm.ru', + 'firstName': 'yyy', + 'lastName': 'xxxx', + 'status': 'free', + 'online': 'true', + 'isAdmin': 'true', + 'isManager': 'false', + 'groups': [] + } + ] + } + ) + ) + + response = self.client.users({'status': 'online', 'isManager': 'false'}) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_user(self): + """ + V5 Test method user + """ + + uid = '777' + + (pook.get(os.getenv('RETAILCRM_URL') + '/api/v5/users/' + uid) + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .reply(200) + .headers(self.__header) + .json( + { + 'success': 'true', + 'user': { + 'id': 777, + 'createdAt': '2020-04-05 11:23:46', + 'active': 'true', + 'email': 'mail@retailcrm.ru', + 'firstName': 'yyy', + 'lastName': 'xxxx', + 'status': 'free', + 'online': 'true', + 'isAdmin': 'true', + 'isManager': 'false', + 'groups': [] + } + } + ) + ) + + response = self.client.user(uid) + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def test_user_status(self): + """ + V5 Test method user_status + """ + + uid = '777' + + (pook.post(os.getenv('RETAILCRM_URL') + '/api/v5/users/' + uid + '/status') + .headers({'X-API-KEY': os.getenv('RETAILCRM_KEY')}) + .body('status=free') + .reply(200) + .headers(self.__header) + .json({'success': 'true'}) + ) + + response = self.client.user_status(uid, 'free') + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True) + + @pook.on + def statistic_update(self): + """ + V5 Test method statistic_update + """ + + (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'}) + ) + + response = self.client.statistic_update() + pook.off() + + self.assertTrue(response.is_successful(), True) + self.assertTrue(response.get_status_code() < 400, True)