Exemplo n.º 1
0
    def updateOpts(self, opts=None):
        """

		Updates options list inside API request definition.

		Keyword arguments:
		self     APIRequest -- Self instance
		opts     dict       -- (optional) Additional options array to merge with previous option values

		Exceptions:
		SDKInvalidArgException if opts param is not a dictionary.
		SDKInvalidArgException if provided parameter list is non-dict parameter.

		"""

        if opts is None:
            opts = {}

        if not isinstance(opts, dict):
            raise SDKInvalidArgException('`opts` must be a dictionary')
        elif 'params' in opts and not isinstance(opts['params'], dict):
            raise SDKInvalidArgException(
                '`opts[\'params\']` must be a dictionary')

        self._opts.update(opts)
Exemplo n.º 2
0
    def all(self, filters=None):
        """

		Function definition for listing all entities. Base function checks for invalid parameters.

		Keyword arguments:
		self    EntityHandler -- Self instance
		filters dict          -- (optional) Filters to apply to restrict listing. Currently supported: limit, page

		Exceptions:
		SDKInvalidArgException if provided filters param is not a dictionary.
		SDKInvalidArgException if invalid filter value found in filters dictionary.

		"""

        if filters is None:
            filters = {}

        if not isinstance(filters, dict):
            raise SDKInvalidArgException('`filters` must be a dictionary')
        else:
            for k in filters.keys():
                if not k in ['include', 'limit', 'page']:
                    raise SDKInvalidArgException('unsupported ' + k +
                                                 ' for `filters`')
Exemplo n.º 3
0
    def exchangeAuthCode(self, clientID, clientSecret, grantType, code,
                         redirectURI):
        """

		Generates an access token string from the provided authorization code

		Keyword arguments:
		self         OAuth2Handler -- Self instance
		clientID     str           -- client ID given at application registration
		clientSecret str           -- client secret given at application registration
		grantType    str           -- oauth specific grant_type value (i.e.: authorization_code)
		code         str           -- authorization code obtained from the generated auth link
		redirectURI  str           -- URL to be redirected to after authorization

		Exceptions:
		SDKInvalidArgException if provided clientID param is not a string
		SDKInvalidArgException if provided clientSecret param is not a string
		SDKInvalidArgException if provided grantType param is not a string
		SDKInvalidArgException if provided code param is not a string
		SDKInvalidArgException if provided redirectURI param is not a string

		Returns:
		str - returns obtained access token string

		"""

        if not isinstance(clientID, str):
            raise SDKInvalidArgException('`clientID` must be a string')
        elif not isinstance(clientSecret, str):
            raise SDKInvalidArgException('`clientSecret` must be a string')
        elif not isinstance(grantType, str):
            raise SDKInvalidArgException('`grantType` must be a string')
        elif not isinstance(code, str):
            raise SDKInvalidArgException('`code` must be a string')
        elif not isinstance(redirectURI, str):
            raise SDKInvalidArgException('`redirectURI` must be a string')

        params = {
            'grant_type': grantType,
            'client_id': clientID,
            'client_secret': clientSecret,
            'redirect_uri': redirectURI,
            'code': code
        }

        req = APIRequest(self._origin, '/login/oauth/access_token', 'POST', {
            'base_uri': 'https://app.leantesting.com',
            'params': params
        })

        resp = req.exec_()
        return resp['access_token']
Exemplo n.º 4
0
    def generateAuthLink(self,
                         clientID,
                         redirectURI,
                         scope='read',
                         state=None):
        """

		Function that generates link for user to follow in order to request authorization code

		Keyword arguments:
		self        OAuth2Handler -- Self instance
		clientID    str           -- client ID given at application registration
		redirectURI str           -- URL to be redirected to after authorization
		scope       str           -- (optional) comma-separated list of requested scopes (default: 'read')
		state       str           -- (optional) random string for MITM attack prevention

		Exceptions:
		SDKInvalidArgException if provided clientID param is not a string
		SDKInvalidArgException if provided redirectURI param is not a string
		SDKInvalidArgException if provided scope param is not a string
		SDKInvalidArgException if provided state param is not a string

		Returns:
		str - returns URL to follow for authorization code request

		"""

        if not isinstance(clientID, str):
            raise SDKInvalidArgException('`clientID` must be a string')
        elif not isinstance(redirectURI, str):
            raise SDKInvalidArgException('`redirectURI` must be a string')
        elif not isinstance(scope, str):
            raise SDKInvalidArgException('`scope` must be a string')
        elif not state is None and not isinstance(state, str):
            raise SDKInvalidArgException('`state` must be a string')

        baseURL = 'https://app.leantesting.com/login/oauth/authorize'

        params = {
            'client_id': clientID,
            'redirect_uri': redirectURI,
            'scope': scope
        }

        if not state is None:
            params['state'] = state

        baseURL += '?' + urllib.parse.urlencode(params)
        return baseURL
