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


Python responses.reset方法代码示例

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


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

示例1: test_interest_form_post_triggers_slack_notification

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def test_interest_form_post_triggers_slack_notification(self, testapp):
        ''' A valid interest form post triggers a Slack notification.
        '''

        # set a fake Slack webhook URL
        fake_webhook_url = 'http://webhook.example.com/'
        current_app.config['SLACK_WEBHOOK_URL'] = fake_webhook_url

        # create a mock to receive POST requests to that URL
        responses.add(responses.POST, fake_webhook_url, status=200)

        # post an interest form submission
        testapp.post("/interest/", params=dict(name="Jean Weaver", agency="Clinton Police Department", location="Clinton, OK", phone="580-970-3338", email="jean.weaver@example.com", comments="I'm interested in Comport as an open-source tool!"))

        # test the captured post payload
        post_body = json.loads(responses.calls[0].request.body)
        assert 'New Interest Form Submission!' in post_body['text']

        # delete the fake Slack webhook URL
        del(current_app.config['SLACK_WEBHOOK_URL'])
        # reset the mock
        responses.reset() 
开发者ID:codeforamerica,项目名称:comport,代码行数:24,代码来源:test_interest_form.py

示例2: testRetryDelay

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def testRetryDelay():
    global call
    call = 0
    def request_callback(request):
        global call
        if call == 0 :
            call = 1
            return (200, headers,  '{"meta":{"code":999,"message":"PROBLEM","retryable":true, "details":[]},"data":{}}')
        elif call == 1 :
            call = 2
            "second attempt"
            return (200, headers,  '{"meta":{"code":999,"message":"PROBLEM","retryable":true,"details":[]},"data":{}}')
        elif call == 2 :
            call = 3
            return (200, headers,  '{"meta":{"code":200,"message":"OK","details":[]},"data":{}}')
    responses.add_callback(responses.GET, 'https://REGION-api.postmen.com/v3/labels', callback=request_callback)
    api = Postmen('KEY', 'REGION')
    api.get('labels')
    responses.reset()

# TEST 9 
开发者ID:postmen,项目名称:postmen-sdk-python,代码行数:23,代码来源:postmen_test.py

示例3: testRetryMaxAttempt

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def testRetryMaxAttempt(monkeypatch):
    monkeypatch.setattr(time, 'sleep', lambda s: None)
    global call
    call = 0
    def request_callback(request):
        global call
        if call < 4 :
            call += 1
            return (200, headers,  '{"meta":{"code":999,"message":"PROBLEM","retryable":true, "details":[]},"data":{}}')
        else :
            return (200, headers,  '{"meta":{"code":200,"message":"OK","details":[]},"data":{}}')
    responses.add_callback(responses.GET, 'https://REGION-api.postmen.com/v3/labels', callback=request_callback)
    api = Postmen('KEY', 'REGION')
    before = time.time()
    api.get('labels')
    after = time.time()
    responses.reset()
    monkeypatch.setattr(time, 'sleep', lambda s: None)

# TEST 10 
开发者ID:postmen,项目名称:postmen-sdk-python,代码行数:22,代码来源:postmen_test.py

示例4: testRetryMaxAttemptExceeded

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def testRetryMaxAttemptExceeded(monkeypatch):
    monkeypatch.setattr(time, 'sleep', lambda s: None)
    global call
    call = 0
    def request_callback(request):
        global call
        if call < 5 :
            call += 1
            return (200, headers,  '{"meta":{"code":999,"message":"PROBLEM","retryable":true, "details":[]},"data":{}}')
        else :
            pytest.fail("Maximum 5 attempts of retry, test #10 failed")
    responses.add_callback(responses.GET, 'https://REGION-api.postmen.com/v3/labels', callback=request_callback)
    api = Postmen('KEY', 'REGION')
    with pytest.raises(PostmenException) as e:
        api.get('labels')
    responses.reset()
    monkeypatch.setattr(time, 'sleep', lambda s: None)
    assert "PROBLEM" in str(e.value.message())
    assert 999 == e.value.code()

# TEST 11 
开发者ID:postmen,项目名称:postmen-sdk-python,代码行数:23,代码来源:postmen_test.py

示例5: testArguments11

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def testArguments11(monkeypatch):
    monkeypatch.setattr(time, 'sleep', lambda s: None)
    global call
    call = 0
    def request_callback(request):
        global call
        if call < 1 :
            call += 1
            return (200, headers,  '{"meta":{"code":999,"message":"PROBLEM","retryable":true, "details":[]},"data":{}}')
        else :
            pytest.fail("Shall not retry if retry = False, test #11 failed")
    responses.add_callback(responses.GET, 'https://REGION-api.postmen.com/v3/labels', callback=request_callback)
    api = Postmen('KEY', 'REGION', retry=False)
    with pytest.raises(PostmenException) as e:
        api.get('labels')
    responses.reset()
    monkeypatch.setattr(time, 'sleep', lambda s: None)
    assert "PROBLEM" in str(e.value.message())
    assert 999 == e.value.code()
    assert e.value.retryable()

