Skip to content

Commit d06c8c4

Browse files
- Azure_eu and include_metadata support added
- Live preview code updated - Security file added
1 parent 5592f67 commit d06c8c4

File tree

2 files changed

+80
-107
lines changed

2 files changed

+80
-107
lines changed

tests/test_live_preview.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import config
44
import contentstack
5+
from contentstack.deep_merge_lp import DeepMergeMixin
56

67
management_token = 'cs8743874323343u9'
78
entry_uid = 'blt8743874323343u9'
@@ -131,5 +132,84 @@ def test_10_live_preview_check_hash_value(self):
131132
self.assertEqual(ENVIRONMENT, self.stack.headers['environment'])
132133

133134

135+
lp_response = [
136+
{
137+
"uid": "76743678743",
138+
"comment": "this belongs to live preview object",
139+
"_version": 2,
140+
"locale": "en-us",
141+
"ACL": {},
142+
"author": [
143+
{
144+
"uid": "77f3f0ea3630e06",
145+
"_content_type_uid": "author"
146+
}
147+
]
148+
},
149+
{
150+
"uid": "7634767463",
151+
"_version": 2,
152+
"locale": "en-us",
153+
"comment": "this belongs to live preview object",
154+
"ACL": {},
155+
"author": [
156+
{
157+
"uid": "bltb77f3f0ea3630e06",
158+
"_content_type_uid": "author"
159+
}
160+
]
161+
}
162+
]
163+
164+
entry_response = [
165+
{
166+
"uid": "76743678743",
167+
"_version": 3,
168+
"locale": "en-uk",
169+
"title": "Updated Title",
170+
"comment": "this belongs to entry object",
171+
},
172+
{
173+
"uid": "47634767463",
174+
"_version": 3,
175+
"locale": "en-uk",
176+
"title": "Updated Title",
177+
"comment": "this belongs to entry object",
178+
},
179+
{
180+
"uid": "34767463",
181+
"_version": 3,
182+
"locale": "en-us",
183+
"comment": "this belongs to entry object",
184+
"title": "You have received a new merged entry response"
185+
}
186+
]
187+
188+
189+
class TestLivePreviewObject(unittest.TestCase):
190+
191+
def setUp(self):
192+
self.stack = contentstack.Stack(
193+
API_KEY, DELIVERY_TOKEN,
194+
ENVIRONMENT, host=HOST)
195+
196+
def test_setup_live_preview(self):
197+
self.stack = contentstack.Stack(API_KEY, DELIVERY_TOKEN, ENVIRONMENT, live_preview={
198+
'enable': False,
199+
'host': 'api.contentstack.io',
200+
'management_token': 'string987654321'
201+
})
202+
self.stack.content_type('product').entry(entry_uid)
203+
self.assertEqual(3, len(self.stack.get_live_preview))
204+
self.assertFalse(self.stack.get_live_preview['enable'])
205+
self.assertTrue(self.stack.get_live_preview['management_token'])
206+
207+
def test_deep_merge_object(self):
208+
merged_response = DeepMergeMixin(entry_response, lp_response)
209+
self.assertTrue(isinstance(merged_response.entry_response, list))
210+
self.assertEqual(3, len(merged_response.entry_response))
211+
print(merged_response.entry_response)
212+
213+
134214
if __name__ == '__main__':
135215
unittest.main()

tests/test_preview_obj.py

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +0,0 @@
1-
import unittest
2-
3-
import config
4-
import contentstack
5-
from contentstack.deep_merge_lp import DeepMergeMixin
6-
7-
management_token = 'cs8743874323343u9'
8-
entry_uid = 'blt8743874323343u9'
9-
10-
_lp_query = {
11-
'live_preview': '#0#0#0#0#0#0#0#0#0#',
12-
'content_type_uid': 'product',
13-
'entry_uid': entry_uid
14-
}
15-
_lp = {
16-
'enable': True,
17-
'host': 'api.contentstack.io',
18-
'management_token': management_token
19-
}
20-
21-
API_KEY = config.APIKEY
22-
DELIVERY_TOKEN = config.DELIVERYTOKEN
23-
ENVIRONMENT = config.ENVIRONMENT
24-
HOST = config.HOST
25-
ENTRY_UID = config.APIKEY
26-
27-
lp_response = [
28-
{
29-
"uid": "76743678743",
30-
"comment": "this belongs to live preview object",
31-
"_version": 2,
32-
"locale": "en-us",
33-
"ACL": {},
34-
"author": [
35-
{
36-
"uid": "77f3f0ea3630e06",
37-
"_content_type_uid": "author"
38-
}
39-
]
40-
},
41-
{
42-
"uid": "7634767463",
43-
"_version": 2,
44-
"locale": "en-us",
45-
"comment": "this belongs to live preview object",
46-
"ACL": {},
47-
"author": [
48-
{
49-
"uid": "bltb77f3f0ea3630e06",
50-
"_content_type_uid": "author"
51-
}
52-
]
53-
}
54-
]
55-
56-
entry_response = [
57-
{
58-
"uid": "76743678743",
59-
"_version": 3,
60-
"locale": "en-uk",
61-
"title": "Updated Title",
62-
"comment": "this belongs to entry object",
63-
},
64-
{
65-
"uid": "47634767463",
66-
"_version": 3,
67-
"locale": "en-uk",
68-
"title": "Updated Title",
69-
"comment": "this belongs to entry object",
70-
},
71-
{
72-
"uid": "34767463",
73-
"_version": 3,
74-
"locale": "en-us",
75-
"comment": "this belongs to entry object",
76-
"title": "You have received a new merged entry response"
77-
}
78-
]
79-
80-
81-
class TestLivePreviewObject(unittest.TestCase):
82-
83-
def setUp(self):
84-
self.stack = contentstack.Stack(
85-
API_KEY, DELIVERY_TOKEN,
86-
ENVIRONMENT, host=HOST)
87-
88-
def test_setup_live_preview(self):
89-
self.stack = contentstack.Stack(API_KEY, DELIVERY_TOKEN, ENVIRONMENT, live_preview={
90-
'enable': False,
91-
'host': 'api.contentstack.io',
92-
'management_token': 'string987654321'
93-
})
94-
self.stack.content_type('product').entry(entry_uid)
95-
self.assertEqual(3, len(self.stack.get_live_preview))
96-
self.assertFalse(self.stack.get_live_preview['enable'])
97-
self.assertTrue(self.stack.get_live_preview['management_token'])
98-
99-
def test_deep_merge_object(self):
100-
merged_response = DeepMergeMixin(entry_response, lp_response)
101-
self.assertTrue(isinstance(merged_response.entry_response, list))
102-
self.assertEqual(3, len(merged_response.entry_response))
103-
print(merged_response.entry_response)
104-
105-
106-
if __name__ == '__main__':
107-
unittest.main()

0 commit comments

Comments
 (0)