Skip to content

Commit ea0a8d8

Browse files
Test resouces/template.py
1 parent 00f625f commit ea0a8d8

File tree

4 files changed

+165
-2
lines changed

4 files changed

+165
-2
lines changed

connect/resources/template.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ def list(self, product_id):
2222
"""
2323
# type: (Dict[str, Any]) -> List[Any]
2424
"""
25-
if not product_id:
26-
raise ValueError('Invalid product Id for list template')
2725
response, _ = self._api.get(
2826
'/public/v1/products/' + product_id + '/templates/',
2927
params={'scope': 'asset', 'type': 'fulfillment'},
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[
2+
{
3+
"id": "TL-313-655-502",
4+
"title": "Default Activation Template",
5+
"name": "Default Activation Template",
6+
"body": "# Sample Activation Template\n\nActivation template is used to share details of the **successful** asset creation with the user. Once purchase request is approved, this template is used to generate user-visible notification.\n\nThis template uses **[Markdown](https://en.wikipedia.org/wiki/Markdown)** syntax and allows to use Parameters of the product which has scope 'Asset'.\n\n### Formatting\n\nMarkdown allows you to control various aspects of the document:\n\n1. Text formatting like **bold** or *italic*\n2. Images embedding\n3. Lists\n4. and more\n\n### Parameters\n\nYou can refer to the Parameters using their ID, like in the following example:\n\n\nYou can also embed pictures like the one below:\n\n![logo](https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Ringworld_Waiting.jpg/270px-Ringworld_Waiting.jpg)",
7+
"scope": "asset",
8+
"type": "fulfillment",
9+
"position": 10000,
10+
"events": {
11+
"created": {
12+
"at": "2020-01-07T09:11:25+00:00"
13+
},
14+
"updated": {
15+
"at": "2020-05-02T22:04:38+00:00",
16+
"by": {
17+
"id": "UR-216-020-887",
18+
"name": "Martin Constante"
19+
}
20+
}
21+
}
22+
},
23+
{
24+
"id": "TL-362-270-671",
25+
"title": "Default Activation Template",
26+
"name": "Default Activation Template",
27+
"body": "# Sample Template For Setup of Tier 1\n\nThis template is used to share details of the **successful** setup configuration of reseller of 1st level.\n\nThis template uses **[Markdown](https://en.wikipedia.org/wiki/Markdown)** syntax and allows to use Parameters of the product which have scope 'Tier 1'.\n\n### Formatting\n\nMarkdown allows you to control various aspects of the document:\n\n1. Text formatting like **bold** or *italic*\n2. Images embedding\n3. Lists\n4. and more\n\n### Parameters\n\nYou can refer to the Parameters using their ID, like in the following example:\n\n* The value of **param_a** is **{{ param_a }}**\n* The value of **param_b** is **{{ param_b }}**\n\nYou can also embed pictures like the one below:\n\n![logo](https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Ringworld_Waiting.jpg/270px-Ringworld_Waiting.jpg)",
28+
"scope": "tier1",
29+
"position": 20000,
30+
"events": {
31+
"created": {
32+
"at": "2020-01-07T09:11:25+00:00"
33+
},
34+
"updated": {
35+
"at": "2020-01-07T09:11:25+00:00"
36+
}
37+
}
38+
},
39+
{
40+
"id": "TL-064-379-743",
41+
"title": "Default Activation Template",
42+
"name": "Default Activation Template",
43+
"body": "# Sample Template For Setup of Tier 2\n\nThis template is used to share details of the **successful** setup configuration of reseller of 2nd level.\n\nThis template uses **[Markdown](https://en.wikipedia.org/wiki/Markdown)** syntax and allows to use Parameters of the product which have scope 'Tier 2'.\n\n### Formatting\n\nMarkdown allows you to control various aspects of the document:\n\n1. Text formatting like **bold** or *italic*\n2. Images embedding\n3. Lists\n4. and more\n\n### Parameters\n\nYou can refer to the Parameters using their ID, like in the following example:\n\n* The value of **param_a** is **{{ param_a }}**\n* The value of **param_b** is **{{ param_b }}**\n\nYou can also embed pictures like the one below:\n\n![logo](https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Ringworld_Waiting.jpg/270px-Ringworld_Waiting.jpg)",
44+
"scope": "tier2",
45+
"position": 30000,
46+
"events": {
47+
"created": {
48+
"at": "2020-01-07T09:11:25+00:00"
49+
},
50+
"updated": {
51+
"at": "2020-01-07T09:11:25+00:00"
52+
}
53+
}
54+
},
55+
{
56+
"id": "TL-416-019-529",
57+
"title": "Additional information is required to process your request",
58+
"name": "Additional information is required to process your request",
59+
"body": "Please complete our **[Activation Form]({{ activation_form_url }})** to resume processing of your request",
60+
"scope": "asset",
61+
"type": "inquire",
62+
"position": 40000,
63+
"events": {
64+
"created": {
65+
"at": "2020-01-07T09:11:25+00:00"
66+
},
67+
"updated": {
68+
"at": "2020-01-07T09:11:25+00:00"
69+
}
70+
}
71+
}
72+
]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"id": "TL-313-655-502",
3+
"title": "Default Activation Template",
4+
"name": "Default Activation Template",
5+
"body": "# Sample Activation Template\n\nActivation template is used to share details of the **successful** asset creation with the user. Once purchase request is approved, this template is used to generate user-visible notification.\n\nThis template uses **[Markdown](https://en.wikipedia.org/wiki/Markdown)** syntax and allows to use Parameters of the product which has scope 'Asset'.\n\n### Formatting\n\nMarkdown allows you to control various aspects of the document:\n\n1. Text formatting like **bold** or *italic*\n2. Images embedding\n3. Lists\n4. and more\n\n### Parameters\n\nYou can refer to the Parameters using their ID, like in the following example:\n\n\nYou can also embed pictures like the one below:\n\n![logo](https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Ringworld_Waiting.jpg/270px-Ringworld_Waiting.jpg)",
6+
"scope": "asset",
7+
"type": "fulfillment",
8+
"position": 10000,
9+
"events": {
10+
"created": {
11+
"at": "2020-01-07T09:11:25+00:00"
12+
},
13+
"updated": {
14+
"at": "2020-05-02T22:04:38+00:00",
15+
"by": {
16+
"id": "UR-216-020-887",
17+
"name": "Martin Constante"
18+
}
19+
}
20+
}
21+
}

