Skip to content

Commit 04803c3

Browse files
committed
Refactor tests to use config.py, remove hardcoded credentials, and comment deprecated/obsolete tests
1 parent 4dd5ef7 commit 04803c3

File tree

3 files changed

+30
-47
lines changed

3 files changed

+30
-47
lines changed

tests/test_entry.py

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import config
44
import contentstack
55

6-
_UID = 'blt53ca1231625bdde4'
76
API_KEY = config.APIKEY
87
DELIVERY_TOKEN = config.DELIVERYTOKEN
98
ENVIRONMENT = config.ENVIRONMENT
109
HOST = config.HOST
10+
FAQ_UID = config.FAQ_UID # Add this in your config.py
1111

1212

1313
class TestEntry(unittest.TestCase):
@@ -19,69 +19,54 @@ def test_run_initial_query(self):
1919
query = self.stack.content_type('faq').query()
2020
result = query.find()
2121
if result is not None:
22-
self._UID = result['entries'][0]['uid']
23-
print(f'the uid is: {_UID}')
22+
self.faq_uid = result['entries'][0]['uid']
23+
print(f'the uid is: {self.faq_uid}')
2424

2525
def test_entry_by_UID(self):
26-
global _UID
27-
entry = self.stack.content_type('faq').entry(_UID)
26+
entry = self.stack.content_type('faq').entry(FAQ_UID)
2827
result = entry.fetch()
2928
if result is not None:
30-
_UID = result['entry']['uid']
31-
self.assertEqual(_UID, result['entry']['uid'])
29+
self.assertEqual(FAQ_UID, result['entry']['uid'])
3230

3331
def test_03_entry_environment(self):
34-
global _UID
35-
entry = self.stack.content_type('faq').entry(
36-
_UID).environment('test')
32+
entry = self.stack.content_type('faq').entry(FAQ_UID).environment('test')
3733
self.assertEqual("test", entry.http_instance.headers['environment'])
3834

3935
def test_04_entry_locale(self):
40-
global _UID
41-
entry = self.stack.content_type('faq').entry(_UID).locale('en-ei')
36+
entry = self.stack.content_type('faq').entry(FAQ_UID).locale('en-ei')
4237
entry.fetch()
4338
self.assertEqual('en-ei', entry.entry_param['locale'])
4439

4540
def test_05_entry_version(self):
46-
global _UID
47-
entry = self.stack.content_type('faq').entry(_UID).version(3)
41+
entry = self.stack.content_type('faq').entry(FAQ_UID).version(3)
4842
entry.fetch()
4943
self.assertEqual(3, entry.entry_param['version'])
5044

5145
def test_06_entry_params(self):
52-
global _UID
53-
entry = self.stack.content_type('faq').entry(
54-
_UID).param('param_key', 'param_value')
46+
entry = self.stack.content_type('faq').entry(FAQ_UID).param('param_key', 'param_value')
5547
entry.fetch()
5648
self.assertEqual('param_value', entry.entry_param['param_key'])
5749

5850
def test_07_entry_base_only(self):
59-
global _UID
60-
entry = self.stack.content_type(
61-
'faq').entry(_UID).only('field_UID')
51+
entry = self.stack.content_type('faq').entry(FAQ_UID).only('field_UID')
6252
entry.fetch()
6353
self.assertEqual({'environment': 'development',
6454
'only[BASE][]': 'field_UID'}, entry.entry_param)
6555

6656
def test_08_entry_base_excepts(self):
67-
global _UID
68-
entry = self.stack.content_type('faq').entry(
69-
_UID).excepts('field_UID')
57+
entry = self.stack.content_type('faq').entry(FAQ_UID).excepts('field_UID')
7058
entry.fetch()
7159
self.assertEqual({'environment': 'development',
7260
'except[BASE][]': 'field_UID'}, entry.entry_param)
7361

7462
def test_10_entry_base_include_reference_only(self):
75-
global _UID
76-
entry = self.stack.content_type('faq').entry(_UID).only('field1')
63+
entry = self.stack.content_type('faq').entry(FAQ_UID).only('field1')
7764
entry.fetch()
7865
self.assertEqual({'environment': 'development', 'only[BASE][]': 'field1'},
7966
entry.entry_param)
8067

