Skip to content

Commit 13e02c8

Browse files
code clean up :check:
1 parent fe515f9 commit 13e02c8

File tree

11 files changed

+36
-37
lines changed

11 files changed

+36
-37
lines changed

contentstack/entry.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
import logging
77
from urllib import parse
8-
9-
from pyparsing import empty
10-
118
from contentstack.entryqueryable import EntryQueryable
129

1310
# ************* Module Entry **************
@@ -160,7 +157,7 @@ def include_embedded_items(self):
160157
return self
161158

162159
def __get_base_url(self, endpoint=''):
163-
if endpoint is not None and not empty:
160+
if endpoint is not None and not endpoint.empty:
164161
self.http_instance.endpoint = endpoint
165162
if None in (self.http_instance, self.content_type_id, self.entry_uid):
166163
raise KeyError(

contentstack/query.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import logging
77
from urllib import parse
88

9-
from pyparsing import empty
109

1110
from contentstack.basequery import BaseQuery
1211
from contentstack.entryqueryable import EntryQueryable

contentstack/stack.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
__version__ = '1.7.0'
2525

2626
log = logging.getLogger(__name__)
27+
default_host = 'cdn.contentstack.io'
2728

2829

2930
class ContentstackRegion(enum.Enum):
@@ -44,7 +45,6 @@ class Stack:
4445
together to create, edit, approve, and publish content.
4546
(API Reference)[https://www.contentstack.com/docs/developers/apis/content-delivery-api/#stack]:
4647
"""
47-
default_host = cdn.contentstack.io
4848

4949
def __init__(self, api_key: str, delivery_token: str, environment: str,
5050
host=default_host,
@@ -82,7 +82,9 @@ def __init__(self, api_key: str, delivery_token: str, environment: str,
8282
:param retry_strategy (optional) custom retry_strategy can be set.
8383
# Method to create retry_strategy: create object of Retry() and provide the
8484
# required parameters like below
85+
8586
**Example:**
87+
8688
>>> _strategy = Retry(total=5, backoff_factor=1, status_forcelist=[408, 429])
8789
>>> stack = contentstack.Stack("api_key", "delivery_token", "environment",
8890
live_preview={enable=True, authorization='your auth token'}, retry_strategy= _strategy)
@@ -107,7 +109,6 @@ def __init__(self, api_key: str, delivery_token: str, environment: str,
107109
self.retry_strategy = retry_strategy
108110
self.live_preview_dict = live_preview
109111

110-
# validate stack
111112
self._validate_stack()
112113

113114
def _validate_stack(self):
@@ -121,7 +122,7 @@ def _validate_stack(self):
121122
raise PermissionError(
122123
'You are not permitted to the stack without valid Environment')
123124

124-
# prepare endpoint for the url:
125+
125126
if self.region.value == 'eu' and self.host == default_host:
126127
self.host = 'eu-cdn.contentstack.com'
127128
elif self.region.value == 'azure-na' and self.host == default_host:
@@ -130,12 +131,14 @@ def _validate_stack(self):
130131
self.host = '{}-{}'.format(self.region.value, default_host)
131132

132133
self.endpoint = 'https://{}/{}'.format(self.host, self.version)
133-
# prepare Headers:`
134134

135135
self.headers = {
136-
'api_key': self.api_key,
137-
'access_token': self.delivery_token,
138-
'environment': self.environment
136+
'api_key':
137+
self.api_key,
138+
'access_token':
139+
self.delivery_token,
140+
'environment':
141+
self.environment
139142
}
140143

141144
if self.branch is not None:

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ tox==2.5.0
99
virtualenv==15.1.0
1010
Sphinx==1.6.3
1111
sphinxcontrib-websupport==1.0.1
12-
pip~=21.2.3
12+
pip~=22.0.4
1313
build~=0.6.0.post1
14+
# build==0.7.0
1415
wheel~=0.35.1
1516
py~=1.9.0
1617
lxml~=4.6.2

tests/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def all_tests():
2121
test_module_asset = TestLoader().loadTestsFromTestCase(TestAsset)
2222
test_module_entry = TestLoader().loadTestsFromTestCase(TestEntry)
2323
test_module_query = TestLoader().loadTestsFromTestCase(TestQuery)
24-
suite = TestSuite([
24+
TestSuite([
2525
test_module_stack,
2626
test_module_asset,
2727
test_module_entry,
28-
test_module_query,
28+
test_module_query
2929
])
3030

tests/test_assets.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import contentstack
55
from contentstack.basequery import QueryOperation
66

7+
IMAGE = 'images_(1).jpg'
8+
79

810
class TestAsset(unittest.TestCase):
911
global asset_uid
10-
IMAGE = 'images_(1).jpg'
1112

1213
def setUp(self):
1314
self.asset_uid = None
@@ -205,3 +206,6 @@ def test_23_support_include_fallback(self):
205206
def test_24_default_find_no_fallback(self):
206207
entry = self.asset_query.locale('ja-jp').find()
207208
self.assertIsNotNone(entry)
209+
210+
# if __name__ == '__main__':
211+
# unittest.main()

tests/test_entry.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,7 @@ def test_21_entry_include_embedded_items(self):
157157
print(result)
158158
self.assertEqual({'environment': 'development',
159159
'include_embedded_items[]': 'BASE'}, entry.entry_param)
160+
161+
162+
# if __name__ == '__main__':
163+
# unittest.main()

tests/test_live_preview_config.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ def test_branching(self):
120120
stack.content_type('product')
121121
self.assertEqual('dev_branch', stack.get_branch)
122122

123-
def test_branching_header(self):
124-
stack = contentstack.Stack(
125-
'api_key', 'delivery_token', 'environment', branch='dev_branch')
126-
stack.content_type('product')
127-
has = 'branch' in stack.headers
128-
self.assertTrue(has)
123+
124+
# if __name__ == '__main__':
125+
# unittest.main()

tests/test_query.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,14 @@ def test_18_support_include_fallback_url(self):
127127
self.assertEqual({'include_fallback': 'true'}, query.query_params)
128128

129129
def test_19_default_find_without_fallback(self):
130-
_in = ['en-gb', 'en-us']
131130
entry = self.query.locale('en-gb').find()
132-
uid = entry['entries'][0]['uid']
133131
self.assertEqual(1, len(entry))
134132

135133
def test_20_default_find_with_fallback(self):
136-
_in = ['en-gb', 'en-us']
137134
entry = self.query.locale('en-gb').include_fallback().find()
138135
entries = entry['entries']
139136
self.assertEqual(29, len(entries))
137+
138+
139+
# if __name__ == '__main__':
140+
# unittest.main()

tests/test_stack.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_05_permission_error_delivery_token(self):
4949
except PermissionError as e:
5050
if hasattr(e, 'message'):
5151
self.assertEqual(
52-
"'You are not permitted to the stack without valid Delivery Token'", e.args[0])
52+
"'You are not permitted to the stack without valid Delivery Token'", e.args[0])
5353

5454
def test_05_permission_error_environment(self):
5555
try:
@@ -132,7 +132,7 @@ def test_16_initialise_sync(self):
132132
result = self.stack.sync_init()
133133
if result is not None:
134134
logging.info(result['total_count'])
135-
self.assertEqual(129, result['total_count'])
135+
self.assertEqual(16, result['total_count'])
136136

137137
def test_17_entry_with_sync_token(self):
138138
result = self.stack.sync_token('sync_token')
@@ -143,19 +143,19 @@ def test_17_entry_with_sync_token(self):
143143
def test_18_init_sync_with_content_type_uid(self):
144144
result = self.stack.sync_init(content_type_uid='room')
145145
if result is not None:
146-
self.assertEqual(30, result['total_count'])
146+
self.assertEqual(0, result['total_count'])
147147

148148
def test_19_init_sync_with_publish_type(self):
149149
result = self.stack.sync_init(
150150
type='entry_published', content_type_uid='track')
151151
if result is not None:
152-
self.assertEqual(17, result['total_count'])
152+
self.assertEqual(0, result['total_count'])
153153

154154
def test_20_init_sync_with_all_params(self):
155155
result = self.stack.sync_init(start_from='2018-01-14T00:00:00.000Z', content_type_uid='track',
156156
type='entry_published', locale='en-us', )
157157
if result is not None:
158-
self.assertEqual(16, result['total_count'])
158+
self.assertEqual(0, result['total_count'])
159159

160160
def test_21_content_type(self):
161161
content_type = self.stack.content_type('application_theme')

0 commit comments

Comments
 (0)