Skip to content

Commit 0247b2c

Browse files
More tests (finished)
1 parent 0f3a4c5 commit 0247b2c

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

connect/models/activation_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class ActivationTileResponse(object):
1212
tile = 'Activation succeeded' # type: str
1313

14-
def __init__(self, markdown=None):
14+
def __init__(self, markdown=''):
1515
# type: (str) -> None
1616
try:
1717
self.tile = json.loads(markdown)

connect/resource/tier_config_automation.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,5 @@ def get_tier_config(self, tier_id, product_id):
6767

6868
if isinstance(objects, list) and len(objects) > 0:
6969
return objects[0].configuration
70-
elif isinstance(objects, TierConfigRequest):
71-
# Actually, we should no get here as schema has many=True
72-
return objects.configuration
7370
else:
7471
return None

tests/test_tier_config_request.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010
import pytest
1111
from mock import MagicMock, patch
12-
from typing import Union
12+
from typing import Union, ClassVar
1313

1414
from connect import TierConfigAutomation
1515
from connect.models import Param, ActivationTileResponse, ActivationTemplateResponse
1616
from connect.models.base import BaseModel
1717
from connect.models.company import Company
1818
from connect.models.connection import Connection
19+
from connect.models.exception import FulfillmentInquire, FulfillmentFail, Skip
1920
from connect.models.hub import Hub
2021
from connect.models.product import Product
2122
from connect.models.tier_config import TierConfigRequest, TierConfig, Events, Template, \
@@ -175,9 +176,34 @@ def test_process_invalid_product():
175176

176177

177178
@patch('requests.get', MagicMock(return_value=_get_response_ok()))
178-
@patch('requests.post')
179-
def test_process_with_activation_tile(_):
180-
automation = TierConfigAutomationHelper(ActivationTileResponse('TL-000-000-000'))
179+
@patch('requests.post', MagicMock(return_value=_get_response_ok()))
180+
def test_process_with_activation_tile():
181+
automation = TierConfigAutomationHelper(ActivationTileResponse())
182+
automation.process()
183+
184+
185+
@patch('requests.get', MagicMock(return_value=_get_response_ok()))
186+
@patch('requests.post', MagicMock(return_value=_get_response_ok()))
187+
def test_process_with_activation_template():
188+
automation = TierConfigAutomationHelper(ActivationTemplateResponse('TL-000-000-000'))
189+
automation.process()
190+
191+
192+
@patch('requests.get', MagicMock(return_value=_get_response_ok_invalid_product()))
193+
def test_process_raise_inquire():
194+
automation = TierConfigAutomationHelper(exception_class=FulfillmentInquire)
195+
automation.process()
196+
197+
198+
@patch('requests.get', MagicMock(return_value=_get_response_ok_invalid_product()))
199+
def test_process_raise_fail():
200+
automation = TierConfigAutomationHelper(exception_class=FulfillmentFail)
201+
automation.process()
202+
203+
204+
@patch('requests.get', MagicMock(return_value=_get_response_ok_invalid_product()))
205+
def test_process_raise_skip():
206+
automation = TierConfigAutomationHelper(exception_class=Skip)
181207
automation.process()
182208

183209

@@ -203,10 +229,14 @@ def test_get_tier_config_param():
203229

204230

205231
class TierConfigAutomationHelper(TierConfigAutomation):
206-
def __init__(self, response=''):
207-
# type: (Union[ActivationTemplateResponse, ActivationTileResponse]) -> None
232+
def __init__(self, response='', exception_class=None):
233+
# type: (Union[ActivationTemplateResponse, ActivationTileResponse, str], ClassVar) -> None
208234
super(TierConfigAutomationHelper, self).__init__()
209235
self.response = response
236+
self.exception_class = exception_class
210237

211238
def process_request(self, request):
212-
return self.response
239+
if self.exception_class:
240+
self.exception_class(self.response)
241+
else:
242+
return self.response

0 commit comments

Comments
 (0)