Best Python code snippet using Kiwi_python
bitbucket.py
Source:bitbucket.py
...8 BitBucket API interaction class.9 """10 def __init__(self, base_url=None, api_username=None, api_password=None):11 api_version = "2.0"12 self.endpoint_url = self._construct_endpoint_url(api_version, base_url)13 self.headers = {14 "Accept": "application/json",15 "Content-type": "application/json",16 }17 self.auth = HTTPBasicAuth(api_username, api_password)18 def create_issue(self, data):19 url = f"{self.endpoint_url}/issues"20 return self._request(21 "POST", url, headers=self.headers, auth=self.auth, json=data22 )23 def get_issue(self, issue_id):24 url = f"{self.endpoint_url}/issues/{issue_id}"25 return self._request("GET", url, headers=self.headers, auth=self.auth)26 def update_issue(self, issue_id, data):27 url = f"{self.endpoint_url}/issues/{issue_id}/changes"28 return self._request(29 "POST", url, headers=self.headers, auth=self.auth, json=data30 )31 def add_comment(self, issue_id, comment):32 url = f"{self.endpoint_url}/issues/{issue_id}/comments/"33 return self._request(34 "POST", url, headers=self.headers, auth=self.auth, json=comment35 )36 def get_comments(self, issue_id):37 url = f"{self.endpoint_url}/issues/{issue_id}/comments?sort=-updated_on"38 return self._request("GET", url, headers=self.headers, auth=self.auth)39 def delete_comment(self, issue_id, comment_id):40 url = f"{self.endpoint_url}/issues/{issue_id}/comments/{comment_id}"41 return self._request("DELETE", url, headers=self.headers, auth=self.auth)42 @staticmethod43 def _request(method, url, **kwargs):44 if method == "DELETE":45 return requests.request(method, url, **kwargs)46 return requests.request(method, url, **kwargs).json()47 @staticmethod48 def _construct_endpoint_url(api_version, url):49 splitted_url = url.replace("https://", "").split("/")50 base_url = "https://api.bitbucket.org"51 workspace = splitted_url[1]52 repository = splitted_url[2]53 endpoint_url = f"{base_url}/{api_version}/repositories/{workspace}/{repository}"54 return endpoint_url55class BitBucketThread(IntegrationThread):56 """57 Execute BitBucket code in a thread!58 Executed from the IssueTracker interface methods.59 """60 def post_comment(self):61 comment_body = {"content": {"raw": self.text().replace("\n", "\n\n")}}62 self.rpc.add_comment(self.bug_id, comment_body)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!