当前位置: 首页>>代码示例>>Python>>正文


Python requests_mock.ANY属性代码示例

本文整理汇总了Python中requests_mock.ANY属性的典型用法代码示例。如果您正苦于以下问题:Python requests_mock.ANY属性的具体用法?Python requests_mock.ANY怎么用?Python requests_mock.ANY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在requests_mock的用法示例。


在下文中一共展示了requests_mock.ANY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_download_file

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def test_download_file(sample_zip_data, tmpdir):
    dl_path = 'http://some.url/thezipfile.zip'
    target_path = os.path.join(tmpdir.strpath, 'target.zip')

    with requests_mock.Mocker() as mock:
        # Return any size (doesn't matter, only for prints)
        mock.head(requests_mock.ANY, headers={'Content-Length': '100'})

        mock.get(dl_path, content=sample_zip_data)

        download.download_file(dl_path, target_path)

    assert os.path.isfile(target_path)

    with open(target_path, 'rb') as f:
        assert f.read() == sample_zip_data 
开发者ID:ynop,项目名称:audiomate,代码行数:18,代码来源:test_download.py

示例2: test_available_files

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def test_available_files(self, sample_response):
        with requests_mock.Mocker() as mock:
            # Return any size (doesn't matter, only for prints)
            mock.head(requests_mock.ANY, headers={'Content-Length': '100'})

            url = 'http://someurl.com/some/download/dir'
            mock.get(url, text=sample_response)
            files = voxforge.VoxforgeDownloader.available_files(url)

            assert set(files) == {
                'http://someurl.com/some/download/dir/1337ad-20170321-amr.tgz',
                'http://someurl.com/some/download/dir/1337ad-20170321-bej.tgz',
                'http://someurl.com/some/download/dir/1337ad-20170321-blf.tgz',
                'http://someurl.com/some/download/dir/1337ad-20170321-czb.tgz',
                'http://someurl.com/some/download/dir/1337ad-20170321-hii.tgz'
            } 
开发者ID:ynop,项目名称:audiomate,代码行数:18,代码来源:test_voxforge.py

示例3: get_sdk

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def get_sdk(self, mock):

        sdk = SDK('whatever', 'whatever', 'mock://whatever', redirect_uri='mock://whatever-redirect')

        self.authentication_mock(mock)
        sdk.platform().login('18881112233', None, 'password')

        matcher = re.compile('pubsub\.pubnub\.com')

        mock.register_uri(
            method=requests_mock.ANY,
            url=matcher,
            text=''
        )

        matcher = re.compile('ps\.pndsn\.com')

        mock.register_uri(
            method=requests_mock.ANY,
            url=matcher,
            text=''
        )

        return sdk 
开发者ID:ringcentral,项目名称:ringcentral-python,代码行数:26,代码来源:testcase.py

示例4: test_token_refresh

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def test_token_refresh():
    update_called = []

    # hacky way to test side effect
    def token_updater(token):
        update_called.append(1)

    client = OuraClient('test_id', access_token='token', refresh_callback=token_updater)
    adapter.register_uri(requests_mock.POST, requests_mock.ANY, status_code=401, text=json.dumps({
            'access_token': 'fake_return_access_token',
            'refresh_token': 'fake_return_refresh_token'
        }))
    adapter.register_uri(requests_mock.GET, requests_mock.ANY, status_code=401, text=json.dumps({ 'a': 'b'}))

    client._session.mount(client.API_ENDPOINT, adapter)
    try:
        resp = client.user_info()
    except:
        pass
    assert len(update_called) == 1 
开发者ID:turing-complet,项目名称:python-ouraring,代码行数:22,代码来源:test_client.py

示例5: test_score_task

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def test_score_task(self, m):
        # arrange
        expected_headers = {
            'x-api-user': self.api_user,
            'x-api-key': self.api_key,
        }

        expected_url = 'https://habitica.com/api/v3/tasks/task1/score/up'

        m.post(requests_mock.ANY, text='{}')

        # act
        app.score_task('task1', 'up')

        # assert
        history = m.request_history
        self.assertEqual(len(history), 1)

        request = history[0]
        self.assertEqual(request.url, expected_url)
        self.assertEqual(request.method, 'POST')
        for item in expected_headers.items():
            self.assertIn(item, request.headers.items()) 
开发者ID:niteshpatel,项目名称:habitica-github,代码行数:25,代码来源:test_app.py

示例6: test_signature_post

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def test_signature_post(self, mock_logger, m):
        '''Test signature on a post request.'''
        params = {'max_amount': 10,
                  'price': 1337,
                  'trading_pair': 'btceur',
                  'type': 'buy' }
        response = self.sampleData('createOrder')
        m.post(requests_mock.ANY, json=response, status_code=201)
        self.conn.createOrder(params['type'],
                              params['trading_pair'],
                              params['max_amount'],
                              params['price'])
        history = m.request_history
        request_signature = history[0].headers.get('X-API-SIGNATURE')
        verified_signature = self.verifySignature(self.conn.orderuri,
                                                  'POST', self.conn.nonce,
                                                  params)
        self.assertEqual(request_signature, verified_signature)
        self.assertTrue(mock_logger.debug.called) 
