|
3 | 3 | import config |
4 | 4 | import contentstack |
5 | 5 |
|
6 | | -_uid = 'blt53ca1231625bdde4' |
7 | | -api_key = config.api_key |
8 | | -delivery_token = config.delivery_token |
9 | | -environment = config.environment |
10 | | -env_host = config.host |
| 6 | +_UID = 'blt53ca1231625bdde4' |
| 7 | +API_KEY = config.APIKEY |
| 8 | +DELIVERY_TOKEN = config.DELIVERYTOKEN |
| 9 | +ENVIRONMENT = config.ENVIRONMENT |
| 10 | +HOST = config.HOST |
11 | 11 |
|
12 | 12 |
|
13 | 13 | class TestEntry(unittest.TestCase): |
14 | 14 |
|
15 | 15 | def setUp(self): |
16 | | - self.stack = contentstack.Stack(api_key, delivery_token, environment, host=env_host) |
| 16 | + self.stack = contentstack.Stack(API_KEY, DELIVERY_TOKEN, ENVIRONMENT, host=HOST) |
17 | 17 |
|
18 | 18 | def test_run_initial_query(self): |
19 | 19 | query = self.stack.content_type('faq').query() |
20 | 20 | result = query.find() |
21 | | - global _uid |
| 21 | + global _UID |
22 | 22 | if result is not None: |
23 | | - _uid = result['entries'][0]['uid'] |
24 | | - print(f'the uid is: {_uid}') |
| 23 | + _UID = result['entries'][0]['uid'] |
| 24 | + print(f'the uid is: {_UID}') |
25 | 25 |
|
26 | | - def test_entry_by_uid(self): |
27 | | - global _uid |
28 | | - entry = self.stack.content_type('faq').entry(_uid) |
| 26 | + def test_entry_by_UID(self): |
| 27 | + global _UID |
| 28 | + entry = self.stack.content_type('faq').entry(_UID) |
29 | 29 | result = entry.fetch() |
30 | 30 | if result is not None: |
31 | | - _uid = result['entry']['uid'] |
32 | | - self.assertEqual(_uid, result['entry']['uid']) |
| 31 | + _UID = result['entry']['uid'] |
| 32 | + self.assertEqual(_UID, result['entry']['uid']) |
33 | 33 |
|
34 | 34 | def test_03_entry_environment(self): |
35 | | - global _uid |
| 35 | + global _UID |
36 | 36 | entry = self.stack.content_type('faq').entry( |
37 | | - _uid).environment('test') |
| 37 | + _UID).environment('test') |
38 | 38 | self.assertEqual("test", entry.http_instance.headers['environment']) |
39 | 39 |
|
40 | 40 | def test_04_entry_locale(self): |
41 | | - global _uid |
42 | | - entry = self.stack.content_type('faq').entry(_uid).locale('en-ei') |
| 41 | + global _UID |
| 42 | + entry = self.stack.content_type('faq').entry(_UID).locale('en-ei') |
43 | 43 | entry.fetch() |
44 | 44 | self.assertEqual('en-ei', entry.entry_param['locale']) |
45 | 45 |
|
46 | 46 | def test_05_entry_version(self): |
47 | | - global _uid |
48 | | - entry = self.stack.content_type('faq').entry(_uid).version(3) |
| 47 | + global _UID |
| 48 | + entry = self.stack.content_type('faq').entry(_UID).version(3) |
49 | 49 | entry.fetch() |
50 | 50 | self.assertEqual(3, entry.entry_param['version']) |
51 | 51 |
|
52 | 52 | def test_06_entry_params(self): |
53 | | - global _uid |
| 53 | + global _UID |
54 | 54 | entry = self.stack.content_type('faq').entry( |
55 | | - _uid).param('param_key', 'param_value') |
| 55 | + _UID).param('param_key', 'param_value') |
56 | 56 | entry.fetch() |
57 | 57 | self.assertEqual('param_value', entry.entry_param['param_key']) |
58 | 58 |
|
59 | 59 | def test_07_entry_base_only(self): |
60 | | - global _uid |
| 60 | + global _UID |
61 | 61 | entry = self.stack.content_type( |
62 | | - 'faq').entry(_uid).only('field_uid') |
| 62 | + 'faq').entry(_UID).only('field_UID') |
63 | 63 | entry.fetch() |
64 | 64 | self.assertEqual({'environment': 'development', |
65 | | - 'only[BASE][]': 'field_uid'}, entry.entry_param) |
| 65 | + 'only[BASE][]': 'field_UID'}, entry.entry_param) |
66 | 66 |
|
67 | 67 | def test_08_entry_base_excepts(self): |
68 | | - global _uid |
| 68 | + global _UID |
69 | 69 | entry = self.stack.content_type('faq').entry( |
70 | | - _uid).excepts('field_uid') |
| 70 | + _UID).excepts('field_UID') |
71 | 71 | entry.fetch() |
72 | 72 | self.assertEqual({'environment': 'development', |
73 | | - 'except[BASE][]': 'field_uid'}, entry.entry_param) |
| 73 | + 'except[BASE][]': 'field_UID'}, entry.entry_param) |
74 | 74 |
|
75 | 75 | def test_10_entry_base_include_reference_only(self): |
76 | | - global _uid |
77 | | - entry = self.stack.content_type('faq').entry(_uid).only('field1') |
| 76 | + global _UID |
| 77 | + entry = self.stack.content_type('faq').entry(_UID).only('field1') |
78 | 78 | entry.fetch() |
79 | 79 | self.assertEqual({'environment': 'development', 'only[BASE][]': 'field1'}, |
80 | 80 | entry.entry_param) |
81 | 81 |
|
82 | 82 | def test_11_entry_base_include_reference_excepts(self): |
83 | | - global _uid |
| 83 | + global _UID |
84 | 84 | entry = self.stack.content_type( |
85 | | - 'faq').entry(_uid).excepts('field1') |
| 85 | + 'faq').entry(_UID).excepts('field1') |
86 | 86 | entry.fetch() |
87 | 87 | self.assertEqual({'environment': 'development', 'except[BASE][]': 'field1'}, |
88 | 88 | entry.entry_param) |
89 | 89 |
|
90 | 90 | def test_12_entry_include_reference_github_issue(self): |
91 | 91 | stack_for_products = contentstack.Stack( |
92 | | - "api_key", "delivery_token", "environment") |
| 92 | + "API_KEY", "DELIVERY_TOKEN", "ENVIRONMENT") |
93 | 93 | _entry = stack_for_products.content_type('product').entry("ENTRY_UI").include_reference( |
94 | 94 | ["categories", |
95 | 95 | "brand"]) |
96 | 96 | response = _entry.fetch() |
97 | | - # print(response) |
| 97 | + print(response) |
98 | 98 | # categories = response['entry']['categories'] |
99 | 99 | # self.assertEqual(2, len(categories)) |
100 | 100 |
|
101 | 101 | def test_13_entry_support_include_fallback_unit_test(self): |
102 | | - global _uid |
| 102 | + global _UID |
103 | 103 | entry = self.stack.content_type('faq').entry( |
104 | | - _uid).include_fallback() |
| 104 | + _UID).include_fallback() |
105 | 105 | self.assertEqual( |
106 | 106 | True, entry.entry_param.__contains__('include_fallback')) |
107 | 107 |
|
108 | 108 | def test_14_entry_queryable_only(self): |
109 | 109 | try: |
110 | | - entry = self.stack.content_type('faq').entry(_uid).only(4) |
| 110 | + entry = self.stack.content_type('faq').entry(_UID).only(4) |
111 | 111 | result = entry.fetch() |
112 | 112 | self.assertEqual(None, result['uid']) |
113 | 113 | except KeyError as e: |
114 | 114 | if hasattr(e, 'message'): |
115 | | - self.assertEqual("Invalid field_uid provided", e.args[0]) |
| 115 | + self.assertEqual("Invalid field_UID provided", e.args[0]) |
116 | 116 |
|
117 | | - def test_15_entry_queryable_excepts(self): |
| 117 | + def test_entry_queryable_excepts(self): |
118 | 118 | try: |
119 | | - entry = self.stack.content_type('faq').entry(_uid).excepts(4) |
| 119 | + entry = self.stack.content_type('faq').entry(_UID).excepts(4) |
120 | 120 | result = entry.fetch() |
121 | 121 | self.assertEqual(None, result['uid']) |
122 | 122 | except KeyError as e: |
123 | 123 | if hasattr(e, 'message'): |
124 | | - self.assertEqual("Invalid field_uid provided", e.args[0]) |
| 124 | + self.assertEqual("Invalid field_UID provided", e.args[0]) |
125 | 125 |
|
126 | 126 | def test_16_entry_queryable_include_content_type(self): |
127 | 127 | entry = self.stack.content_type('faq').entry( |
128 | | - _uid).include_content_type() |
| 128 | + _UID).include_content_type() |
129 | 129 | self.assertEqual({'include_content_type': 'true', 'include_global_field_schema': 'true'}, |
130 | 130 | entry.entry_queryable_param) |
131 | 131 |
|
132 | | - def test_18_entry_queryable_include_reference_content_type_uid(self): |
| 132 | + def test_reference_content_type_uid(self): |
133 | 133 | entry = self.stack.content_type('faq').entry( |
134 | | - _uid).include_reference_content_type_uid() |
| 134 | + _UID).include_reference_content_type_uid() |
135 | 135 | self.assertEqual({'include_reference_content_type_uid': 'true'}, |
136 | 136 | entry.entry_queryable_param) |
137 | 137 |
|
138 | 138 | def test_19_entry_queryable_add_param(self): |
139 | 139 | entry = self.stack.content_type('faq').entry( |
140 | | - _uid).add_param('cms', 'contentstack') |
| 140 | + _UID).add_param('cms', 'contentstack') |
141 | 141 | self.assertEqual({'cms': 'contentstack'}, entry.entry_queryable_param) |
142 | 142 |
|
143 | 143 | def test_20_entry_include_fallback(self): |
|
0 commit comments