Пример #1
0
    def create(self, **create_parameters):
        """
        Method to create new pet in database

        :param **create_parameters - **kwargs values that can be considered:
        - id: int64;
        - category: {
                    id: int64,
                    name: str
                    };
        - name*: str;
        - photoUrls*: [str] #list of strings;
        - tags: [{
                    id: int64,
                    name: str
                    }]; #list of dicts
        - status: str # values that can be used: 'available', 'pending', 'sold'
        Note: * - required parameters

        :return json data
        """
        LOGGER.debug('Convert input data to JSON data')
        json_data = convert_data_to_json(create_parameters)
        LOGGER.info(f'input data converted to JSON data: {json_data}')
        LOGGER.debug(f'Request: POST {json_data} to {self.base_url}')

        response = requests.post(self.base_url, json=json_data)
        if response.status_code == HTTPStatus.OK:
            LOGGER.info(f'Response: Status code {response.status_code}' +
                        f'{response.text}')
        else:
            LOGGER.warning(f'Response: Status code {response.status_code}' +
                           f'{response.url} {response.text}')
        return response
Пример #2
0
 def latest_symbols(self):
     """Request specific exchange rates by setting the symbols parameter"""
     response = requests.get(self.url + '?symbols=USD,GBP')
     status_code = response.status_code
     logger.info(f"Code status: {status_code}. Successful operation. "
                 f"URL: {self.url + '?symbols=USD,GBP'}")
     return response
Пример #3
0
 def historical(self):
     """Get historical rates for any day since 1999"""
     response = requests.get(self.url)
     status_code = response.status_code
     logger.info(f"Code status: {status_code}. Successful operation. "
                 f"URL: {self.url}")
     return response
Пример #4
0
 def latest_foreign(self):
     """Get the latest foreign exchange reference rates"""
     response = requests.get(self.url)
     status_code = response.status_code
     logger.info(f"Code status: {status_code}. Successful operation. "
                 f"URL: {self.url}")
     return response
Пример #5
0
 def _find_user_by_name(cls, username: str) -> requests.models.Response:
     """Send GET request to find user by username."""
     LOGGER.debug(f'Send GET {cls.url}/{username}')
     response = requests.get(f'{cls.url}/{username}')
     LOGGER.info(f'Response: Status code {response.status_code}, '
                 f'{response.text}, '
                 f'{response.url}')
     return response
Пример #6
0
 def rates_time_period(self):
     """Get historical rates for a time period"""
     response = requests.get(self.url +
                             '?start_at=2018-01-01&end_at=2018-09-01')
     status_code = response.status_code
     logger.info(
         f"Code status: {status_code}. Successful operation. "
         f"URL: {self.url + '?start_at=2018-01-01&end_at=2018-09-01'}")
     return response
Пример #7
0
 def latest_base(self):
     """Rates are quoted against the Euro by default.
     Quote against a different currency by setting the base parameter in your request
     """
     response = requests.get(self.url + '?base=USD')
     status_code = response.status_code
     logger.info(f"Code status: {status_code}. Successful operation. "
                 f"URL: {self.url + '?base=USD'}")
     return response
Пример #8
0
    def _find_request(cls, url: str) -> requests.models.Response:
        """Send GET request to url.

        :param url: string
        :return: requests.models.Response
        """
        LOGGER.debug(f'Request: GET {url}')
        response = requests.get(url)
        LOGGER.info(f'Response: Status code {response.status_code}')
        return response
Пример #9
0
 def different_currency(self):
     """Quote the historical rates against a different currency"""
     response = requests.get(
         self.url + '?start_at=2018-01-01&end_at=2018-09-01&base=USD')
     status_code = response.status_code
     logger.info(
         f"Code status: {status_code}. Successful operation. "
         f"URL: {self.url + '?start_at=2018-01-01&end_at=2018-09-01&base=USD'}"
     )
     return response
Пример #10
0
 def specific_exchange_rates(self):
     """Limit results to specific exchange rates to save bandwidth with the symbols parameter"""
     response = requests.get(
         self.url +
         '?start_at=2018-01-01&end_at=2018-09-01&symbols=ILS,JPY')
     status_code = response.status_code
     logger.info(
         f"Code status: {status_code}. Successful operation. "
         f"URL: {self.url + '?start_at=2018-01-01&end_at=2018-09-01&symbols=ILS,JPY'}"
     )
     return response