开发者ID:peshay,项目名称:btcde,代码行数:21,代码来源:test_btcde_func.py

示例7: test_show_orderbook

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def test_show_orderbook(self, mock_logger, m):
        '''Test function showOrderbook.'''
        params = {'price': 1337,
                  'trading_pair': 'btceur',
                  'type': 'buy'}
        base_url = 'https://api.bitcoin.de/v2/orders'
        url_args = '?' + urlencode(params)
        response = self.sampleData('showOrderbook_buy')
        m.get(requests_mock.ANY, json=response, status_code=200)
        self.conn.showOrderbook(params.get('type'),
                                params.get('trading_pair'),
                                price=params.get('price'))
        history = m.request_history
        self.assertEqual(history[0].method, "GET")
        self.assertEqual(history[0].url, base_url + url_args)
        self.assertTrue(mock_logger.debug.called) 
开发者ID:peshay,项目名称:btcde,代码行数:18,代码来源:test_btcde_func.py

示例8: test_createOrder

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def test_createOrder(self, mock_logger, m):
        '''Test function createOrder.'''
        params = {'max_amount': '10',
                  'price': '10',
                  'trading_pair': 'btceur',
                  'type': 'buy'
                  }
        base_url = 'https://api.bitcoin.de/v2/orders'
        url_args = '?' + urlencode(params)
        response = self.sampleData('createOrder')
        m.post(requests_mock.ANY, json=response, status_code=201)
        self.conn.createOrder(params.get('type'),
                              params.get('trading_pair'),
                              params.get('max_amount'),
                              params.get('price'))
        history = m.request_history
        self.assertEqual(history[0].method, "POST")
        self.assertEqual(history[0].url, base_url + url_args)
        self.assertTrue(mock_logger.debug.called) 
开发者ID:peshay,项目名称:btcde,代码行数:21,代码来源:test_btcde_func.py

示例9: test_executeTrade

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def test_executeTrade(self, mock_logger, m):
        '''Test function executeTrade.'''
        params = {'amount': '10',
                  'order_id': '1337',
                  'trading_pair': 'btceur',
                  'type': 'buy'}
        base_url = 'https://api.bitcoin.de/v2/trades/{}'\
                   .format(params.get('order_id'))
        url_args = '?' + urlencode(params)
        response = self.sampleData('executeTrade')
        m.get(requests_mock.ANY, json=response, status_code=200)
        m.post(requests_mock.ANY, json=response, status_code=201)
        self.conn.executeTrade(params.get('order_id'),
                               params.get('type'),
                               params.get('trading_pair'),
                               params.get('amount'))
        history = m.request_history
        self.assertEqual(history[0].method, "POST")
        self.assertEqual(history[0].url, base_url + url_args)
        self.assertTrue(mock_logger.debug.called) 
开发者ID:peshay,项目名称:btcde,代码行数:22,代码来源:test_btcde_func.py

示例10: setup_server

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def setup_server(m):
    """Add endpoints to the server."""
    # Content strings
    first_solver_response = structured_solver_data(solver_name)
    second_solver_response = structured_solver_data(second_solver_name)
    two_solver_response = '[' + first_solver_response + ',' + second_solver_response + ']'

    # Setup the server
    headers = {'X-Auth-Token': token}
    m.get(requests_mock.ANY, status_code=404)
    m.get(all_solver_url, status_code=403, request_headers={})
    m.get(solver1_url, status_code=403, request_headers={})
    m.get(solver2_url, status_code=403, request_headers={})
    m.get(all_solver_url, text=two_solver_response, request_headers=headers)
    m.get(solver1_url, text=first_solver_response, request_headers=headers)
    m.get(solver2_url, text=second_solver_response, request_headers=headers) 
开发者ID:dwavesystems,项目名称:dwave-cloud-client,代码行数:18,代码来源:test_mock_solver_loading.py

示例11: call_api

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def call_api(self, method, type="GET", params=None):
        with requests_mock.Mocker() as m:
            mock = {
                "DELETE": m.delete,
                "GET": m.get,
                "PUT": m.put,
                "POST": m.post,
                "PATCH": m.patch,
            }[type]

            if type == "DELETE":
                mock(requests_mock.ANY)
                return super(PacketMockManager, self).call_api(method, type, params)

            fixture = "%s_%s" % (type.lower(), method.lower())
            fixture = fixture.replace("/", "_").split("?")[0]
            fixture = "test/fixtures/%s.json" % fixture

            headers = {"content-type": "application/json"}

            with open(fixture) as data_file:
                j = json.load(data_file)

            mock(requests_mock.ANY, headers=headers, json=j)
            return super(PacketMockManager, self).call_api(method, type, params) 
