Skip to content

Commit ab4784e

Browse files
requirements updated
1 parent 13e02c8 commit ab4784e

File tree

4 files changed

+94
-104
lines changed

4 files changed

+94
-104
lines changed

contentstack/stack.py

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,20 @@
99
import enum
1010
import logging
1111
from urllib import parse
12-
13-
from urllib3 import Retry
14-
15-
import contentstack
12+
from urllib3.util import Retry
1613
from contentstack.asset import Asset
1714
from contentstack.assetquery import AssetQuery
1815
from contentstack.contenttype import ContentType
1916
from contentstack.https_connection import HTTPSConnection
2017
from contentstack.image_transform import ImageTransform
2118

19+
2220
__author__ = "ishaileshmishra (ishaileshmishra@gmail.com)"
2321
__license__ = "MIT"
2422
__version__ = '1.7.0'
2523

2624
log = logging.getLogger(__name__)
27-
default_host = 'cdn.contentstack.io'
25+
DEFAULT_HOST = 'cdn.contentstack.io'
2826

2927

3028
class ContentstackRegion(enum.Enum):
@@ -37,17 +35,17 @@ class ContentstackRegion(enum.Enum):
3735

3836

3937
class Stack:
40-
from urllib3.util import Retry
4138

4239
"""
4340
A stack can be defined as a pool of data or a container that holds all
4441
the content/assets related to a site. It is a collaboration space where multiple users can work
4542
together to create, edit, approve, and publish content.
4643
(API Reference)[https://www.contentstack.com/docs/developers/apis/content-delivery-api/#stack]:
4744
"""
45+
#from urllib3.util import Retry
4846

