Best Python code snippet using autotest_python
apirequest.py
Source:apirequest.py
1"""Handling of API requests."""2import six3from abc import ABCMeta, abstractmethod4@six.add_metaclass(ABCMeta)5class APIRequest(object):6 """Base Class for API-request classes."""7 @abstractmethod8 def __init__(self, endpoint, method="GET", expected_status=200):9 """Instantiate an API request.10 Parameters11 ----------12 endpoint : string13 the URL format string14 method : string15 the method for the request. Default: GET.16 """17 self._expected_status = expected_status18 self._status_code = None19 self._response = None20 self._endpoint = endpoint21 self.method = method22 @property23 def expected_status(self):24 return self._expected_status25 @property26 def status_code(self):27 return self._status_code28 @status_code.setter29 def status_code(self, value):30 if value != self._expected_status:31 raise ValueError("{} {} {:d}".format(self, self.method, value))32 self._status_code = value33 @property34 def response(self):35 """response - get the response of the request."""36 return self._response37 @response.setter38 def response(self, value):39 """response - set the response of the request."""40 self._response = value41 def __str__(self):42 """return the endpoint."""...
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!!