Skip to content

Commit faf700d

Browse files
Added coverage reports generartion in github action
Added coverage report github action Changed methods name Changed unit test cases Code improvements API Documentation
1 parent 55eaf55 commit faf700d

File tree

15 files changed

+158
-141
lines changed

15 files changed

+158
-141
lines changed

.github/workflows/unit-test.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Pytest Workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
coverage-report:
13+
strategy:
14+
matrix:
15+
python-version:
16+
- 3.9
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- uses: actions/setup-python@v2
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
- name: Install build dependencies
24+
run: pip install --upgrade setuptools
25+
- name: Install dot env
26+
run: pip install python-dotenv
27+
- name: Install requests
28+
run: pip install requests
29+
- uses: lpenz/ghaction-pytest-cov@v1
30+
- uses: AndreMiras/coveralls-python-action@v20201129
31+
with:
32+
parallel: true
33+
flag-name: python-${{ matrix.python-version }}
34+
github-token: ${{ secrets.GITHUB_TOKEN }}
35+
36+
37+
coverage-finish:
38+
needs: coverage-report
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: AndreMiras/coveralls-python-action@v20201129
42+
with:
43+
parallel-finished: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,4 @@ tests/resources/.DS_Store
136136
tests/.DS_Store
137137
tests/resources/.DS_Store
138138
.DS_Store
139+
.talismanrc

.talismanrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,13 @@ fileignoreconfig:
4848
checksum: a2ba35250e069e789f11e40efa7c1b2786f5db6899497643b5bf3a0e344d13e9
4949
- filename: contentstack_management/stack/stack.py
5050
checksum: f1b63294922e19f41dbf30caa6cbefe381b0c8834950d94dad7c7a28dd707047
51+
version: ""
52+
53+
fileignoreconfig:
54+
- filename: contentstack_management/organizations/organizations.py
55+
checksum: 31dc00bc449f8a9e5cb9321da10384dd7d40bd8fce30e56699e0ce0a0e3de48e
56+
- filename: contentstack_management/users/user.py
57+
checksum: 1aa5ed251d166293e2616c6a227ee945a8213c5fde03778db08abac5f1a09c72
58+
- filename: tests/stack/test_stack_unittest.py
59+
checksum: 12389c99db0d917954cd9970b340cc443602b4acf512090f42d13f7a726c85b6
5160
version: ""

contentstack_management/organizations/organizations.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ def __init__(self, endpoint, authtoken, headers, api_client, organization_uid):
1515
self.authtoken = authtoken
1616
self.headers = headers
1717
self.organization_uid = organization_uid
18+
self.headers['authtoken'] = self.authtoken
1819

1920

20-
def get(self):
21+
def find(self):
2122
"""
22-
Fetches the organizations entries
23+
Finds the organizations entries
2324
:return: Json, with organizations details.
2425
-------------------------------
2526
[Example:]
@@ -28,21 +29,30 @@ def get(self):
2829
>>> client = contentstack.client(host='HOST NAME')
2930
>>> client.login(email="email_id", password="password")
3031
>>> result = client.organizations().get().json()
32+
-------------------------------
33+
"""
34+
url = "organizations"
35+
return self.api_client.get(url, headers = self.headers)
36+
37+
def fetch(self):
38+
"""
39+
Fetches the organizations entry
40+
:return: Json, with organizations details.
41+
-------------------------------
42+
[Example:]
3143
44+
>>> from contentstack_management import contentstack
45+
>>> client = contentstack.client(host='HOST NAME')
46+
>>> client.login(email="email_id", password="password")
3247
>>> result = client.organizations('ORG_UID').get().json()
3348
3449
-------------------------------
3550
"""
36-
url = "organizations"
37-
if self.organization_uid is None:
38-
url = "organizations"
39-
else:
40-
url = f"organizations/{self.organization_uid}"
41-
self.headers['authtoken'] = self.authtoken
51+
url = f"organizations/{self.organization_uid}"
4252
return self.api_client.get(url, headers = self.headers)
4353

4454

45-
def get_organization_roles(self):
55+
def roles(self):
4656
"""
4757
Fetches the organization roles entries
4858
:return: Json, with organization role details.
@@ -57,11 +67,10 @@ def get_organization_roles(self):
5767
-------------------------------
5868
"""
5969
url = f"organizations/{self.organization_uid}/roles"
60-
self.headers['authtoken'] = self.authtoken
6170
return self.api_client.get(url, headers = self.headers)
6271