Пример #11
0
    def _response(cls, url: str):
        """Returns response message"""
        response = Dog._find_request(url)

        if not response.status_code == HTTPStatus.OK:
            LOGGER.warning(
                f'Response: Status code {response.status_code}, {response.text}, '
                f'{response.url}')
            return None

        return json.loads(response.text)['message']
Пример #12
0
 def lookup(self, post_code: str):
     """Lookup a postcode."""
     response = requests.get(self.url + "/postcodes/" + post_code)
     status = response.status_code
     if status == HTTPStatus.OK:
         LOGGER.info(
             f'Lookup a postcode. Status code: {status}. Successful operation.'
         )
         return response
     LOGGER.debug(
         f'Lookup a postcode. Status code: {status}. Something went wrong')
     return response
Пример #13
0
 def random(self):
     """Get a random postcode."""
     response = requests.get(self.url + '/random/postcodes')
     status = response.status_code
     if status == HTTPStatus.OK:
         LOGGER.info(
             f'Getting random postcode. Status code: {status}. Successful operation.'
         )
         return response
     LOGGER.debug(
         f'Getting random postcode. Status code: {status}. Something went wrong'
     )
     return response
Пример #14
0
 def bulk_lookup(self, data: dict):
     """Bulk lookup postcodes."""
     data_json = json.loads(data)
     response = requests.post(self.url + "/postcodes", json=data_json)
     status = response.status_code
     if status == HTTPStatus.OK:
         LOGGER.info(
             f'Bulk lookup postcodes. Status code: {status}. Successful operation.'
         )
         return response
     LOGGER.debug(
         f'Bulk lookup postcodes. Status code: {status}. Something went wrong'
     )
     return response
Пример #15
0
 def update(self, pet_id: str, new_name: dict):
     """
     updating pets info
     :param pet_id: str
     :param new_name: dict
     :return:
     """
     response = requests.post(self.base_url + pet_id, data=new_name)
     code = response.status_code
     if code == HTTPStatus.OK:
         LOGGER.info(
             f'UPDATING...Status code: {code}. Successful operation.')
         return response
     LOGGER.warning(f'UPDATING...Status code: {code}. Something went wrong')
     return response
Пример #16
0
 def delete_pet(self, pet_id: str):
     """
     deleting pet from store
     :param pet_id: str
     :return:
     """
     url = self.base_url + pet_id
     response = requests.delete(url)
     code = response.status_code
     if code == HTTPStatus.OK:
         LOGGER.info(
             f'DELETING...Status code: {code}. Successful operation.')
         return response
     LOGGER.warning(f'DELETING...Status code: {code}. Something went wrong')
     return response
Пример #17
0
    def get_user_by_name(self, username: str):
        """Set user's attributes, received from GET request."""
        response = User._find_user_by_name(username)
        LOGGER.info(f'Status code:{response.status_code}, {response.text}')

        if not response.status_code == HTTPStatus.OK:
            LOGGER.warning(
                f'Status code:{response.status_code}, {response.url}, {response.text}'
            )
            return None

        response = json.loads(response.text)
        self.id = response['id']
        self.username = response['username']
        self.first_name = response['firstName']
        self.last_name = response['lastName']
        self.email = response['email']
        self.password = response['password']
        self.phone = response['phone']
        self.user_status = response['userStatus']

        LOGGER.debug(
            f'Set user attributes: {self.id}, {self.username}, {self.first_name}, '
            f'{self.last_name}, {self.email}, {self.password}, {self.phone}, '
            f'{self.user_status}')
Пример #18
0
 def find_by_status(self, status: str):
     """
     Method that finds pet by it`s status in system
     :param status: str values that can be considered:
      - "available"
      - "pending"
      - "sold"
      :return json data
      """
     request_url = self.base_url + "findByStatus?status=" + status
     LOGGER.debug(f'Request: GET {request_url}')
     response = requests.get(request_url)
     if response.status_code == HTTPStatus.OK:
         LOGGER.info(f'Response: Status code { response.status_code}' +
                     f'{ response.text[:100]}')
     else:
         LOGGER.warning(f'Response: Status code { response.status_code}' +
                        f'{ response.url} { response.text[:100]}')
     return response