Exemplo n.º 5
0
    def upload(self, filepath):
        """

		Uploads given file as an attachment for specified bug.

		Keyword arguments:
		self     BugAttachmentsHandler -- Self instance
		filepath str                   -- an absolute path of the file to be uploaded
										example: /home/path/to/file.txt (Linux), C:\\Users\\Documents\\file.txt (Windows)

		Exceptions:
		SDKInvalidArgException if filepath is not a string

		Returns:
		BugAttachment -- the newly uploaded attachment

		"""

        if not isinstance(filepath, str):
            raise SDKInvalidArgException('`filepath` must be of type string')

        req = APIRequest(self._origin,
                         '/v1/bugs/' + str(self._bugID) + '/attachments',
                         'POST', {
                             'form_data': True,
                             'file_path': filepath
                         })

        return BugAttachment(self._origin, req.exec_())
Exemplo n.º 6
0
    def create(self, fields):
        """

		Function definition for creating a new entity. Base function checks for invalid parameters.

		Keyword arguments:
		self   EntityHandler -- Self instance
		fields dict          -- Non-empty dictionary consisting of entity data to send for adding

		Exceptions:
		SDKInvalidArgException if provided fields param is not a dictionary.
		SDKInvalidArgException if provided fields param is empty.

		"""

        if not isinstance(fields, dict):
            raise SDKInvalidArgException('`fields` must be a dictionary')
        elif not len(fields):
            raise SDKInvalidArgException('`fields` must be non-empty')
Exemplo n.º 7
0
	def __init__(self, origin, endpoint, method, opts = None):
		"""

		Constructs API request definition.

		Keyword arguments:
		self     APIRequest -- Self instance
		origin   Client   -- Originating client reference
		endpoint str        -- API endpoint
		method   str        -- Method for cURL call - supports GET, POST, PUT or DELETE only
		opts     dict       -- (optional) Additional options to pass to request.
								Request parameters (if any) must bep assed here.

		Exceptions:
		SDKInvalidArgException if method is non-string.
		SDKInvalidArgException if unsupported method is provided.
		SDKInvalidArgException if endpoint is non-string.
		SDKInvalidArgException if opts param is not a dictionary.

		"""

		if opts is None:
			opts = {}

		if not isinstance(method, str):
			raise SDKInvalidArgException('`method` must be a string')
		elif not method in ['GET', 'POST', 'PUT', 'DELETE']:
			raise SDKInvalidArgException('unsupported ' + method + ' `method`')
		elif not isinstance(endpoint, str):
			raise SDKInvalidArgException('`endpoint` must be a string')
		elif not isinstance(opts, dict):
			raise SDKInvalidArgException('`opts` must be a dictionary')

		self._opts = self._default_opts.copy()
		self.updateOpts(opts)

		self._origin   = origin
		self._endpoint = endpoint
		self._method   = method
    def __init__(self, origin, data):
        """

		Constructs an Entity instance

		Keyword arguments:
		self   Entity -- Self instance
		origin Client -- Original client instance reference
		data   dict   -- Data to be contained in the new Entity. Must be non-empty.

		Exceptions:
		SDKInvalidArgException if provided data param is not a dictionary.
		SDKInvalidArgException if provided data param is empty. Entities cannot be empty.

		"""

        if not isinstance(data, dict):
            raise SDKInvalidArgException('`data` must be a dictionary')
        elif not len(data):
            raise SDKInvalidArgException('`data` must be non-empty')

        self.origin = origin
        self.data = data
Exemplo n.º 9
0
    def update(self, id_, fields):
        """

		Function definition for updating an existing entity. Base function checks for invalid parameters.

		Keyword arguments:
		self   EntityHandler -- Self instance
		id_    int           -- ID field of entity to update in the entity collection
		fields dict          -- Non-empty dictionary consisting of entity data to send for update

		Exceptions:
		SDKInvalidArgException if provided id_ param is not an integer.
		SDKInvalidArgException if provided fields param is not a dictionary.
		SDKInvalidArgException if provided fields param is empty.

		"""

        if not isinstance(id_, int):
            raise SDKInvalidArgException('`id_` must be of type integer')
        elif not isinstance(fields, dict):
            raise SDKInvalidArgException('`fields` must be a dictionary')
        elif not len(fields):
            raise SDKInvalidArgException('`fields` must be non-empty')
Exemplo n.º 10
0
    def delete(self, id_):
        """

		Function definition for deleting an existing entity. Base function checks for invalid parameters.

		Keyword arguments:
		self EntityHandler -- Self instance
		id_  int           -- ID field of entity to delete in the entity collection

		Exceptions:
		SDKInvalidArgException if provided id_ param is not an integer.

		"""

        if not isinstance(id_, int):
            raise SDKInvalidArgException('`id_` must be of type integer')
Exemplo n.º 11
0
    def attachToken(self, accessToken):
        """

		Function to attach new token to SDK Client instance. Token changes are dynamic; all objects/entities
		originating from an instance which has had its token updated will utilize the new token automatically.

		Keyword arguments:
		self        Client -- Self instance
		accessToken str    -- the string of the token to be attached

		Exceptions:
		SDKInvalidArgException if provided accessToken param is not a string

		"""

        if not isinstance(accessToken, str):
            raise SDKInvalidArgException('`accessToken` must be a string')

        self._accessToken = accessToken