6372

64-
def organization_add_users(self, user_data):
73+
def add_users(self, user_data):
6574
"""
6675
Add user to the organization
6776
:return: Json, with user details.
@@ -94,11 +103,10 @@ def organization_add_users(self, user_data):
94103
-------------------------------
95104
"""
96105
url = f"organizations/{self.organization_uid}/share"
97-
self.headers['authtoken'] = self.authtoken
98106
data = json.dumps(user_data)
99107
return self.api_client.post(url, headers = self.headers, data = data)
100108

101-
def transfer_organizations_ownership(self, data):
109+
def transfer_ownership(self, data):
102110
"""
103111
Add user to the organization
104112
:return: Json, with user details.
@@ -117,12 +125,11 @@ def transfer_organizations_ownership(self, data):
117125
"""
118126

119127
url = f"organizations/{self.organization_uid}/transfer-ownership"
120-
self.headers['authtoken'] = self.authtoken
121128
data = json.dumps(data)
122129
return self.api_client.post(url, headers = self.headers, data = data)
123130

124131

125-
def organization_stacks(self):
132+
def stacks(self):
126133
"""
127134
Fetches the organization stacks
128135
:return: Json, with organization stack details.
@@ -137,11 +144,10 @@ def organization_stacks(self):
137144
-------------------------------
138145
"""
139146
url = f"organizations/{self.organization_uid}/stacks"
140-
self.headers['authtoken'] = self.authtoken
141147
return self.api_client.get(url, headers = self.headers)
142148

143149

144-
def organization_logs(self):
150+
def logs(self):
145151
"""
146152
Fetches the organization log entries
147153
:return: Json, with organization log details.
@@ -156,6 +162,5 @@ def organization_logs(self):
156162
-------------------------------
157163
"""
158164
url = f"organizations/{self.organization_uid}/logs"
159-
self.headers['authtoken'] = self.authtoken
160165
return self.api_client.get(url, headers = self.headers)
161166

contentstack_management/stack/stack.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def __init__(self, endpoint, authtoken, headers, api_client, api_key):
2020
self.authtoken = authtoken
2121
self.headers = headers
2222
self.api_key = api_key
23+
self.headers['authtoken'] = self.authtoken
2324

2425
def fetch(self):
2526
"""
@@ -36,11 +37,10 @@ def fetch(self):
3637
-------------------------------
3738
"""
3839
url = "stacks"
39-
self.headers['authtoken'] = self.authtoken
4040
self.headers['api_key'] = self.api_key
4141
return self.api_client.get(url, headers = self.headers)
4242

43-
def fetch_all(self):
43+
def find(self):
4444

4545
"""
4646
Fetches the stacks entries
@@ -57,7 +57,6 @@ def fetch_all(self):
5757
"""
5858

5959
url = "stacks"
60-
self.headers['authtoken'] = self.authtoken
6160
return self.api_client.get(url, headers = self.headers)
6261

6362
def create(self, organization_uid, data):
@@ -81,7 +80,7 @@ def create(self, organization_uid, data):
8180
-------------------------------
8281
"""
8382
url = "stacks"
84-
self.headers['authtoken'] = self.authtoken
83+
8584
self.headers['organization_uid'] = organization_uid
8685
data = json.dumps(data)
8786
return self.api_client.post(url, headers = self.headers, data=data)
@@ -107,7 +106,6 @@ def update(self, data):
107106
-------------------------------
108107
"""
109108
url = "stacks"
110-
self.headers['authtoken'] = self.authtoken
111109
self.headers['api_key'] = self.api_key
112110
data = json.dumps(data)
113111
return self.api_client.put(url, headers = self.headers, data=data)
@@ -129,11 +127,10 @@ def delete(self):
129127
"""
130128

131129
url = "stacks"
132-
self.headers['authtoken'] = self.authtoken
133130
self.headers['api_key'] = self.api_key
134131
return self.api_client.delete(url, headers = self.headers)
135132

136-
def fetch_all_user(self):
133+
def users(self):
137134
"""
138135
Fetches the all users of a stack
139136
:return: Json, with users of a stack details.
@@ -149,7 +146,6 @@ def fetch_all_user(self):
149146
"""
150147

151148
url = "stacks/users"
152-
self.headers['authtoken'] = self.authtoken
153149
self.headers['api_key'] = self.api_key
154150
return self.api_client.get(url, headers = self.headers)
155151

@@ -172,12 +168,11 @@ def update_user_role(self, data):
172168
-------------------------------
173169
"""
174170
url = "stacks/users/roles"
175-
self.headers['authtoken'] = self.authtoken
176171
self.headers['api_key'] = self.api_key
177172
data = json.dumps(data)
178173
return self.api_client.put(url, headers = self.headers, data=data)
179174

