Skip to content

Commit 256e270

Browse files
Added unit testcases
1 parent c4f1b22 commit 256e270

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

contentstack/asset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(self, http_instance, uid=None, logger=None):
1717
self.__uid = uid
1818
if self.__uid is None or self.__uid.strip() == 0:
1919
raise KeyError(ErrorMessages.INVALID_UID)
20+
self.uid = uid
2021
self.base_url = f'{self.http_instance.endpoint}/assets/{self.__uid}'
2122
if 'environment' in self.http_instance.headers:
2223
self.asset_params['environment'] = self.http_instance.headers['environment']

contentstack/entry.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ def environment(self, environment):
5454
self.http_instance.headers['environment'] = environment
5555
return self
5656

57+
def remove_environment(self):
58+
"""Removes environment from the request headers
59+
:return: Entry, so we can chain the call
60+
-------------------------------
61+
Example::
62+
63+
>>> import contentstack
64+
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
65+
>>> content_type = stack.content_type('content_type_uid')
66+
>>> entry = content_type.entry(uid='entry_uid')
67+
>>> entry = entry.environment('test')
68+
>>> entry = entry.remove_environment()
69+
>>> result = entry.fetch()
70+
-------------------------------
71+
"""
72+
if 'environment' in self.http_instance.headers:
73+
self.http_instance.headers.pop('environment')
74+
return self
75+
5776
def version(self, version):
5877
"""When no version is specified, it returns the latest version
5978
To retrieve a specific version, specify the version number under this parameter.
@@ -96,6 +115,9 @@ def param(self, key, value):
96115
"""
97116
if None in (key, value) and not isinstance(key, str):
98117
raise ValueError(ErrorMessages.INVALID_KEY_VALUE_ARGS)
118+
# Convert non-string values to strings
119+
if not isinstance(value, str):
120+
value = str(value)
99121
self.entry_param[key] = value
100122
return self
101123

0 commit comments

Comments
 (0)