diff --git a/openprocurement_client/resources/assets.py b/openprocurement_client/resources/assets.py index e0b5da8..7a963e3 100644 --- a/openprocurement_client/resources/assets.py +++ b/openprocurement_client/resources/assets.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- +from retrying import retry + from openprocurement_client.clients import APIResourceClient from openprocurement_client.constants import ASSETS +from openprocurement_client.exceptions import RequestFailed class AssetsClient(APIResourceClient): @@ -8,8 +11,18 @@ class AssetsClient(APIResourceClient): resource = ASSETS - get_asset = APIResourceClient.get_resource_item - get_assets = APIResourceClient.get_resource_items - patch_asset = APIResourceClient.patch_resource_item + @retry(wait_exponential_multiplier=200, + wait_exponential_max=1200, + stop_max_delay=45000, + retry_on_exception=lambda exc: isinstance(exc, RequestFailed)) + def patch_asset(self, asset_id, patch_data): + return self.patch_resource_item(asset_id, patch_data) + + @retry(wait_exponential_multiplier=200, + wait_exponential_max=1200, + stop_max_delay=45000, + retry_on_exception=lambda exc: isinstance(exc, RequestFailed)) + def get_asset(self, asset_id): + return self.get_resource_item(asset_id) diff --git a/openprocurement_client/resources/lots.py b/openprocurement_client/resources/lots.py index 2ae7255..3d703f6 100644 --- a/openprocurement_client/resources/lots.py +++ b/openprocurement_client/resources/lots.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- +from retrying import retry + from openprocurement_client.clients import APIResourceClient from openprocurement_client.constants import LOTS +from openprocurement_client.exceptions import RequestFailed class LotsClient(APIResourceClient): @@ -8,8 +11,18 @@ class LotsClient(APIResourceClient): resource = LOTS - get_lot = APIResourceClient.get_resource_item - get_lots = APIResourceClient.get_resource_items - patch_lot = APIResourceClient.patch_resource_item + @retry(wait_exponential_multiplier=200, + wait_exponential_max=1200, + stop_max_delay=45000, + retry_on_exception=lambda exc: isinstance(exc, RequestFailed)) + def patch_lot(self, lot_id, patch_data): + return self.patch_resource_item(lot_id, patch_data) + + @retry(wait_exponential_multiplier=200, + wait_exponential_max=1200, + stop_max_delay=45000, + retry_on_exception=lambda exc: isinstance(exc, RequestFailed)) + def get_lot(self, lot_id): + return self.get_resource_item(lot_id) diff --git a/openprocurement_client/tests/test_registry_client.py b/openprocurement_client/tests/test_registry_client.py index 5579718..abeb4ec 100644 --- a/openprocurement_client/tests/test_registry_client.py +++ b/openprocurement_client/tests/test_registry_client.py @@ -96,7 +96,7 @@ def test_get_asset(self): asset = self.client.get_asset(TEST_ASSET_KEYS.asset_id) self.assertEqual(asset, self.asset) - def test_patch_asset(self): + def test_patch_resource_item(self): setup_routing(self.app, routes=["asset_patch"]) asset_id = self.asset.data.id patch_data = {'data': {'description': 'test_patch_asset'}} @@ -106,6 +106,16 @@ def test_patch_asset(self): self.assertEqual(patched_asset.data.description, patch_data['data']['description']) + def test_patch_asset(self): + setup_routing(self.app, routes=["asset_patch"]) + asset_id = self.asset.data.id + patch_data = {'data': {'description': 'test_patch_asset'}} + patched_asset = self.client.patch_asset(asset_id, + patch_data) + self.assertEqual(patched_asset.data.id, self.asset.data.id) + self.assertEqual(patched_asset.data.description, + patch_data['data']['description']) + class LotsRegistryTestCase(BaseTestClass): def setUp(self): @@ -136,7 +146,7 @@ def test_get_lot(self): lot = self.client.get_lot(TEST_LOT_KEYS.lot_id) self.assertEqual(lot, self.lot) - def test_patch_lot(self): + def test_patch_resource_item(self): setup_routing(self.app, routes=["lot_patch"]) lot_id = self.lot.data.id patch_data = {'data': {'description': 'test_patch_lot'}} @@ -145,6 +155,15 @@ def test_patch_lot(self): self.assertEqual(patched_lot.data.description, patch_data['data']['description']) + def test_patch_lot(self): + setup_routing(self.app, routes=["lot_patch"]) + lot_id = self.lot.data.id + patch_data = {'data': {'description': 'test_patch_lot'}} + patched_lot = self.client.patch_lot(lot_id, patch_data) + self.assertEqual(patched_lot.data.id, lot_id) + self.assertEqual(patched_lot.data.description, + patch_data['data']['description']) + def suite(): suite = unittest.TestSuite()