Skip to content

Commit

Permalink
Next (#26)
Browse files Browse the repository at this point in the history
* Added users and organisations api methods

User Session

Logging in/out

Users

Get User

Update User

Activate User

Request Password

Reset Password

Organizations

Get All Organizations

Get Single Organization

Organization Roles

Organization Users

Transfer Organization Ownership

Organization Stacks

Organization Logs

* added requirements.txt file

* loaded install, changlog , codeowners and release.yml file

* Organized package structure

* Developed stack Implementation

* Code Optimized

* Added Mock test and Api Test cases

* Added test cases and coverage packages

* Added API documentation and added stacks test cases

* Added coverage reports generartion in github action

Added coverage report github action
Changed methods name
Changed unit test cases
Code improvements
API Documentation

* Added global fields class

* - General code improvements
- Corrected few testcases
- Single place for credentials
- linting added

* Feat/cs 40287 workflow class implemetation (#14)

* feat: ✨ implemented branches and aliases with unit and api test cases

* test: ✅ added mock tests for branches and aliases

* docs: 📝 added api documentation for branches and aliases

* feat: ✨ content type implementation with api references, unit test cases and api test cases

* test: renamed the api, mock, unit test file names of branch and alias

* test: renamed file path in branch and alias mock tests

* test: improved coverage report for branches and aliases

* test: Added mock test cases for content type

* docs: 📝 Cleared typo errors

* test: removed unwanted test files

* refactor: Code improvement for branches, aliases and content type implementation

* - General code improvements
- Testcases improvements

* - General code improvements
- Testcases improvements

* - General code improvements
- Formats are updated

* code enhancement

* Created Entry class and test cases

Created Entry Class
created entry class test cases

* feat: ✨ asset class implementation with tests and api docs

* Code improvements and changed test cases to new structure

* test: ✅ added resources and made some changes in api and unit test cases

* Updated Unit test cases.

* Webhook class Implementation

* Created workflow class

* Deleted secrets-scan.yml file

* Updated variable name

* Deleted sast-scan.yml file

* Feat/cs 40545 metadata class implemetation (#15)

* Metadata class implementation

* Deleted sast-scan.yml file

* Fixed PR comments

* Code optimisation and handling custom error exception

* Removed uids

* Feat/cs 40549 roles class implementation (#16)

* Created roles class with unit testcases, mock test cases and api test cases

* Updated coverage report github workflow file

* Added coverage install command

* Added pytest install command

* Updated stack class unit test file

* Added html coverage

* Added coverage reports and visualizations

* Removed visualisation

* Generating coverage report in svg format

* Added coverage-badge  install command

* Fixed PR comments and code optimisation

* Added coverage reports graphical visualisation in github page

* Created readme file

* changed variable name

* Updated readme file

* Update README.md

* Added auditlog class and license file (#17)

* Added auditlog class and license file

* Added test case for invalid inputs

* commented the idiom

It Allows You to Execute Code When the File Runs as a Script, but Not When It’s Imported as a Module

---------

Co-authored-by: Shailesh Mishra <[email protected]>

---------

Co-authored-by: Shailesh Mishra <[email protected]>

* Developed environment class implementation (#19)

* Developed environment class implementation

* Updated variable name

* Added CI-CD implementation (#20)

* Added CI-CD implementation

Added CICD implemetation
Updated code Optimization
Updated code for check package in test environment.

* Removed Unused files

* Feat/cs 41198 locale class implementation (#21)

* Added locale class implementation

* Implemented  taxonomy support (#22)

---------

Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: Shailesh Mishra <[email protected]>
Co-authored-by: Shailesh Mishra <[email protected]>

* Feat/cs 41199 label class implementation (#25)

* Next (#23)

* Added users and organisations api methods

User Session

Logging in/out

Users

Get User

Update User

Activate User

Request Password

Reset Password

Organizations

Get All Organizations

Get Single Organization

Organization Roles

Organization Users

Transfer Organization Ownership

Organization Stacks

Organization Logs

* added requirements.txt file

* loaded install, changlog , codeowners and release.yml file

* Organized package structure

* Developed stack Implementation

* Code Optimized

* Added Mock test and Api Test cases

* Added test cases and coverage packages

* Added API documentation and added stacks test cases

* Added coverage reports generartion in github action

Added coverage report github action
Changed methods name
Changed unit test cases
Code improvements
API Documentation

* Added global fields class

* - General code improvements
- Corrected few testcases
- Single place for credentials
- linting added

* Feat/cs 40287 workflow class implemetation (#14)

* feat: ✨ implemented branches and aliases with unit and api test cases

* test: ✅ added mock tests for branches and aliases

* docs: 📝 added api documentation for branches and aliases

* feat: ✨ content type implementation with api references, unit test cases and api test cases

* test: renamed the api, mock, unit test file names of branch and alias

* test: renamed file path in branch and alias mock tests

* test: improved coverage report for branches and aliases

* test: Added mock test cases for content type

* docs: 📝 Cleared typo errors

* test: removed unwanted test files

* refactor: Code improvement for branches, aliases and content type implementation

* - General code improvements
- Testcases improvements

* - General code improvements
- Testcases improvements

* - General code improvements
- Formats are updated

* code enhancement

* Created Entry class and test cases

Created Entry Class
created entry class test cases

* feat: ✨ asset class implementation with tests and api docs

* Code improvements and changed test cases to new structure

* test: ✅ added resources and made some changes in api and unit test cases

* Updated Unit test cases.

* Webhook class Implementation

* Created workflow class

* Deleted secrets-scan.yml file

* Updated variable name

* Deleted sast-scan.yml file

* Feat/cs 40545 metadata class implemetation (#15)

* Metadata class implementation

* Deleted sast-scan.yml file

* Fixed PR comments

* Code optimisation and handling custom error exception

* Removed uids

* Feat/cs 40549 roles class implementation (#16)

* Created roles class with unit testcases, mock test cases and api test cases

* Updated coverage report github workflow file

* Added coverage install command

* Added pytest install command

* Updated stack class unit test file

* Added html coverage

* Added coverage reports and visualizations

* Removed visualisation

* Generating coverage report in svg format

* Added coverage-badge  install command

* Fixed PR comments and code optimisation

* Added coverage reports graphical visualisation in github page

* Created readme file

* changed variable name

* Updated readme file

* Update README.md

* Added auditlog class and license file (#17)

* Added auditlog class and license file

* Added test case for invalid inputs

* commented the idiom

It Allows You to Execute Code When the File Runs as a Script, but Not When It’s Imported as a Module

---------

Co-authored-by: Shailesh Mishra <[email protected]>

---------

Co-authored-by: Shailesh Mishra <[email protected]>

* Developed environment class implementation (#19)

* Developed environment class implementation

* Updated variable name

* Added CI-CD implementation (#20)

* Added CI-CD implementation

Added CICD implemetation
Updated code Optimization
Updated code for check package in test environment.

* Removed Unused files

* Feat/cs 41198 locale class implementation (#21)

* Added locale class implementation

* Implemented  taxonomy support (#22)

---------

Co-authored-by: harshithad0703 <[email protected]>
Co-authored-by: Shailesh Mishra <[email protected]>
Co-authored-by: Shailesh Mishra <[email protected]>

---------

Co-authored-by: Shailesh Mishra <[email protected]>
Co-authored-by: Shailesh Mishra <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>

* Deleted .idea directory (#24)

* Deleted .idea directory

* Deleted Test apidoc files

* Deleted coverage.txt file

* Created label class implementation

* Updated document data

---------

Co-authored-by: Shailesh Mishra <[email protected]>
Co-authored-by: Shailesh Mishra <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>

---------

Co-authored-by: Shailesh Mishra <[email protected]>
Co-authored-by: Shailesh Mishra <[email protected]>
Co-authored-by: harshithad0703 <[email protected]>
  • Loading branch information
4 people authored Sep 15, 2023
1 parent 5adc180 commit 839a041
Show file tree
Hide file tree
Showing 20 changed files with 2,363 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .idea/contentstack-management-python.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,13 @@ fileignoreconfig:
- filename: tests/unit/taxonomies/test_taxonomy_unit.py
checksum: 5dd2f73f683c293f71fd9002148747a7167a85981d6fb90e491cafddf7b96169
version: ""

fileignoreconfig:
- filename: tests/unit/labels/test_label_unit.py
checksum: 6fbb2a05402d94988e585dd48ee8881416d19340134a89088f9884533a6218d1
- filename: tests/api/labels/test_labels_api.py
checksum: 1111ead97107bf5348adb0fa2457ec5c4182278865d7e461bf2a42c90ef71588
- filename: tests/mock/labels/test_labels_mock.py
checksum: 069ee74fe19848e7a5bc4510772c389421e03956c31ce8347f93cb67b7f16847
version: ""

1,824 changes: 1,824 additions & 0 deletions apidoc/Test Results - .html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions contentstack_management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from ._errors import ArgumentException
from .locale.locale import Locale
from .taxonomies.taxonomy import Taxonomy
from .labels.label import Label


__all__ = (
"ContentstackClient",
Expand All @@ -47,6 +49,7 @@
"Entry",
"Locale",
"Taxonomy",
"Label",
)

__title__ = 'contentstack-management-python'
Expand Down
1 change: 1 addition & 0 deletions contentstack_management/labels/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from contentstack_management import contentstack
171 changes: 171 additions & 0 deletions contentstack_management/labels/label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
"""This class takes a base URL as an argument when it's initialized,
which is the endpoint for the RESTFUL API that we'll be interacting with.
The create(), read(), update(), and delete() methods each correspond to
the CRUD operations that can be performed on the API """

import json
from ..common import Parameter
from urllib.parse import quote
from .._errors import ArgumentException

class Label(Parameter):
"""
This class takes a base URL as an argument when it's initialized,
which is the endpoint for the RESTFUL API that
we'll be interacting with. The create(), read(), update(), and delete()
methods each correspond to the CRUD
operations that can be performed on the API """

def __init__(self, client, label_uid: str):
self.client = client
self.label_uid = label_uid
super().__init__(self.client)

self.path = "labels"

def find(self):
"""
The Find label call fetches all the existing labels of the stack.
:return: Json, with label details.
-------------------------------
[Example:]
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = client.stack("api_key").label().find().json()
-------------------------------
"""
return self.client.get(self.path, headers = self.client.headers)



def fetch(self, label_uid: str = None):
"""
The Get label call returns information about a particular label of a stack.
:param label_uid: The `label_uid` parameter is a string that represents the unique identifier of
a label. It is used to specify which label to fetch from the server
:type label_uid: str
:return: the result of the GET request made to the specified URL.
-------------------------------
[Example:]
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = client.stack('api_key').label('label_uid').fetch().json()
-------------------------------
"""

if label_uid is not None and label_uid != '':
self.label_uid = label_uid

self.validate_uid()
url = f"{self.path}/{self.label_uid}"
return self.client.get(url, headers = self.client.headers)


def create(self, data: dict):
"""
This call is used to create a label.
:param data: The `data` parameter is the payload that you want to send in the request body. It
should be a dictionary or a JSON serializable object that you want to send as the request body
:return: Json, with label details.
-------------------------------
[Example:]
>>> data ={
>>> "label": {
>>> "name": "Test",
>>> "parent": [
>>> "label_uid"
>>> ],
>>> "content_types": [
>>> "content_type_uid"
>>> ]
>>> }
>>> }
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = client.stack('api_key').label().create(data).json()
-------------------------------
"""

data = json.dumps(data)
return self.client.post(self.path, headers = self.client.headers, data=data)

def update(self, data: dict, label_uid: str = None):
"""
The "Update label" call is used to update an existing label.
:param data: The `data` parameter is a dictionary that contains the updated information that you
want to send to the server. This data will be converted to a JSON string before sending it in
the request
:type data: dict
:param label_uid: The `label_uid` parameter is a string that represents the unique identifier of
the label. It is used to specify which label should be updated with the provided data
:type label_uid: str
:return: the result of the `put` request made to the specified URL.
-------------------------------
[Example:]
>>> data = {
>>> "label": {
>>> "name": "Test",
>>> "parent": [
>>> "label_uid"
>>> ],
>>> "content_types": [
>>> "content_type_uid"
>>> ]
>>> }
>>> }
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = client.stack('api_key').label("label_uid").update(data).json()
-------------------------------
"""
if label_uid is not None and label_uid != '':
self.label_uid = label_uid
self.validate_uid()
url = f"{self.path}/{self.label_uid}"
data = json.dumps(data)
return self.client.put(url, headers = self.client.headers, data=data)


def delete(self, label_uid: str = None):
"""
The "Delete label" call is used to delete a specific label.
:param label_uid: The `label_uid` parameter is a string that represents the unique identifier of
the label that you want to delete
:type label_uid: str
:return: the result of the `client.delete()` method, which is likely a response object or a
boolean value indicating the success of the deletion operation.
-------------------------------
[Example:]
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = client.stack('api_key').label('label_uid').delete().json()
-------------------------------
"""
if label_uid is not None and label_uid != '':
self.label_uid = label_uid
self.validate_uid()
url = f"{self.path}/{self.label_uid}"
return self.client.delete(url, headers = self.client.headers)

def validate_uid(self):
"""
The function checks if the label_uid is None or an empty string and raises an ArgumentException
if it is.
"""

if self.label_uid is None or '':
raise ArgumentException("label Uid is required")
4 changes: 4 additions & 0 deletions contentstack_management/stack/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ..environments.environment import Environment
from ..locale.locale import Locale
from ..taxonomies.taxonomy import Taxonomy
from ..labels.label import Label



Expand Down Expand Up @@ -348,4 +349,7 @@ def locale(self, locale_code: str = None):

def taxonomy(self, taxonomy_uid: str = None):
return Taxonomy(self.client, taxonomy_uid)

def label(self, label_uid: str = None):
return Label(self.client, label_uid)

Empty file added coverage.txt
Empty file.
70 changes: 70 additions & 0 deletions tests/api/labels/test_labels_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os
import unittest
from dotenv import load_dotenv
from contentstack_management import contentstack
from tests.cred import get_credentials

credentials = get_credentials()
username = credentials["username"]
password = credentials["password"]
host = credentials["host"]
api_key = credentials["api_key"]
label_uid = credentials["label_uid"]

class LabelApiTests(unittest.TestCase):

def setUp(self):
self.client = contentstack.ContentstackClient(host=host)
self.client.login(username, password)

def test_get_all_label(self):
response = self.client.stack(api_key).label().find()
self.assertEqual(response.request.url, f"{self.client.endpoint}labels")
self.assertEqual(response.status_code, 200)

def test_get_a_label(self):
response = self.client.stack(api_key).label(label_uid).fetch()
self.assertEqual(response.request.url,
f"{self.client.endpoint}labels/{label_uid}")
self.assertEqual(response.status_code, 200)


def test_create(self):
data = {
"label": {
"name": "Test",
"parent": [
"label_uid"
],
"content_types": [
"content_type_uid"
]
}
}
response = self.client.stack(api_key).label().create(data)
self.assertEqual(response.request.url, f"{self.client.endpoint}labels")
self.assertEqual(response.status_code, 201)

def test_update_label(self):
data = {
"label": {
"name": "Test",
"parent": [
"label_uid"
],
"content_types": [
"content_type_uid"
]
}
}
response = self.client.stack(api_key).label(label_uid).update(data)
self.assertEqual(response.request.url,
f"{self.client.endpoint}labels/{label_uid}")
self.assertEqual(response.status_code, 200)


def test_delete_label(self):
response = self.client.stack(api_key).label(label_uid).delete()
self.assertEqual(response.status_code, 200)


2 changes: 2 additions & 0 deletions tests/cred.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
default_environments_name = "environments_name" #Default environment name
default_locale_code = "locale_code" #Default locale code
default_taxonomy_uid = "taxonomy_uid" #Default taxonomy code
default_label_uid = "label_uid" #Default label code


def get_credentials():
Expand Down Expand Up @@ -72,6 +73,7 @@ def get_credentials():
"environments_name": os.getenv("ENVIRONMENT_NAME", default_environments_name),
"locale_code": os.getenv("LOCALE_CODE", default_locale_code),
"taxonomy_uid": os.getenv("TAXONOMY_UID", default_taxonomy_uid),
"label_uid": os.getenv("LABEL_UID", default_label_uid),

}
return credentials
Loading

0 comments on commit 839a041

Please sign in to comment.