Beispiel #1
0
    def test_api_exception_message(self):
        e = APIException(TestApiException.URL, TestApiException.STATUS_CODE,
                         TestApiException.MESSAGE_RESPONSE)

        self.assertEqual(e.url, TestApiException.URL)
        self.assertIn(TestApiException.STATUS_CODE_STR, str(e))
        self.assertIn(TestApiException.MESSAGE_RESPONSE['message'], str(e))
Beispiel #2
0
    def test_api_exception_error(self):
        e = APIException(TestApiException.URL, TestApiException.STATUS_CODE,
                         TestApiException.ERROR_RESPONSE)

        self.assertEqual(e.url, TestApiException.URL)
        self.assertIn(TestApiException.STATUS_CODE_STR, str(e))
        self.assertIn(TestApiException.ERROR_RESPONSE['error'], str(e))
Beispiel #3
0
def process_resp(esiapp, esiclient, resp):
    assert (resp.status == 200)
    fit_list = {}
    for fit in resp.data:
        
        op = esiapp.op['get_universe_types_type_id'](
            type_id=fit.ship_type_id
        )
        resp = esiclient.request(op)
        if resp.status != 200:
            raise APIException('', resp.status, resp.data)
        
        if resp.data.name in fit_list:
            fit_list[resp.data.name] += [(fit.name, json.dumps(fit)
                                              .replace(u'<', u'\\u003c')
                                              .replace(u'>', u'\\u003e')
                                              .replace(u'&', u'\\u0026')
                                              .replace(u"'", u'\\u0027'))]
        else:
            fit_list[resp.data.name] = [(fit.name, json.dumps(fit)
                                              .replace(u'<', u'\\u003c')
                                              .replace(u'>', u'\\u003e')
                                              .replace(u'&', u'\\u0026')
                                              .replace(u"'", u'\\u0027'))]
            
    
    return OrderedDict(sorted(fit_list.items(), key=lambda t: t[0]))
Beispiel #4
0
    def test_api_exception_no_message_error(self):
        e = APIException(TestApiException.URL, TestApiException.STATUS_CODE,
                         {})

        self.assertEqual(e.url, TestApiException.URL)
        self.assertIn(TestApiException.STATUS_CODE_STR, str(e))
        self.assertNotIn(TestApiException.ERROR_RESPONSE['error'], str(e))
        self.assertNotIn(TestApiException.MESSAGE_RESPONSE['message'], str(e))
Beispiel #5
0
    def test_api_exception_error(self):
        e = APIException(TestApiException.URL,
                         TestApiException.STATUS_CODE,
                         response=TestApiException.ERROR_RESPONSE,
                         request_param=TestApiException.PARAMS,
                         response_header=TestApiException.HEADERS)

        self.assertEqual(e.url, TestApiException.URL)
        self.assertIn(TestApiException.STATUS_CODE_STR, str(e))
        self.assertIn(TestApiException.ERROR_RESPONSE['error'], str(e))
        self.assertEqual(e.request_param, TestApiException.PARAMS)
        self.assertEqual(e.response_header, TestApiException.HEADERS)
Beispiel #6
0
 def refresh(self):
     """ Update the auth data (tokens) using the refresh token in auth.
     """
     request_data = self.get_refresh_token_params()
     res = self._session.post(**request_data)
     if res.status_code != 200:
         raise APIException(
             request_data['url'],
             res.status_code,
             res.json()
         )
     json_res = res.json()
     self.update_token(json_res)
     return json_res
Beispiel #7
0
    def verify(self):
        """ Make a get call to the oauth/verify endpoint to get the user data

        :return: the json with the data.
        """
        res = self._session.get(
            self.oauth_verify,
            headers=self.__get_oauth_header()
        )
        if res.status_code != 200:
            raise APIException(
                self.oauth_verify,
                res.status_code,
                res.json()
            )
        return res.json()
Beispiel #8
0
def _get_esi(op, raw_body_only=False):
    """
    Try to get a result from an esipy request response tuple
    :param op: Request response tuple generated by esiapp.op
    :return: parsed result data
    :raises: `esipy.excpetions.APIException` if an ESI Exception is encountered
    """
    res = esiclient.request(op, raw_body_only=raw_body_only)

    if res.status == 200:
        if raw_body_only:
            return json.loads(res.raw.decode('utf-8'))
        else:
            return res.data
    else:
        raise APIException(op[0].url, res.status,
                           json.loads(res.raw.decode('utf-8')))
    def get_types(self) -> List[TypesResponse]:
        """
        Get response containing a list of all type ids
        """
        resp = self.__client.head(self.__api.op['get_universe_types'](page=1))
        if (resp.status != 200):
            raise APIException("", resp.status)

        pages = 1
        if 'X-Pages' in resp.header:
            pages = int(resp.header['X-Pages'][0])

        ops = []
        for page in range(1, pages + 1):
            ops.append(self.__api.op['get_universe_types'](page=page))

        responses = self.__client.multi_request(ops)

        response_list: List[TypesResponse] = []
        for data_tuple in responses:  # (request, response)
            response_list.append(TypesResponse(data_tuple[1]))

        return response_list