4947
def __init__(self, api_key: str, delivery_token: str, environment: str,
50-
host=default_host,
48+
host=DEFAULT_HOST,
5149
version='v3',
5250
region=ContentstackRegion.US,
5351
timeout=30,
@@ -67,7 +65,8 @@ def __init__(self, api_key: str, delivery_token: str, environment: str,
6765
:param branch: branch of the stack
6866
:param version: (optional) apiVersion of the stack default is v3
6967
:param region: (optional) region support of the stack default is ContentstackRegion.US
70-
:param live_preview: (optional) accepts type dictionary that enables live_preview option for request,
68+
:param live_preview: (optional) accepts type dictionary that enables
69+
live_preview option for request,
7170
takes input as dictionary object. containing one/multiple key value pair like below.
7271
7372
```python
@@ -82,7 +81,6 @@ def __init__(self, api_key: str, delivery_token: str, environment: str,
8281
:param retry_strategy (optional) custom retry_strategy can be set.
8382
# Method to create retry_strategy: create object of Retry() and provide the
8483
# required parameters like below
85-
8684
**Example:**
8785
8886
>>> _strategy = Retry(total=5, backoff_factor=1, status_forcelist=[408, 429])
@@ -123,22 +121,19 @@ def _validate_stack(self):
123121
'You are not permitted to the stack without valid Environment')
124122

125123

126-
if self.region.value == 'eu' and self.host == default_host:
124+
if self.region.value == 'eu' and self.host == DEFAULT_HOST:
127125
self.host = 'eu-cdn.contentstack.com'
128-
elif self.region.value == 'azure-na' and self.host == default_host:
126+
elif self.region.value == 'azure-na' and self.host == DEFAULT_HOST:
129127
self.host = 'azure-na-cdn.contentstack.com'
130128
elif self.region.value != 'us':
131-
self.host = '{}-{}'.format(self.region.value, default_host)
132-
133-
self.endpoint = 'https://{}/{}'.format(self.host, self.version)
129+
#self.host = '{}-{}'.format(self.region.value, DEFAULT_HOST)
130+
self.host = f'{self.region.value}-{DEFAULT_HOST}'
131+
self.endpoint = f'https://{self.host}/{self.version}'
134132

135133
self.headers = {
136-
'api_key':
137-
self.api_key,
138-
'access_token':
139-
self.delivery_token,
140-
'environment':
141-
self.environment
134+
'api_key': self.api_key,
135+
'access_token':self.delivery_token,
136+
'environment': self.environment
142137
}
143138

144139
if self.branch is not None:
@@ -163,7 +158,7 @@ def _validate_live_preview(self):
163158
self.headers['authorization'] = self.live_preview_dict['authorization']
164159
# remove deliveryToken and environment
165160
self.host = self.live_preview_dict['host']
166-
self.endpoint = 'https://{}/{}'.format(self.host, self.version)
161+
self.endpoint = f'https://{self.host}/{self.version}'
167162
self.headers.pop('access_token')
168163
self.headers.pop('environment')
169164

@@ -252,18 +247,22 @@ def asset_query(self):
252247
"""
253248
return AssetQuery(self.http_instance)
254249

255-
def sync_init(self, content_type_uid=None, start_from=None, locale=None, type=None):
250+
def sync_init(self, content_type_uid=None, start_from=None, locale=None, publish_type=None):
256251
"""
257-
Set init to ‘true’ if you want to sync all the published entries and assets. This is usually used when the
258-
app does not have any content and you want to get all the content for the first time.\n
252+
Set init to ‘true’ if you want to sync all the published entries and assets.
253+
This is usually used when the app does not have any content and you want to
254+
get all the content for the first time.\n
259255
260256
:param content_type_uid: (optional) content type UID. e.g., products
261257
This retrieves published entries of specified content type
262258
:param start_from: (optional) The start date. e.g., 2018-08-14T00:00:00.000Z
263259
This retrieves published entries starting from a specific date
264-
:param locale: (optional) locale code. e.g., en-us, This retrieves published entries of specific locale.
265-
:param type: (optional) If you do not specify any value, it will bring all published
266-
entries and published assets. You can pass multiple types as comma-separated values,
260+
:param locale: (optional) locale code. e.g., en-us, This retrieves published
261+
entries of specific locale.
262+
:param publish_type: (optional) If you do not specify any value,
263+
it will bring all published
264+
entries and published assets. You can pass multiple types
265+
as comma-separated values,
267266
for example, entry_published,entry_unpublished,asset_published
268267
:return: list of sync items
269268
-------------------------------
@@ -273,7 +272,7 @@ def sync_init(self, content_type_uid=None, start_from=None, locale=None, type=No
273272
>>> import contentstack
274273
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
275274
>>> result = stack.sync_init(content_type_uid='content_type_uid',
276-
start_from='date', locale='en-us', type='asset_published')
275+
start_from='date', locale='en-us', publish_type='asset_published')
277276
-------------------------------
278277
"""
279278
self.sync_param['init'] = 'true'
@@ -283,8 +282,8 @@ def sync_init(self, content_type_uid=None, start_from=None, locale=None, type=No
283282
self.sync_param['start_from'] = start_from
284283
if locale is not None and isinstance(locale, str):
285284
self.sync_param['locale'] = locale
286-
if type is not None and isinstance(type, str):
287-
self.sync_param['type'] = type
285+
if publish_type is not None and isinstance(publish_type, str):
286+
self.sync_param['type'] = publish_type
288287
return self.__sync_request()
289288

290289
def pagination(self, pagination_token: str):
@@ -333,18 +332,18 @@ def __sync_request(self):
333332
:return: :class:`Response <Response>` object
334333
:rtype: requests.Response
335334
"""
336-
base_url = '{}/stacks/sync'.format(self.http_instance.endpoint)
335+
base_url = f'{self.http_instance.endpoint}/stacks/sync'
337336
self.sync_param['environment'] = self.http_instance.headers['environment']
338337
encoded_query = parse.urlencode(self.sync_param)
339-
url = '{}?{}'.format(base_url, encoded_query)
338+
url = f'{base_url}?{encoded_query}'
340339
result = self.http_instance.get(url)
341340
return result
342341

343342
def image_transform(self, image_url, **kwargs):
344343
"""
345344
This document is a detailed reference to Contentstack’s Image Delivery
346345
API and covers the parameters that you can add to the URL to retrieve,
347-
manipulate (or convert) image files and display it to your web or
346+
manipulate (or convert) image files and display it to your web or
348347
mobile properties.\n
349348
350349
:param image_url: base url on which queries to apply

requirements.txt

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
twython~=3.8.2
2-
setuptools~=51.1.0
1+
twython~=3.9.1
2+
setuptools~=62.1.0
33
urllib3~=1.26.2
44
contentstack-utils
5-
python-dateutil==2.8.1
6-
requests>=2.20.0,<3.0
7-
coverage==4.3.4
8-
tox==2.5.0
9-
virtualenv==15.1.0
10-
Sphinx==1.6.3
11-
sphinxcontrib-websupport==1.0.1
5+
python-dateutil==2.8.2
6+
requests==2.27.1
7+
coverage==6.3.2
8+
tox==3.24.5
9+
virtualenv==20.14.0
10+
Sphinx==4.5.0
11+
sphinxcontrib-websupport==1.2.4
1212
pip~=22.0.4
13-
build~=0.6.0.post1
14-
# build==0.7.0
15-
wheel~=0.35.1
16-
py~=1.9.0
17-
lxml~=4.6.2
13+
build~=0.7.0
14+
wheel~=0.37.1
15+
py~=1.11.0
16+
lxml~=4.8.0
1817
utils~=1.0.1
19-
keyring~=21.5.0
20-
docutils~=0.16
21-
pyparsing~=2.4.7
18+
keyring~=23.5.0
19+
docutils==0.16
20+
pyparsing~=3.0.8
2221
config~=0.5.1

tests/test_entry.py

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import logging
21
import unittest
32

43
import config
54
import contentstack
65

7-
entry_uid = None
6+
ENTRY_UI = None
87

98

109
class TestEntry(unittest.TestCase):
@@ -17,82 +16,79 @@ def test_01_run_initial_query(self):
1716
query = self.stack.content_type('faq').query()
1817
result = query.find()
1918
if result is not None:
20-
global entry_uid
21-
entry_uid = result['entries'][0]['uid']
22-
logging.debug(entry_uid)
23-
logging.info(' => query result is: {}'.format(result['entries']))
24-
self.assertEqual(entry_uid, result['entries'][0]['uid'])
19+
global ENTRY_UI
20+
ENTRY_UI = result['entries'][0]['uid']
21+
self.assertEqual(ENTRY_UI, result['entries'][0]['uid'])
2522

2623
def test_02_entry_by_uid(self):
27-
global entry_uid
28-
entry = self.stack.content_type('faq').entry(entry_uid)
24+
global ENTRY_UI
25+
entry = self.stack.content_type('faq').entry(ENTRY_UI)
2926
result = entry.fetch()
3027
if result is not None:
31-
logging.info(' => entry result is: {}'.format(result['entry']))
32-
entry_uid = result['entry']['uid']
33-
self.assertEqual(entry_uid, result['entry']['uid'])
28+
ENTRY_UI = result['entry']['uid']
29+
self.assertEqual(ENTRY_UI, result['entry']['uid'])
3430

3531
def test_03_entry_environment(self):
36-
global entry_uid
32+
global ENTRY_UI
3733
entry = self.stack.content_type('faq').entry(
38-
entry_uid).environment('test')
34+
ENTRY_UI).environment('test')
3935
self.assertEqual("test", entry.http_instance.headers['environment'])
4036

4137
def test_04_entry_locale(self):
42-
global entry_uid
38+
global ENTRY_UI
4339
entry = self.stack.content_type('faq').entry(
44-
entry_uid).locale('en-eu-ei')
40+
ENTRY_UI).locale('en-eu-ei')
4541
entry.fetch()
4642
self.assertEqual('en-eu-ei', entry.entry_param['locale'])
4743

4844
def test_05_entry_version(self):
49-
global entry_uid
50-
entry = self.stack.content_type('faq').entry(entry_uid).version(3)
45+
global ENTRY_UI
46+
entry = self.stack.content_type('faq').entry(ENTRY_UI).version(3)
5147
entry.fetch()
5248
self.assertEqual(3, entry.entry_param['version'])
5349

5450
def test_06_entry_params(self):
55-
global entry_uid
51+
global ENTRY_UI
5652
entry = self.stack.content_type('faq').entry(
57-
entry_uid).param('param_key', 'param_value')
53+
ENTRY_UI).param('param_key', 'param_value')
5854
entry.fetch()
5955
self.assertEqual('param_value', entry.entry_param['param_key'])
6056

6157
def test_07_entry_base_only(self):
62-
global entry_uid
58+
global ENTRY_UI
6359
entry = self.stack.content_type(
64-
'faq').entry(entry_uid).only('field_uid')
60+
'faq').entry(ENTRY_UI).only('field_uid')
6561
entry.fetch()
6662
self.assertEqual({'environment': 'development',
6763
'only[BASE][]': 'field_uid'}, entry.entry_param)
6864

6965
def test_08_entry_base_excepts(self):
70-
global entry_uid
66+
global ENTRY_UI
7167
entry = self.stack.content_type('faq').entry(
72-
entry_uid).excepts('field_uid')
68+
ENTRY_UI).excepts('field_uid')
7369
entry.fetch()
7470
self.assertEqual({'environment': 'development',
7571
'except[BASE][]': 'field_uid'}, entry.entry_param)
7672

7773
def test_10_entry_base_include_reference_only(self):
78-
global entry_uid
79-
entry = self.stack.content_type('faq').entry(entry_uid).only('field1')
74+
global ENTRY_UI
75+
entry = self.stack.content_type('faq').entry(ENTRY_UI).only('field1')
8076
entry.fetch()
8177
self.assertEqual({'environment': 'development', 'only[BASE][]': 'field1'},
8278
entry.entry_param)
8379

8480
def test_11_entry_base_include_reference_excepts(self):
85-
global entry_uid
81+
global ENTRY_UI
8682
entry = self.stack.content_type(
87-
'faq').entry(entry_uid).excepts('field1')
83+
'faq').entry(ENTRY_UI).excepts('field1')
8884
entry.fetch()
8985
self.assertEqual({'environment': 'development', 'except[BASE][]': 'field1'},
9086
entry.entry_param)
9187

9288
def test_12_entry_include_reference_github_issue(self):
9389
stack_for_products = contentstack.Stack(
9490
"api_key", "delivery_token", "environment")
95-
_entry = stack_for_products.content_type('product').entry("entry_uid").include_reference(
91+
_entry = stack_for_products.content_type('product').entry("ENTRY_UI").include_reference(
9692
["categories",
9793
"brand"])
9894
response = _entry.fetch()
@@ -101,15 +97,15 @@ def test_12_entry_include_reference_github_issue(self):
10197
# self.assertEqual(2, len(categories))
10298

10399
def test_13_entry_support_include_fallback_unit_test(self):
104-
global entry_uid
100+
global ENTRY_UI
105101
entry = self.stack.content_type('faq').entry(
106-
entry_uid).include_fallback()
102+
ENTRY_UI).include_fallback()
107103
self.assertEqual(
108104
True, entry.entry_param.__contains__('include_fallback'))
109105

110106
def test_14_entry_queryable_only(self):
111107
try:
112-
entry = self.stack.content_type('faq').entry(entry_uid).only(4)
108+
entry = self.stack.content_type('faq').entry(ENTRY_UI).only(4)
113109
result = entry.fetch()
114110
self.assertEqual(None, result['uid'])
115111
except KeyError as e:
@@ -118,7 +114,7 @@ def test_14_entry_queryable_only(self):
118114

119115
def test_15_entry_queryable_excepts(self):
120116
try:
121-
entry = self.stack.content_type('faq').entry(entry_uid).excepts(4)
117+
entry = self.stack.content_type('faq').entry(ENTRY_UI).excepts(4)
122118
result = entry.fetch()
123119
self.assertEqual(None, result['uid'])
124120
except KeyError as e:
@@ -127,19 +123,19 @@ def test_15_entry_queryable_excepts(self):
127123

128124
def test_16_entry_queryable_include_content_type(self):
129125
entry = self.stack.content_type('faq').entry(
130-
entry_uid).include_content_type()
126+
ENTRY_UI).include_content_type()
131127
self.assertEqual({'include_content_type': 'true', 'include_global_field_schema': 'true'},
132128
entry.entry_queryable_param)
133129

134130
def test_18_entry_queryable_include_reference_content_type_uid(self):
135131
entry = self.stack.content_type('faq').entry(
136-
entry_uid).include_reference_content_type_uid()
132+
ENTRY_UI).include_reference_content_type_uid()
137133
self.assertEqual({'include_reference_content_type_uid': 'true'},
138134
entry.entry_queryable_param)
139135

140136
def test_19_entry_queryable_add_param(self):
141137
entry = self.stack.content_type('faq').entry(
142-
entry_uid).add_param('cms', 'contentstack')
138+
ENTRY_UI).add_param('cms', 'contentstack')
143139
self.assertEqual({'cms': 'contentstack'}, entry.entry_queryable_param)
144140

145141
def test_20_entry_include_fallback(self):

0 commit comments

Comments
 (0)