# TEST 12 
开发者ID:postmen,项目名称:postmen-sdk-python,代码行数:24,代码来源:postmen_test.py

示例6: testRateLimit

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def testRateLimit(monkeypatch):
    monkeypatch.setattr(time, 'sleep', lambda s: None)
    global call
    call = 0
    def request_callback(request):
        global call
        if call == 0 :
            call = 1
            return (200, exceeded,  '{"meta":{"code":429,"message":"EXCEEDED","retryable":true, "details":[]},"data":{}}')
        elif call == 1 :
            return (200, headers,  '{"meta":{"code":200,"message":"OK","details":[]},"data":{}}')
    responses.add_callback(responses.GET, 'https://REGION-api.postmen.com/v3/labels', callback=request_callback)
    api = Postmen('KEY', 'REGION')
    api.get('labels')
    responses.reset()
    monkeypatch.setattr(time, 'sleep', lambda s: None)

# TEST 14 
开发者ID:postmen,项目名称:postmen-sdk-python,代码行数:20,代码来源:postmen_test.py

示例7: test_create_node

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def test_create_node(self):
        """
        Verify that node creation makes the correct request and returns the ID
        contained in the response, and raises an exception for non-201 status codes.
        """
        self.mock_api_client()

        response_data = {'id': self.node_id}
        self.mock_node_create(response_data, 201)

        node_data = {'foo': 'bar'}
        node_id = self.publisher.create_node(node_data)

        assert responses.calls[-1].request.url == self.publisher.node_api_base
        assert json.loads(responses.calls[-1].request.body) == node_data
        assert node_id == self.node_id

        responses.reset()

        self.mock_api_client()
        self.mock_node_create(response_data, 500)

        with pytest.raises(NodeCreateError):
            self.publisher.create_node(node_data) 
开发者ID:edx,项目名称:course-discovery,代码行数:26,代码来源:test_publishers.py

示例8: test_edit_node

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def test_edit_node(self):
        """
        Verify that node editing makes the correct request and raises an exception
        for non-200 status codes.
        """
        self.mock_api_client()
        self.mock_node_edit(200)

        node_data = {'foo': 'bar'}
        self.publisher.edit_node(self.node_id, node_data)

        assert responses.calls[-1].request.url == '{base}/{node_id}'.format(
            base=self.publisher.node_api_base,
            node_id=self.node_id
        )
        assert json.loads(responses.calls[-1].request.body) == node_data

        responses.reset()

        self.mock_api_client()
        self.mock_node_edit(500)

        with pytest.raises(NodeEditError):
            self.publisher.edit_node(self.node_id, node_data) 
开发者ID:edx,项目名称:course-discovery,代码行数:26,代码来源:test_publishers.py

示例9: test_delete_node

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def test_delete_node(self):
        """
        Verify that node deletion makes the correct request and raises an exception
        for non-204 status codes.
        """
        self.mock_api_client()
        self.mock_node_delete(200)

        self.publisher.delete_node(self.node_id)

        assert responses.calls[-1].request.url == '{base}/{node_id}'.format(
            base=self.publisher.node_api_base,
            node_id=self.node_id
        )

        responses.reset()

        self.mock_api_client()
        self.mock_node_delete(500)

        with pytest.raises(NodeDeleteError):
            self.publisher.delete_node(self.node_id) 
开发者ID:edx,项目名称:course-discovery,代码行数:24,代码来源:test_publishers.py

示例10: test_access_token

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def test_access_token(self):
        """ Verify the property retrieves, and caches, an access token from the OAuth 2.0 provider. """
        token = 'abc123'
        partner = PartnerFactory()
        url = '{root}/access_token'.format(root=partner.oauth2_provider_url)
        body = {
            'access_token': token,
            'expires_in': 3600,
        }
        responses.add(responses.POST, url, json=body, status=200)
        assert partner.access_token == token
        assert len(responses.calls) == 1

        # No HTTP calls should be made if the access token is cached.
        responses.reset()
        assert partner.access_token == token 
开发者ID:edx,项目名称:course-discovery,代码行数:18,代码来源:test_models.py

示例11: test_get_user_api_data

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def test_get_user_api_data(self):
        """ Verify the method retrieves data from the User API and caches it. """
        username = Faker().user_name()
        data = {
            'username': username,
        }
        url = '{root}accounts/{username}'.format(root=self.site_configuration.user_api_url, username=username)
        responses.add(responses.GET, url, body=json.dumps(data), content_type=JSON, status=200)
        self.mock_access_token_response()

        actual = self.site_configuration.get_user_api_data(username)
        self.assertEqual(actual, data)
        self.assertEqual(len(responses.calls), 2)

        # Verify the data is cached
        responses.reset()
        actual = self.site_configuration.get_user_api_data(username)
        self.assertEqual(actual, data)
        self.assertEqual(len(responses.calls), 0) 
