コード例 #1
0
    def test_get_users(self):

        self.body = self.response.json()
        code = self.response.status_code
        self.assertEqual(code, 200)
        reg = ['post_id', 'title', 'body', 'created_at', 'updated_at']
        recorded_data = dict.fromkeys(reg)

        recorded_data['post_id'] = self.body["data"]["id"]
        recorded_data['title'] = self.body["data"]["title"]
        recorded_data['body'] = self.body["data"]["body"]
        recorded_data['created_at'] = self.body["data"]["created_at"]
        recorded_data['updated_at'] = self.body["data"]["updated_at"]
        logger.info(f'post_id: {recorded_data["post_id"]}')

        r = GorestRequests()
        self.query = r.request_post_query()
        code = self.query.status_code
        body = self.query.json()

        self.assertEqual(code, 200)

        for i in range(len(body["data"])):
            if body['data'][i]['id'] == recorded_data['post_id']:
                self.assertEqual(body['data'][i]['id'],
                                 recorded_data['post_id'])
                self.assertEqual(body['data'][i]['title'],
                                 recorded_data['title'])
                self.assertEqual(body['data'][i]['body'],
                                 recorded_data['body'])
                self.assertEqual(body['data'][i]['created_at'],
                                 recorded_data['created_at'])
                self.assertEqual(body['data'][i]['updated_at'],
                                 recorded_data['updated_at'])
コード例 #2
0
ファイル: delete.py プロジェクト: rtejada/Python-Api-Testing
    def test_post_users(self):

        response = self.create_user()
        self.assertTrue(response.status_code, 200)
        body = response.json()
        logger.info(body["data"]["id"])

        reg = ['name', 'email', 'gender', 'status']
        recorded_data = dict.fromkeys(reg)

        recorded_data['name'] = body["data"]["name"]
        recorded_data['email'] = body["data"]["email"]
        recorded_data['gender'] = body["data"]["gender"]
        recorded_data['status'] = body["data"]["status"]

        r = GorestRequests()
        data_response = r.delete_user(recorded_data, body["data"]["id"])
        result = data_response.json()

        self.assertEqual(result["code"], 204)

        query = GorestRequests()
        data = query.request_get_user(body["data"]["id"])
        body_result = data.json()
        self.assertEqual(body_result["code"], 404)
コード例 #3
0
    def test_put_user(self):

        response = self.create_user()
        data_user = response.json()
        self.assertTrue(response.status_code, 200)
        user_id = data_user["data"]["id"]

        upd = GorestRequests()
        response = upd.request_update_user(user_id)
        body_update = response.json()
        self.assertEqual(response.status_code, 200)

        r = GorestRequests()
        get_post = r.request_get_user(user_id)
        body_get = get_post.json()

        self.assertTrue(get_post.status_code, 200)
        self.assertEqual(body_get['data']['id'], body_update["data"]["id"])
        self.assertEqual(body_get['data']['name'], body_update["data"]["name"])
        self.assertEqual(body_get['data']['email'],
                         body_update["data"]["email"])
        self.assertEqual(body_get['data']['gender'],
                         body_update["data"]["gender"])
        self.assertEqual(body_get['data']['status'],
                         body_update["data"]["status"])
        self.assertEqual(body_get['data']['created_at'],
                         body_update["data"]["created_at"])
        self.assertEqual(body_get['data']['updated_at'],
                         body_update["data"]["updated_at"])
        logger.info(f'user_id: {body_update["data"]["id"]}')
コード例 #4
0
        if cls.__cursor is None:
            try:
                cls.__cursor = cls.get_connected().cursor()
                return cls.__cursor
            except Exception as e:
                logger.error(f'error when get to the Cursor: {e}')
                sys.exit()
        else:
            return cls.__cursor

    @classmethod
    def close(cls):
        if cls.__cursor is not None:
            try:
                cls.__cursor.close()
            except Exception as e:
                logger.error(f'Error to the close Cursor: {e}')

        if cls.__connection is not None:
            try:
                cls.__connection.close()
            except Exception as e:
                logger.error(f'Error to the close Connection: {e}')
        logger.debug('the connection and cursor objects have been closed')


if __name__ == '__main__':
    logger.info(Connection.get_cursor())
    Connection.close()