开发者ID:packethost,项目名称:packet-python,代码行数:27,代码来源:test_packet.py

示例12: session

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def session():
    adapter = requests_mock.Adapter()
    session = requests.Session()
    session.mount(settings.SCHEDULER_URL, adapter)

    # Lets just listen to everything and sort it out ourselves
    adapter.register_uri(
        requests_mock.ANY, requests_mock.ANY,
        json=mock_kubernetes
    )

    return session 
开发者ID:deis,项目名称:controller,代码行数:14,代码来源:mock.py

示例13: test_uses_timeouts

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def test_uses_timeouts(self):
        c = Client('cfexampleapi', 'b4c0n73n7fu1')
        with requests_mock.mock() as m:
            m.register_uri('GET', ANY, status_code=500)
            self.assertRaises(HTTPError, c.entries)
            self.assertEqual(m.call_count, 1)
            self.assertEqual(m.request_history[0].timeout, 1)

        c = Client('cfexampleapi', 'b4c0n73n7fu1', timeout_s=0.1231570235)
        with requests_mock.mock() as m:
            m.register_uri('GET', ANY, status_code=500)
            self.assertRaises(HTTPError, c.entries)
            self.assertEqual(m.call_count, 1)
            self.assertEqual(m.request_history[0].timeout, c.timeout_s) 
开发者ID:contentful,项目名称:contentful.py,代码行数:16,代码来源:client_test.py

示例14: test_publishes_missing_recipes

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def test_publishes_missing_recipes(self, rs_settings, requestsmock):
        # Some records will be created with PUT.
        requestsmock.put(requests_mock.ANY, json={})
        # A signature request will be sent.
        requestsmock.patch(self.capabilities_workspace_collection_url, json={})
        # Instantiate local recipes.
        r1 = RecipeFactory(name="Test 1", enabler=UserFactory(), approver=UserFactory())
        r2 = RecipeFactory(name="Test 2", enabler=UserFactory(), approver=UserFactory())

        # Mock the server responses.
        # `r2` should be on the server
        requestsmock.get(
            self.capabilities_published_records_url, json={"data": [exports.recipe_as_record(r1)]}
        )
        # It will be created.
        r2_capabilities_url = self.capabilities_workspace_collection_url + f"/records/{r2.id}"
        requestsmock.put(r2_capabilities_url, json={})

        # Ignore any requests before this point
        requestsmock._adapter.request_history = []

        call_command("sync_remote_settings")

        requests = requestsmock.request_history
        # First request should be to get the existing records
        assert requests[0].method == "GET"
        assert requests[0].url.endswith(self.capabilities_published_records_url)
        # The next should be to PUT the missing recipe2
        assert requests[1].method == "PUT"
        assert requests[1].url.endswith(r2_capabilities_url)
        # The final one should be to approve the changes
        assert requests[2].method == "PATCH"
        assert requests[2].url.endswith(self.capabilities_workspace_collection_url)
        # And there are no extra requests
        assert len(requests) == 3 
开发者ID:mozilla,项目名称:normandy,代码行数:37,代码来源:test_commands.py

示例15: test_republishes_outdated_recipes

# 需要导入模块: import requests_mock [as 别名]
# 或者: from requests_mock import ANY [as 别名]
def test_republishes_outdated_recipes(self, rs_settings, requestsmock):
        # Some records will be created with PUT.
        requestsmock.put(requests_mock.ANY, json={})
        # A signature request will be sent.
        requestsmock.patch(self.capabilities_workspace_collection_url, json={})
        # Instantiate local recipes.
        r1 = RecipeFactory(name="Test 1", enabler=UserFactory(), approver=UserFactory())
        r2 = RecipeFactory(name="Test 2", enabler=UserFactory(), approver=UserFactory())

        # Mock the server responses.
        to_update = {**exports.recipe_as_record(r2), "name": "Outdated name"}
        requestsmock.get(
            self.capabilities_published_records_url,
            json={"data": [exports.recipe_as_record(r1), to_update]},
        )
        # It will be updated.
        r2_capabilities_url = self.capabilities_workspace_collection_url + f"/records/{r2.id}"
        requestsmock.put(r2_capabilities_url, json={})

        # Ignore any requests before this point
        requestsmock._adapter.request_history = []
        call_command("sync_remote_settings")

        requests = requestsmock.request_history
        # The first request should be to get the existing records
        assert requests[0].method == "GET"
        assert requests[0].url.endswith(self.capabilities_published_records_url)
        # The next one should be to PUT the outdated recipe2
        assert requests[1].method == "PUT"
        assert requests[1].url.endswith(r2_capabilities_url)
        # The final one should be to approve the changes
        assert requests[2].method == "PATCH"
        assert requests[2].url.endswith(self.capabilities_workspace_collection_url)
        # And there are no extra requests
        assert len(requests) == 3 
开发者ID:mozilla,项目名称:normandy,代码行数:37,代码来源:test_commands.py


注:本文中的requests_mock.ANY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。