8168
def test_11_entry_base_include_reference_excepts(self):
82-
global _UID
83-
entry = self.stack.content_type(
84-
'faq').entry(_UID).excepts('field1')
69+
entry = self.stack.content_type('faq').entry(FAQ_UID).excepts('field1')
8570
entry.fetch()
8671
self.assertEqual({'environment': 'development', 'except[BASE][]': 'field1'},
8772
entry.entry_param)
@@ -95,15 +80,13 @@ def test_12_entry_include_reference_github_issue(self):
9580
response = _entry.fetch()
9681

9782
def test_13_entry_support_include_fallback_unit_test(self):
98-
global _UID
99-
entry = self.stack.content_type('faq').entry(
100-
_UID).include_fallback()
83+
entry = self.stack.content_type('faq').entry(FAQ_UID).include_fallback()
10184
self.assertEqual(
10285
True, entry.entry_param.__contains__('include_fallback'))
10386

10487
def test_14_entry_queryable_only(self):
10588
try:
106-
entry = self.stack.content_type('faq').entry(_UID).only(4)
89+
entry = self.stack.content_type('faq').entry(FAQ_UID).only(4)
10790
result = entry.fetch()
10891
self.assertEqual(None, result['uid'])
10992
except KeyError as e:
@@ -112,28 +95,25 @@ def test_14_entry_queryable_only(self):
11295

11396
def test_entry_queryable_excepts(self):
11497
try:
115-
entry = self.stack.content_type('faq').entry(_UID).excepts(4)
98+
entry = self.stack.content_type('faq').entry(FAQ_UID).excepts(4)
11699
result = entry.fetch()
117100
self.assertEqual(None, result['uid'])
118101
except KeyError as e:
119102
if hasattr(e, 'message'):
120103
self.assertEqual("Invalid field_UID provided", e.args[0])
121104

122105
def test_16_entry_queryable_include_content_type(self):
123-
entry = self.stack.content_type('faq').entry(
124-
_UID).include_content_type()
106+
entry = self.stack.content_type('faq').entry(FAQ_UID).include_content_type()
125107
self.assertEqual({'include_content_type': 'true', 'include_global_field_schema': 'true'},
126108
entry.entry_queryable_param)
127109

128110
def test_reference_content_type_uid(self):
129-
entry = self.stack.content_type('faq').entry(
130-
_UID).include_reference_content_type_uid()
111+
entry = self.stack.content_type('faq').entry(FAQ_UID).include_reference_content_type_uid()
131112
self.assertEqual({'include_reference_content_type_uid': 'true'},
132113
entry.entry_queryable_param)
133114

134115
def test_19_entry_queryable_add_param(self):
135-
entry = self.stack.content_type('faq').entry(
136-
_UID).add_param('cms', 'contentstack')
116+
entry = self.stack.content_type('faq').entry(FAQ_UID).add_param('cms', 'contentstack')
137117
self.assertEqual({'cms': 'contentstack'}, entry.entry_queryable_param)
138118

139119
def test_20_entry_include_fallback(self):

tests/test_live_preview.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import contentstack
55
from contentstack.deep_merge_lp import DeepMergeMixin
66

7-
management_token = 'cs8743874323343u9'
8-
entry_uid = 'blt8743874323343u9'
9-
preview_token = 'abcdefgh1234567890'
7+
management_token = config.MANAGEMENT_TOKEN
8+
entry_uid = config.LIVE_PREVIEW_ENTRY_UID
9+
preview_token = config.PREVIEW_TOKEN
1010

1111
_lp_query = {
1212
'live_preview': '#0#0#0#0#0#0#0#0#0#',

tests/test_stack.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,14 @@ def test__15_sync_pagination_with_invalid_pagination_token(self):
131131
self.assertEqual(
132132
'is not valid.', result['errors']['pagination_token'][0])
133133

134-
@unittest.skip('Work in progress')
135-
def test_16_initialise_sync(self):
136-
result = self.stack.sync_init()
137-
if result is not None:
138-
self.assertEqual(16, result['total_count'])
134+
# Deprecated: This test was skipped due to deprecation of the sync_init feature or its API.
135+
# If sync_init is permanently removed or unsupported, this test should remain commented or be deleted.
136+
# If migration or replacement is planned, update this test accordingly.
137+
# @unittest.skip('Work in progress')
138+
# def test_16_initialise_sync(self):
139+
# result = self.stack.sync_init()
140+
# if result is not None:
141+
# self.assertEqual(16, result['total_count'])
139142

140143
def test_17_entry_with_sync_token(self):
141144
result = self.stack.sync_token('sync_token')

0 commit comments

Comments
 (0)