How to use the groupy.exceptions function in groupy

To help you get started, we’ve selected a few groupy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rhgrant10 / Groupy / tests / test_utils.py View on Github external
def test_no_matches(self):
        f = utils.make_filter(foobar='barfoo')
        with self.assertRaises(exceptions.NoMatchesError):
            f.find(self.objects)
github rhgrant10 / Groupy / groupy / session.py View on Github external
def errors(self):
        try:
            return self.json()['meta']['errors']
        except ValueError as e:
            raise exceptions.InvalidJsonError(self._resp) from e
        except KeyError as e:
            raise exceptions.MissingMetaError(self._resp) from e
github rhgrant10 / Groupy / groupy / session.py View on Github external
def data(self):
        try:
            return self.json()['response']
        except ValueError as e:
            raise exceptions.InvalidJsonError(self._resp) from e
        except KeyError as e:
            try:
                return self.json()['payload']
            except KeyError:
                raise exceptions.MissingResponseError(self._resp) from e
github rhgrant10 / Groupy / groupy / api / memberships.py View on Github external
def check_if_ready(self):
        """Check for and fetch the results if ready."""
        try:
            results = self.manager.check(self.results_id)
        except exceptions.ResultsNotReady as e:
            self._is_ready = False
            self._not_ready_exception = e
        except exceptions.ResultsExpired as e:
            self._is_ready = True
            self._expired_exception = e
        else:
            failures = self.get_failed_requests(results)
            members = self.get_new_members(results)
            self.results = self.__class__.Results(list(members), list(failures))
            self._is_ready = True
            self._not_ready_exception = None
github rhgrant10 / Groupy / groupy / utils.py View on Github external
def find(self, objects):
        """Find exactly one match in the list of objects.

        :param objects: objects to filter
        :type objects: :class:`list`
        :return: the one matching object
        :raises groupy.exceptions.NoMatchesError: if no objects match
        :raises groupy.exceptions.MultipleMatchesError: if multiple objects match
        """
        matches = list(self.__call__(objects))
        if not matches:
            raise exceptions.NoMatchesError(objects, self.tests)
        elif len(matches) > 1:
            raise exceptions.MultipleMatchesError(objects, self.tests,
                                                  matches=matches)
        return matches[0]
github rhgrant10 / Groupy / groupy / resources.py View on Github external
def _check_if_ready(self):
        try:
            results = self.manager.check(self.results_id)
            self._is_ready = True
            self._not_ready_exception = None
            self._process_new_members(results)
        except exceptions.ResultsNotReady as e:
            self._is_ready = False
            self._not_ready_exception = e
        except exceptions.ResultsExpired as e:
            self._is_ready = True
            self._expired_exception = e
github rhgrant10 / Groupy / groupy / api / memberships.py View on Github external
def check(self, results_id):
        """Check for results of a membership request.

        :param str results_id: the ID of a membership request
        :return: successfully created memberships
        :rtype: :class:`list`
        :raises groupy.exceptions.ResultsNotReady: if the results are not ready
        :raises groupy.exceptions.ResultsExpired: if the results have expired
        """
        path = 'results/{}'.format(results_id)
        url = utils.urljoin(self.url, path)
        response = self.session.get(url)
        if response.status_code == 503:
            raise exceptions.ResultsNotReady(response)
        if response.status_code == 404:
            raise exceptions.ResultsExpired(response)
        return response.data['members']
github rhgrant10 / Groupy / groupy / session.py View on Github external
def data(self):
        try:
            return self.json()['response']
        except ValueError as e:
            raise exceptions.InvalidJsonError(self._resp) from e
        except KeyError as e:
            try:
                return self.json()['payload']
            except KeyError:
                raise exceptions.MissingResponseError(self._resp) from e
github rhgrant10 / Groupy / groupy / resources.py View on Github external
def _check_if_ready(self):
        try:
            results = self.manager.check(self.results_id)
            self._is_ready = True
            self._not_ready_exception = None
            self._process_new_members(results)
        except exceptions.ResultsNotReady as e:
            self._is_ready = False
            self._not_ready_exception = e
        except exceptions.ResultsExpired as e:
            self._is_ready = True
            self._expired_exception = e
github rhgrant10 / Groupy / groupy / session.py View on Github external
def request(self, *args, **kwargs):
        # ensure we reraise exceptions as our own
        try:
            response = super().request(*args, **kwargs)
            response.raise_for_status()
            return Response(response)
        except requests.HTTPError as e:
            logger.exception('received a bad response')
            raise exceptions.BadResponse(response) from e
        except requests.RequestException as e:
            logger.exception('could not receive a response')
            raise exceptions.NoResponse(e.request) from e