开发者ID:edx,项目名称:credentials,代码行数:21,代码来源:test_models.py

示例12: test_handle_processor_response

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def test_handle_processor_response(self):
        """Verify that the processor creates the appropriate PaymentEvent and Source objects."""
        for payer_info in (PaypalMixin.PAYER_INFO, {"shipping_address": None}):
            responses.reset()
            log.info("Testing payer_info with email set to: %s", payer_info.get("email"))
            self.mock_oauth2_response()
            self.mock_payment_creation_response(self.basket, find=True)
            self.mock_payment_execution_response(self.basket, payer_info=payer_info)

            handled_response = self.processor.handle_processor_response(self.RETURN_DATA, basket=self.basket)
            self.assertEqual(handled_response.currency, self.basket.currency)
            self.assertEqual(handled_response.total, self.basket.total_incl_tax)
            self.assertEqual(handled_response.transaction_id, self.PAYMENT_ID)
            self.assertEqual(
                handled_response.card_number,
                'PayPal ({})'.format(payer_info['email']) if 'email' in payer_info else 'PayPal Account')
            self.assertIsNone(handled_response.card_type) 
开发者ID:edx,项目名称:ecommerce,代码行数:19,代码来源:test_paypal.py

示例13: mock_urls

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def mock_urls(request):
    data = _DATA.tostring()
    checksum = _CHECKSUM
    url_data = _URL
    url_checksum = _URL + '.md5'

    if not request.param[0]:
        # Data URL is corrupted.
        url_data = url_data[:-1]
    if not request.param[1]:
        # Data is corrupted.
        data = data[:-1]
    if not request.param[2]:
        # Checksum URL is corrupted.
        url_checksum = url_checksum[:-1]
    if not request.param[3]:
        # Checksum is corrupted.
        checksum = checksum[:-1]

    _add_mock_response(url_data, data)
    _add_mock_response(url_checksum, checksum)
    yield request.param, url_data, url_checksum
    responses.reset() 
开发者ID:kwikteam,项目名称:klusta,代码行数:25,代码来源:test_datasets.py

示例14: test_learnings_alternate_command_echoed

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def test_learnings_alternate_command_echoed(self):
        ''' The learnings alternate command is echoed in the bot's reponse
        '''
        alternate_action = "recent"

        # set a fake Slack webhook URL
        fake_webhook_url = 'http://webhook.example.com/'
        current_app.config['SLACK_WEBHOOK_URL'] = fake_webhook_url

        # create a mock to receive POST requests to that URL
        responses.add(responses.POST, fake_webhook_url, status=200)

        rsp = self.post_command(text=alternate_action)
        self.assertTrue(rsp.status_code in range(200, 299), rsp.status_code)

        # test the captured post payload
        payload = json.loads(responses.calls[0].request.body)
        self.assertIsNotNone(payload['text'])
        self.assertTrue("gloss {action}".format(action=alternate_action) in payload['text'])

        # delete the fake Slack webhook URL
        del(current_app.config['SLACK_WEBHOOK_URL'])
        # reset the mock
        responses.reset() 
开发者ID:codeforamerica,项目名称:glossary-bot,代码行数:26,代码来源:test_bot.py

示例15: test_custom_slash_command_for_public_learnings

# 需要导入模块: import responses [as 别名]
# 或者: from responses import reset [as 别名]
def test_custom_slash_command_for_public_learnings(self):
        ''' A slash command other than /gloss is echoed in the bot's response
            to a public learnings request.
        '''
        test_command = "/gg"

        # set a fake Slack webhook URL
        fake_webhook_url = 'http://webhook.example.com/'
        current_app.config['SLACK_WEBHOOK_URL'] = fake_webhook_url

        # create a mock to receive POST requests to that URL
        responses.add(responses.POST, fake_webhook_url, status=200)

        rsp = self.post_command(text="learnings", slash_command=test_command)
        self.assertTrue(rsp.status_code in range(200, 299), rsp.status_code)

        # test the captured post payload
        payload = json.loads(responses.calls[0].request.body)
        self.assertIsNotNone(payload['text'])
        self.assertTrue("{command} learnings".format(command=test_command) in payload['text'])

        # delete the fake Slack webhook URL
        del(current_app.config['SLACK_WEBHOOK_URL'])
        # reset the mock
        responses.reset() 
开发者ID:codeforamerica,项目名称:glossary-bot,代码行数:27,代码来源:test_bot.py


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