python类POST的实例源码

test_oauth.py 文件源码 项目:weibopy 作者: nooperpudd 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_auth_access(self):
        """
        :return:
        """

        body = """
           {
               "access_token": "ACCESS_TOKEN",
               "expires_in": 1234,
               "remind_in":"798114",
               "uid":"12341234"
         }
        """

        httpretty.register_uri(
            httpretty.POST, "https://api.weibo.com/oauth2/access_token",
            body=body,
            status=200,
            content_type='text/json'
        )

        response = self.oauth2_client.auth_access("abcde")

        self.assertDictEqual(response, json.loads(body))
test_oauth.py 文件源码 项目:weibopy 作者: nooperpudd 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_revoke_auth_access(self):
        """
        :return:
        """

        body = '{"result":true}'

        httpretty.register_uri(
            httpretty.POST, "https://api.weibo.com/oauth2/revokeoauth2",
            body=body,
            status=200,
            content_type='text/json'
        )

        response = self.oauth2_client.revoke_auth_access(self.access_token)
        self.assertTrue(response)
test_oauth.py 文件源码 项目:weibopy 作者: nooperpudd 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_refresh_token(self):
        """
        :return:
        """

        body = """
         {
            "access_token": "SlAV32hkKG",
            "expires_in": 3600
        }
        """

        httpretty.register_uri(
            httpretty.POST, "https://api.weibo.com/oauth2/access_token",
            body=body,
            status=200,
            content_type='text/json'
        )

        response = self.oauth2_client.refresh_token("xxxxxxxx")
        self.assertTrue(response, json.loads(body))
test_oauth.py 文件源码 项目:weibopy 作者: nooperpudd 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_get_token_info(self):
        """
        :return:
        """
        body = """
          {
           "uid": 1073880650,
           "appkey": 1352222456,
           "scope": null,
           "create_at": 1352267591,
           "expire_in": 157679471
         }
        """

        httpretty.register_uri(
            httpretty.POST, "https://api.weibo.com/oauth2/get_token_info",
            body=body,
            status=200,
            content_type='text/json'
        )

        response = self.oauth2_client.get_token_info(self.access_token)

        self.assertDictEqual(response, json.loads(body))
test_oauth.py 文件源码 项目:weibopy 作者: nooperpudd 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_assert_api_error(self):
        """
        :return:
        """
        body = """
        {
                "error": "unsupported_response_type",
                "error_code": 21329,
                "error_description": "Unsupport ResponseType."
            }
        """

        httpretty.register_uri(
            httpretty.POST, "https://api.weibo.com/oauth2/get_token_info",
            body=body,
            status=200,
            content_type='text/json'
        )

        self.assertRaises(WeiboOauth2Error, self.oauth2_client.get_token_info, "dbdsds")
test_record.py 文件源码 项目:python-matchlightsdk 作者: TerbiumLabs 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_record_add_document(min_score, connection, project, document):
    """Verifies adding document records to a project."""
    httpretty.register_uri(
        httpretty.POST, '{}/records/upload/document/{}'.format(
            matchlight.MATCHLIGHT_API_URL_V2, project.upload_token),
        body=json.dumps({
            'id': uuid.uuid4().hex,
            'name': 'name',
            'description': '',
            'ctime': time.time(),
            'mtime': time.time(),
            'metadata': '{}',
        }),
        content_type='application/json', status=200)
    connection.records.add_document(
        project=project,
        name=document['name'],
        description=document['description'],
        document_path=DOCUMENT_RECORD_PATH,
        min_score=min_score)
test_feed.py 文件源码 项目:python-matchlightsdk 作者: TerbiumLabs 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_feed_counts(connection, feed, start_time, end_time):
    """Verifies requesting feed counts."""
    expected = {
        int(time.time()): random.randint(0, 1000),
        int(time.time()): random.randint(0, 1000),
        int(time.time()): random.randint(0, 1000),
        int(time.time()): random.randint(0, 1000),
    }
    httpretty.register_uri(
        httpretty.POST, '{}/feeds/{}'.format(
            matchlight.MATCHLIGHT_API_URL_V2,
            feed.name),
        body=json.dumps(expected),
        content_type='application/json', status=200)
    result = connection.feeds.counts(feed, start_time, end_time)
    assert result == connection.feeds._format_count(expected)

    result = connection.feeds.counts(feed.name, start_time, end_time)
    assert result == connection.feeds._format_count(expected)
