예제 #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 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}')
예제 #3
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
예제 #4
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
예제 #5
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
예제 #6
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
예제 #7
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
예제 #8
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