180-
def stack_transfer_ownership(self, data):
175+
def transfer_ownership(self, data):
181176
"""
182177
Transfer owership of the stacks
183178
:return: Json, with status code and message.
@@ -194,7 +189,6 @@ def stack_transfer_ownership(self, data):
194189
-------------------------------
195190
"""
196191
url = "stacks/transfer_ownership"
197-
self.headers['authtoken'] = self.authtoken
198192
self.headers['api_key'] = self.api_key
199193
data = json.dumps(data)
200194
return self.api_client.post(url, headers = self.headers, data=data)
@@ -214,11 +208,10 @@ def accept_ownership(self, user_id, ownership_token):
214208
-------------------------------
215209
"""
216210
url = f"stacks/accept_ownership/{ownership_token}"
217-
self.headers['authtoken'] = self.authtoken
218211
params = {'api_key': self.api_key, 'uid': user_id}
219212
return self.api_client.get(url, headers = self.headers, params = params)
220213

221-
def get_stack_settings(self):
214+
def settings(self):
222215
"""
223216
Fetches the stack settings
224217
:return: Json, with stack settings details.
@@ -233,12 +226,11 @@ def get_stack_settings(self):
233226
-------------------------------
234227
"""
235228
url = "stacks/settings"
236-
self.headers['authtoken'] = self.authtoken
237229
self.headers['api_key'] = self.api_key
238230
return self.api_client.get(url, headers = self.headers)
239231

240232

241-
def create_stack_settings(self, data):
233+
def create_settings(self, data):
242234
"""
243235
Create the stack settings
244236
:return: Json, with stack setting details.
@@ -264,12 +256,11 @@ def create_stack_settings(self, data):
264256
-------------------------------
265257
"""
266258
url = "stacks/settings"
267-
self.headers['authtoken'] = self.authtoken
268259
self.headers['api_key'] = self.api_key
269260
data = json.dumps(data)
270261
return self.api_client.post(url, headers = self.headers, data=data)
271262

272-
def reset_stack_settings(self, data):
263+
def reset_settings(self, data):
273264
"""
274265
Reset the stack settings
275266
:return: Json, with stack setting details.
@@ -286,12 +277,11 @@ def reset_stack_settings(self, data):
286277
-------------------------------
287278
"""
288279
url = "stacks/settings/reset"
289-
self.headers['authtoken'] = self.authtoken
290280
self.headers['api_key'] = self.api_key
291281
data = json.dumps(data)
292282
return self.api_client.post(url, headers = self.headers, data=data)
293283

294-
def share_stack(self, data):
284+
def share(self, data):
295285
"""
296286
Share a stack to the users with user roles
297287
:return: Json, with status code and message
@@ -315,12 +305,11 @@ def share_stack(self, data):
315305
-------------------------------
316306
"""
317307
url = "stacks/share"
318-
self.headers['authtoken'] = self.authtoken
319308
self.headers['api_key'] = self.api_key
320309
data = json.dumps(data)
321310
return self.api_client.post(url, headers = self.headers, data=data)
322311

323-
def unshare_stack(self, data):
312+
def unshare(self, data):
324313
"""
325314
Unshare a stack to the users with user roles
326315
:return: Json, with status code and message
@@ -337,7 +326,6 @@ def unshare_stack(self, data):
337326
-------------------------------
338327
"""
339328
url = "stacks/unshare"
340-
self.headers['authtoken'] = self.authtoken
341329
self.headers['api_key'] = self.api_key
342330
data = json.dumps(data)
343331
return self.api_client.post(url, headers = self.headers, data=data)

0 commit comments

Comments
 (0)