Skip to content

Commit fc124f5

Browse files
Merge pull request #55 from contentstack/feat/CS-42561_early_access
Added Early access feature
2 parents e704f27 + ad0e325 commit fc124f5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

contentstack/stack.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __init__(self, api_key: str, delivery_token: str, environment: str,
4040
total=5, backoff_factor=0, status_forcelist=[408, 429]),
4141
live_preview=None,
4242
branch=None,
43+
early_access = None,
4344
):
4445
"""
4546
# Class that wraps the credentials of the authenticated user. Think of
@@ -92,6 +93,7 @@ def __init__(self, api_key: str, delivery_token: str, environment: str,
9293
self.branch = branch
9394
self.retry_strategy = retry_strategy
9495
self.live_preview = live_preview
96+
self.early_access = early_access
9597
self._validate_stack()
9698

9799
def _validate_stack(self):
@@ -123,6 +125,9 @@ def _validate_stack(self):
123125
'access_token': self.delivery_token,
124126
'environment': self.environment
125127
}
128+
if self.early_access is not None:
129+
early_access_str = ', '.join(self.early_access)
130+
self.headers['x-header-ea'] = early_access_str
126131

127132
if self.branch is not None:
128133
self.headers['branch'] = self.branch
@@ -141,6 +146,13 @@ def get_api_key(self):
141146
:return: api_key of the stack
142147
"""
143148
return self.api_key
149+
150+
@property
151+
def get_early_access(self):
152+
"""
153+
:return: early access
154+
"""
155+
return self.early_access
144156

145157
@property
146158
def get_delivery_token(self):

tests/test_stack.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class TestStack(unittest.TestCase):
1515

1616
def setUp(self):
1717
self.stack = contentstack.Stack(API_KEY, DELIVERY_TOKEN, ENVIRONMENT, host=HOST)
18+
self.early_access = ['taxonomy', 'teams']
1819

1920
def test_01_stack_credentials(self):
2021
self.assertEqual(ENVIRONMENT, stack_instance.environment)
@@ -167,3 +168,13 @@ def test_check_region(self):
167168
host=config.HOST, region=ContentstackRegion.AZURE_NA)
168169
var = _stack.region.value
169170
self.assertEqual('azure-na', var)
171+
172+
def test_22_check_early_access_headers(self):
173+
stack = contentstack.Stack(
174+
config.APIKEY, config.DELIVERYTOKEN, config.ENVIRONMENT, early_access=[])
175+
self.assertEqual(True, 'x-header-ea' in stack.get_headers)
176+
177+
def test_23_get_early_access(self):
178+
stack = contentstack.Stack(
179+
config.APIKEY, config.DELIVERYTOKEN, config.ENVIRONMENT, early_access=["taxonomy", "teams"])
180+
self.assertEqual(self.early_access, stack.get_early_access)

0 commit comments

Comments
 (0)