tests/test_template.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- coding: utf-8 -*-
2+
# This file is part of the Ingram Micro Cloud Blue Connect SDK.
3+
# Copyright (c) 2019-2020 Ingram Micro. All Rights Reserved.
4+
5+
from mock import patch, MagicMock
6+
import os
7+
8+
import pytest
9+
10+
from connect.exceptions import ServerError
11+
from connect.resources import TemplateResource
12+
from .common import Response, load_str
13+
14+
15+
def _list_template_response():
16+
return _get_response_from_file('list_template_response.json')
17+
18+
19+
def _get_template_response():
20+
return _get_response_from_file('get_template_response.json')
21+
22+
23+
def _get_response_from_file(filename):
24+
return Response(
25+
ok=True,
26+
text=load_str(os.path.join(os.path.dirname(__file__), 'data', filename)),
27+
status_code=200
28+
)
29+
30+
31+
def _get_array_response(object_response):
32+
return Response(
33+
ok=True,
34+
text='[{}]'.format(object_response.text),
35+
status_code=200
36+
)
37+
38+
39+
def _get_bad_response():
40+
return Response(
41+
ok=False,
42+
text='{}',
43+
status_code=404
44+
)
45+
46+
47+
@patch('requests.get')
48+
def test_list_templates(get_mock):
49+
get_mock.return_value = _get_array_response(_list_template_response())
50+
template = TemplateResource().list('PRD-845-746-468')
51+
assert isinstance(template, list)
52+
assert len(template) == 1
53+
54+
get_mock.assert_called_with(
55+
url='http://localhost:8080/public/v1/products/PRD-845-746-468/templates/',
56+
headers={'Content-Type': 'application/json', 'Authorization': 'ApiKey XXXX:YYYYY'},
57+
params={'scope': 'asset', 'type': 'fulfillment'},
58+
timeout=300)
59+
60+
61+
@patch('requests.get', MagicMock(return_value=_get_bad_response()))
62+
def test_list_template_bad():
63+
with pytest.raises(ServerError):
64+
TemplateResource().list('PRD-000-000-000')
65+
66+
67+
@patch('requests.get')
68+
def test_get_template(get_mock):
69+
get_mock.return_value = _get_template_response()
70+
template = TemplateResource().get('TL-313-655-502')
71+
assert template.template_id == 'TL-313-655-502'
72+

0 commit comments

Comments
 (0)