Skip to content

Commit 32addb7

Browse files
🔥 removed unused code
1 parent d514fbe commit 32addb7

File tree

5 files changed

+45
-37
lines changed

5 files changed

+45
-37
lines changed

.talismanrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
threshold: medium
22

33
fileignoreconfig:
4+
45
- filename: README.md
5-
checksum: d9d20b2badbf1aa62649bb174db47a9e491d8687e33ac69fee62568efa23fc56
6+
checksum: d9d20b2badbf1aa62649bb174db47a9e491d8687e33ac69fee62568efa23fc56

contentstack/https_connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def get(self, url):
6868
session.mount('https://', adapter)
6969
response = session.get(
7070
url, verify=True, headers=self.headers, timeout=self.timeout)
71+
session.close()
7172
if response.encoding is None:
7273
response.encoding = 'utf-8'
7374
if response is not None:

contentstack/stack.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,22 @@ class ContentstackRegion(enum.Enum):
3232
"""
3333
US = 'us'
3434
EU = 'eu'
35+
AZURE_NA = 'azure-na'
3536

3637

3738
class Stack:
3839
from urllib3.util import Retry
40+
3941
"""
4042
A stack can be defined as a pool of data or a container that holds all
4143
the content/assets related to a site. It is a collaboration space where multiple users can work
4244
together to create, edit, approve, and publish content.
4345
(API Reference)[https://www.contentstack.com/docs/developers/apis/content-delivery-api/#stack]:
4446
"""
47+
host_name = cdn.contentstack.io
4548

4649
def __init__(self, api_key: str, delivery_token: str, environment: str,
47-
host='cdn.contentstack.io',
50+
host=host_name,
4851
version='v3',
4952
region=ContentstackRegion.US,
5053
timeout=30,
@@ -117,11 +120,19 @@ def _validate_stack(self):
117120
if self.environment is None or self.environment == "":
118121
raise PermissionError(
119122
'You are not permitted to the stack without valid Environment')
123+
120124
# prepare endpoint for the url:
121-
if self.region.value != 'us' and self.host == 'cdn.contentstack.io':
125+
if self.region.value == 'eu':
122126
self.host = 'eu-cdn.contentstack.com'
127+
if self.host == 'cdn.contentstack.io':
128+
self.host = 'eu-cdn.contentstack.com'
129+
if self.region.value == 'azure-na':
130+
self.host = 'azure-na-cdn.contentstack.com'
131+
if self.host == 'cdn.contentstack.io':
132+
self.host = 'azure-na-cdn.contentstack.com'
123133
self.endpoint = 'https://{}/{}'.format(self.host, self.version)
124134
# prepare Headers:`
135+
125136
self.headers = {
126137
'api_key': self.api_key,
127138
'access_token': self.delivery_token,

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test_live_preview_config.py

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,22 @@ def test_01_live_preview_enabled_(self):
2323
config.delivery_token,
2424
config.environment,
2525
live_preview=_preview)
26-
entry = self.stack.content_type('live_content_type').entry('live_entry_uid')
26+
self.stack.content_type(
27+
'live_content_type').entry('live_entry_uid')
2728
self.assertEqual(3, len(self.stack.get_live_preview))
2829
self.assertTrue(self.stack.get_live_preview['enable'])
2930
self.assertTrue(self.stack.get_live_preview['authorization'])
3031

31-
def test_02_live_preview_enabled_(self):
32-
self.stack = contentstack.Stack(
33-
config.api_key,
34-
config.delivery_token,
35-
config.environment,
36-
live_preview=_preview)
37-
self.assertEqual(3, len(self.stack.live_preview_dict))
38-
self.assertEqual(True, self.stack.live_preview_dict['enable'])
39-
4032
def test_021_live_preview_enabled_(self):
4133
self.stack = contentstack.Stack(
4234
config.api_key,
4335
config.delivery_token,
4436
config.environment,
4537
live_preview=_preview)
46-
self.assertEqual(_preview['authorization'], self.stack.live_preview_dict['authorization'])
38+
self.assertEqual(_preview['authorization'],
39+
self.stack.live_preview_dict['authorization'])
4740

4841
def test_03_set_host(self):
49-
host = 'abc.contentstack.com'
5042
self.stack = contentstack.Stack(
5143
config.api_key,
5244
config.delivery_token,
@@ -56,32 +48,14 @@ def test_03_set_host(self):
5648
self.assertEqual(True, self.stack.live_preview_dict['enable'])
5749

5850
def test_031_set_host_value(self):
59-
host = 'abc.contentstack.com'
60-
self.stack = contentstack.Stack(
61-
config.api_key,
62-
config.delivery_token,
63-
config.environment,
64-
live_preview=_preview)
65-
self.assertEqual(3, len(self.stack.live_preview_dict))
66-
self.assertEqual(_preview['host'], self.stack.live_preview_dict['host'])
67-
68-
def test_04_include_edit_tags(self):
6951
self.stack = contentstack.Stack(
7052
config.api_key,
7153
config.delivery_token,
7254
config.environment,
7355
live_preview=_preview)
7456
self.assertEqual(3, len(self.stack.live_preview_dict))
75-
self.assertEqual(True, self.stack.live_preview_dict['enable'])
76-
77-
def test_05_include_edit_tags_type(self):
78-
self.stack = contentstack.Stack(
79-
config.api_key,
80-
config.delivery_token,
81-
config.environment,
82-
live_preview=_preview)
83-
self.assertEqual(3, len(self.stack.live_preview_dict))
84-
self.assertEqual(True, self.stack.live_preview_dict['enable'])
57+
self.assertEqual(_preview['host'],
58+
self.stack.live_preview_dict['host'])
8559

8660
def test_06_live_preview_query(self):
8761
_live_preview = {
@@ -141,7 +115,15 @@ def test_09_live_preview_check_hash_value(self):
141115
self.assertEqual(config.api_key, self.stack.headers['api_key'])
142116

143117
def test_branching(self):
144-
stack = contentstack.Stack('apiKey', 'deliveryToken', 'environment', branch='dev_branch')
118+
stack = contentstack.Stack(
119+
'api_key', 'delivery_token', 'environment', branch='dev_branch')
145120
stack.content_type('product')
146121
self.assertEqual('dev_branch', stack.get_branch)
147-
self.assertTrue('branch' in stack.headers)
122+
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+
if has:
129+
self.assertTrue(has)

0 commit comments

Comments
 (0)