test_project.py 文件源码 项目:python-matchlightsdk 作者: TerbiumLabs 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_project_edit(connection, project, project_payload):
    """Verifies project renaming."""
    httpretty.register_uri(
        httpretty.POST, '{}/project/{}/edit'.format(
            matchlight.MATCHLIGHT_API_URL_V2,
            project.upload_token,
        ),
        body='{}', status=200)
    new_name = 'Test Project 1'
    connection.projects.edit(project, new_name)
    assert project.name == new_name

    new_name = 'Test Project 2'
    httpretty.register_uri(
        httpretty.GET, '{}/project/{}'.format(
            matchlight.MATCHLIGHT_API_URL_V2,
            project.upload_token,
        ),
        body=json.dumps(project_payload),
        content_type='application/json', status=200)
    project = connection.projects.edit(project.upload_token, new_name)
    assert project.name == new_name
test_project.py 文件源码 项目:python-matchlightsdk 作者: TerbiumLabs 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_project_delete(connection, project, project_payload):
    """Verifies project deletion."""
    httpretty.register_uri(
        httpretty.POST, '{}/project/{}/delete'.format(
            matchlight.MATCHLIGHT_API_URL_V2,
            project.upload_token,
        ),
        body='{}', status=200)
    httpretty.register_uri(
        httpretty.GET, '{}/project/{}'.format(
            matchlight.MATCHLIGHT_API_URL_V2,
            project.upload_token,
        ),
        body=json.dumps(project_payload),
        content_type='application/json', status=200)
    connection.projects.delete(project)
test_search.py 文件源码 项目:poet 作者: sdispater 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
def test_search_with_results():
    httpretty.register_uri(
        httpretty.POST, 'https://pypi.python.org/pypi',
        body=RESULTS_RESPONSE,
        content_type='text/xml'
    )

    app = Application()

    command = app.find('search')
    command_tester = CommandTester(command)
    command_tester.execute([
        ('command', command.get_name()),
        ('tokens', ['pendulum'])
    ])

    output = command_tester.get_display()

    assert '\npendulum (0.6.0)\n Python datetimes made easy.\n' == output
test_client.py 文件源码 项目:presto-python-client 作者: prestodb 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_request_timeout():
    timeout = 0.1
    http_scheme = 'http'
    host = 'coordinator'
    port = 8080
    url = http_scheme + '://' + host + ':' + str(port) + constants.URL_STATEMENT_PATH

    def long_call(request, uri, headers):
        time.sleep(timeout * 2)
        return (200, headers, "delayed success")

    httpretty.enable()
    for method in [httpretty.POST, httpretty.GET]:
        httpretty.register_uri(method, url, body=long_call)

    # timeout without retry
    for request_timeout in [timeout, (timeout, timeout)]:
        req = PrestoRequest(
            host=host,
            port=port,
            user='test',
            http_scheme=http_scheme,
            max_attempts=1,
            request_timeout=request_timeout,
        )

        with pytest.raises(requests.exceptions.Timeout):
            req.get(url)

        with pytest.raises(requests.exceptions.Timeout):
            req.post('select 1')

    httpretty.disable()
    httpretty.reset()
conftest.py 文件源码 项目:tfs 作者: devopshq 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def tfs_server_mock():
    for method in (httpretty.GET, httpretty.POST, httpretty.PATCH):
        httpretty.register_uri(method, re.compile(r"http://tfs.tfs.ru(.*)"),
                               body=request_callback_get,
                               content_type="application/json")
test_cloud.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_download(self):
        httpretty.register_uri(
            httpretty.POST, DropboxAPIClient.DOWNLOAD_URL[1],
            body=TEST_CHUNK_BODY)

        self.assertEqual(TEST_CHUNK_BODY, self.client.download(self.chunk))
test_cloud.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_upload(self):
        httpretty.register_uri(
            httpretty.POST, DropboxAPIClient.UPLOAD_URL[1],
            body='')

        self.client.upload(self.chunk, TEST_CHUNK_BODY)
test_cloud.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_delete(self):
        httpretty.register_uri(
            httpretty.POST, DropboxAPIClient.DELETE_URL[1],
            body=TEST_CHUNK_BODY)

        self.client.delete(self.chunk)
test_cloud.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_upload(self):
        # Box requires the file id in the URL, the file_id is assigned by Box,
        # and therefore is stored in ChunkStorage.attrs.
        httpretty.register_uri(
            httpretty.POST,
            BoxAPIClient.UPLOAD_URL[1].format(file_id='abc123'),
            body='{"entries": [{"id":1}]}', content_type='application/json')

        self.client.upload(self.chunk, TEST_CHUNK_BODY)
test_cloud.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_upload(self):
        # GDrive requires the file id in the URL, the file_id is assigned by
        # Google, and therefore is stored in ChunkStorage.attrs.
        httpretty.register_uri(
            httpretty.POST,
            GDriveAPIClient.UPLOAD_URL[1].format(file_id='abc123'),
            body='{"id":1234}')

        self.client.upload(self.chunk, TEST_CHUNK_BODY)
test_views.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def setUp(self):
        super().setUp()
        httpretty.register_uri(
            METHODS.get(self.oauth2_client.USER_PROFILE_URL[0]),
            self.oauth2_client.USER_PROFILE_URL[1],
            body=json.dumps(USER_PROFILE_BOX),
            content_type='application/json')
        httpretty.register_uri(httpretty.POST, self.oauth2_client.CREATE_URL,
                               body=json.dumps(CREATE_BOX),
                               content_type='application/json')
test_cloud.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_download(self):
        httpretty.register_uri(
            httpretty.POST, DropboxAPIClient.DOWNLOAD_URL[1],
            body=TEST_CHUNK_BODY)

        self.assertEqual(TEST_CHUNK_BODY, self.client.download(self.chunk))
test_cloud.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_upload(self):
        httpretty.register_uri(
            httpretty.POST, DropboxAPIClient.UPLOAD_URL[1],
            body='')

        self.client.upload(self.chunk, TEST_CHUNK_BODY)
test_cloud.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_delete(self):
        httpretty.register_uri(
            httpretty.POST, DropboxAPIClient.DELETE_URL[1],
            body=TEST_CHUNK_BODY)

        self.client.delete(self.chunk)
test_cloud.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_upload(self):
        # Box requires the file id in the URL, the file_id is assigned by Box,
        # and therefore is stored in ChunkStorage.attrs.
        httpretty.register_uri(
            httpretty.POST,
            BoxAPIClient.UPLOAD_URL[1].format(file_id='abc123'),
            body='{"entries": [{"id":1}]}', content_type='application/json')

        self.client.upload(self.chunk, TEST_CHUNK_BODY)
test_views.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def setUp(self):
        httpretty.enable()
        httpretty.register_uri(
            httpretty.POST, self.oauth2_client.ACCESS_TOKEN_URL,
            body=json.dumps(ACCESS_TOKEN),
            content_type='application/json')
test_views.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def setUp(self):
        super().setUp()
        httpretty.register_uri(
            METHODS.get(self.oauth2_client.USER_PROFILE_URL[0]),
            self.oauth2_client.USER_PROFILE_URL[1],
            body=json.dumps(USER_PROFILE_BOX),
            content_type='application/json')
        httpretty.register_uri(httpretty.POST, self.oauth2_client.CREATE_URL,
                               body=json.dumps(CREATE_BOX),
                               content_type='application/json')
test_cloud.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_download(self):
        httpretty.register_uri(
            httpretty.POST, DropboxAPIClient.DOWNLOAD_URL[1],
            body=TEST_CHUNK_BODY)

        self.assertEqual(TEST_CHUNK_BODY, self.client.download(self.chunk))
test_cloud.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_upload(self):
        httpretty.register_uri(
            httpretty.POST, DropboxAPIClient.UPLOAD_URL[1],
            body='')

        self.client.upload(self.chunk, TEST_CHUNK_BODY)
test_cloud.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_delete(self):
        httpretty.register_uri(
            httpretty.POST, DropboxAPIClient.DELETE_URL[1],
            body=TEST_CHUNK_BODY)

        self.client.delete(self.chunk)
test_cloud.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_upload(self):
        # GDrive requires the file id in the URL, the file_id is assigned by
        # Google, and therefore is stored in ChunkStorage.attrs.
        httpretty.register_uri(
            httpretty.POST,
            GDriveAPIClient.UPLOAD_URL[1].format(file_id='abc123'),
            body='{"id":1234}')

        self.client.upload(self.chunk, TEST_CHUNK_BODY)
test_views.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def setUp(self):
        httpretty.enable()
        httpretty.register_uri(
            httpretty.POST, self.oauth2_client.ACCESS_TOKEN_URL,
            body=json.dumps(ACCESS_TOKEN),
            content_type='application/json')
test_views.py 文件源码 项目:cloudstrype 作者: btimby 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setUp(self):
        super().setUp()
        httpretty.register_uri(
            METHODS.get(self.oauth2_client.USER_PROFILE_URL[0]),
            self.oauth2_client.USER_PROFILE_URL[1],
            body=json.dumps(USER_PROFILE_BOX),
            content_type='application/json')
        httpretty.register_uri(httpretty.POST, self.oauth2_client.CREATE_URL,
                               body=json.dumps(CREATE_BOX),
                               content_type='application/json')


问题


面经


文章

微信
公众号

扫码关注公众号