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


Python responses.add方法代码示例

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


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

示例1: test_session_get

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def test_session_get():
    responses.add(
        responses.GET,
        'http://foo.bar.baz/api/v1.0/test',
        body='okay',
        status=200)
    host = 'foo.bar.baz'
    token = '5f1e08b6-38ec-4a99-9d0f-00d29c4e325b'
    marker = '40c3eaf6-6a8a-11e7-a4bd-080027ef795a'

    def auth_gen():
        return [('X-Auth-Token', token)]

    dd_ses = dc_session.DrydockSession(host, auth_gen=auth_gen, marker=marker)

    resp = dd_ses.get('v1.0/test')
    req = resp.request

    assert req.headers.get('X-Auth-Token', None) == token
    assert req.headers.get('X-Context-Marker', None) == marker 
开发者ID:airshipit,项目名称:drydock,代码行数:22,代码来源:test_drydock_client.py

示例2: test_session_get_returns_401

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def test_session_get_returns_401(*args):
    responses.add(
        responses.GET,
        'http://foo.bar.baz/api/v1.0/test',
        body='okay',
        status=401)
    host = 'foo.bar.baz'
    token = '5f1e08b6-38ec-4a99-9d0f-00d29c4e325b'
    marker = '40c3eaf6-6a8a-11e7-a4bd-080027ef795a'

    def auth_gen():
        return [('X-Auth-Token', dc_session.KeystoneClient.get_token())]

    dd_ses = dc_session.DrydockSession(host, auth_gen=auth_gen, marker=marker)

    resp = dd_ses.get('v1.0/test')
    req = resp.request

    assert req.headers.get('X-Auth-Token', None) == token
    assert req.headers.get('X-Context-Marker', None) == marker
    assert dc_session.KeystoneClient.get_token.call_count == 2 
开发者ID:airshipit,项目名称:drydock,代码行数:23,代码来源:test_drydock_client.py

示例3: test_client_get_nodes_for_filter_post

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def test_client_get_nodes_for_filter_post():
    node_list = ['node1', 'node2']

    host = 'foo.bar.baz'

    responses.add(
        responses.POST,
        "http://%s/api/v1.0/nodefilter" % (host),
        json=node_list,
        status=200)

    dd_ses = dc_session.DrydockSession(host)
    dd_client = dc_client.DrydockClient(dd_ses)

    design_ref = {'ref': 'hello'}
    validation_resp = dd_client.get_nodes_for_filter(design_ref)

    assert 'node1' in validation_resp
    assert 'node2' in validation_resp 
开发者ID:airshipit,项目名称:drydock,代码行数:21,代码来源:test_drydock_client.py

示例4: test_client_validate_design_post

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def test_client_validate_design_post():
    validation = {'status': 'success'}

    host = 'foo.bar.baz'

    responses.add(
        responses.POST,
        "http://%s/api/v1.0/validatedesign" % (host),
        json=validation,
        status=200)

    dd_ses = dc_session.DrydockSession(host)
    dd_client = dc_client.DrydockClient(dd_ses)

    validation_resp = dd_client.validate_design('href-placeholder')

    assert validation_resp['status'] == validation['status'] 
开发者ID:airshipit,项目名称:drydock,代码行数:19,代码来源:test_drydock_client.py

示例5: test_post

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def test_post(patch1, patch2):
    """
    Test post functionality
    """
    responses.add(
        responses.POST,
        'http://promhost:80/api/v1.0/node-label/n1',
        body='{"key1":"label1"}',
        status=200)

    prom_session = PromenadeSession()
    result = prom_session.post(
        'v1.0/node-label/n1', body='{"key1":"label1"}', timeout=(60, 60))

    assert PROM_HOST == prom_session.host
    assert result.status_code == 200 
开发者ID:airshipit,项目名称:drydock,代码行数:18,代码来源:test_k8sdriver_promenade_client.py

示例6: test_relabel_node

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def test_relabel_node(patch1, patch2):
    """
    Test relabel node call from Promenade
    Client
    """
    responses.add(
        responses.PUT,
        'http://promhost:80/api/v1.0/node-labels/n1',
        body='{"key1":"label1"}',
        status=200)

    prom_client = PromenadeClient()

    result = prom_client.relabel_node('n1', {"key1": "label1"})

    assert result == {"key1": "label1"} 
开发者ID:airshipit,项目名称:drydock,代码行数:18,代码来源:test_k8sdriver_promenade_client.py

示例7: test_parse_authentication_response_preserves_id_token_jwt

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def test_parse_authentication_response_preserves_id_token_jwt(self):
        facade = PyoidcFacade(ProviderConfiguration(provider_metadata=self.PROVIDER_METADATA,
                                                    client_metadata=self.CLIENT_METADATA),
                              self.REDIRECT_URI)
        state = 'state-1234'
        now = int(time.time())
        id_token, id_token_signing_key = signed_id_token({
            'iss': self.PROVIDER_METADATA['issuer'],
            'sub': 'test_sub',
            'aud': 'client1',
            'exp': now + 1,
            'iat': now
        })
        responses.add(responses.GET,
                      self.PROVIDER_METADATA['jwks_uri'],
                      json={'keys': [id_token_signing_key.serialize()]})
        auth_response = AuthorizationResponse(**{'state': state, 'id_token': id_token})
        parsed_auth_response = facade.parse_authentication_response(auth_response)
        assert isinstance(parsed_auth_response, AuthorizationResponse)
        assert parsed_auth_response['state'] == state
        assert parsed_auth_response['id_token_jwt'] == id_token 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:23,代码来源:test_pyoidc_facade.py

示例8: test_should_fetch_provider_metadata_if_not_given

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def test_should_fetch_provider_metadata_if_not_given(self):
        provider_metadata = {
            'issuer': self.PROVIDER_BASEURL,
            'authorization_endpoint': self.PROVIDER_BASEURL + '/auth',
            'jwks_uri': self.PROVIDER_BASEURL + '/jwks'
        }
        responses.add(responses.GET,
                      self.PROVIDER_BASEURL + '/.well-known/openid-configuration',
                      json=provider_metadata)

        provider_config = ProviderConfiguration(issuer=self.PROVIDER_BASEURL,
                                                client_registration_info=ClientRegistrationInfo())
        provider_config.ensure_provider_metadata()
        assert provider_config._provider_metadata['issuer'] == self.PROVIDER_BASEURL
        assert provider_config._provider_metadata['authorization_endpoint'] == self.PROVIDER_BASEURL + '/auth'
        assert provider_config._provider_metadata['jwks_uri'] == self.PROVIDER_BASEURL + '/jwks' 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:18,代码来源:test_provider_configuration.py

示例9: test_should_register_dynamic_client_if_client_registration_info_is_given

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def test_should_register_dynamic_client_if_client_registration_info_is_given(self):
        registration_endpoint = self.PROVIDER_BASEURL + '/register'
        responses.add(responses.POST, registration_endpoint, json={'client_id': 'client1', 'client_secret': 'secret1'})

        provider_config = ProviderConfiguration(
            provider_metadata=self.provider_metadata(registration_endpoint=registration_endpoint),
            client_registration_info=ClientRegistrationInfo())

        extra_args = {'extra_args': 'should be passed'}
        redirect_uris = ['https://client.example.com/redirect']
        provider_config.register_client(redirect_uris, extra_args)
        assert provider_config._client_metadata['client_id'] == 'client1'
        assert provider_config._client_metadata['client_secret'] == 'secret1'
        assert provider_config._client_metadata['redirect_uris'] == redirect_uris

        expected_registration_request = {'redirect_uris': redirect_uris}
        expected_registration_request.update(extra_args)
        assert json.loads(responses.calls[0].request.body.decode('utf-8')) == expected_registration_request 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:20,代码来源:test_provider_configuration.py

示例10: test_token_error_response_calls_to_error_view_if_set

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def test_token_error_response_calls_to_error_view_if_set(self):
        token_endpoint = self.PROVIDER_BASEURL + '/token'
        error_response = {'error': 'invalid_request', 'error_description': 'test error'}
        responses.add(responses.POST, token_endpoint, json=error_response)

        authn = self.init_app(provider_metadata_extras={'token_endpoint': token_endpoint})
        error_view_mock = self.get_view_mock()
        authn.error_view(error_view_mock)
        state = 'test_tate'
        with self.app.test_request_context('/redirect_uri?code=foo&state={}'.format(state)):
            UserSession(flask.session, self.PROVIDER_NAME)
            flask.session['state'] = state
            flask.session['nonce'] = 'test_nonce'
            result = authn._handle_authentication_response()

        self.assert_view_mock(error_view_mock, result)
        error_view_mock.assert_called_with(**error_response) 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:19,代码来源:test_flask_pyoidc.py

示例11: test_interest_form_post_triggers_slack_notification

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [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

示例12: test_invalid_confidentials_should_raise

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def test_invalid_confidentials_should_raise():
    responses.add(
        responses.POST,
        "https://api.twitter.com/oauth2/token",
        json={
            "errors": [
                {
                    "code": 99,
                    "message": "Unable to verify your credentials",
                    "label": "authenticity_token_error",
                }
            ]
        },
        status=403,
    )

    with pytest.raises(e.BearerTokenNotFetchedError):
        _ = twt_img.Downloader("my api key", "my api secret") 
开发者ID:morinokami,项目名称:twitter-image-downloader,代码行数:20,代码来源:test_app.py

示例13: setUp

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def setUp(self):
        self.client = self.app.test_client()
        self.app_context = self.app.app_context()
        self.app_context.push()
        for table in reversed(self.db.metadata.sorted_tables):
            self.db.session.execute(table.delete())
        # Mock responses from haveibeenpwned.
        responses.add(
            responses.GET,
            re.compile(
                r"^(https:\/\/api\.pwnedpasswords\.com\/range\/836BA).*"),
            body=("BDDC66080E01D52B8272AA9461C69EE0496:12145\n"
                  "00d4f6e8fa6eecad2a3aa415eec418d38ec:2"))
        responses.add(
            responses.GET,
            re.compile(
                r"^(https:\/\/api\.pwnedpasswords\.com\/)(?!.*836BA).*"),
            body=("BDDC66080E01D52B8272AA9461C69EE0496:12145\n"
                  "00d4f6e8fa6eecad2a3aa415eec418d38ec:2")) 
开发者ID:smallwat3r,项目名称:shhh,代码行数:21,代码来源:test_app.py

示例14: test_api_post_haveibeenpwned_not_reachable

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def test_api_post_haveibeenpwned_not_reachable(self):
        payload = {
            "secret": "secret message",
            "passphrase": "Hello123",
            "haveibeenpwned": True
        }
        with self.client as c:
            with responses.RequestsMock() as rsps:
                rsps.add(
                    responses.GET,
                    re.compile(r"^(https:\/\/api\.pwnedpasswords\.com\/).*"),
                    body=Exception)
                response = json.loads(
                    c.post("/api/c", json=payload).get_data())

        # haveibeenpwned wasn't reachable, but secret still created if it has
        # all mandatory requirements.
        r = Parse(response)
        self.assertEqual(r.response.status, "created") 
开发者ID:smallwat3r,项目名称:shhh,代码行数:21,代码来源:test_app.py

示例15: test_extract_link

# 需要导入模块: import responses [as 别名]
# 或者: from responses import add [as 别名]
def test_extract_link(self):
        success_response = {'success': True, 'data': 'link'}
        responses.add(responses.POST, constants.ENDPOINTS['extract_link'],
                      json=success_response,
                      status=200)
        responses.add(responses.POST, constants.ENDPOINTS['extract_link'],
                      status=401)
        # success call
        result = utils.extract_link(self.session, 'https://www.ojbk.com')
        self.assertEqual(result, 'link')
        self.assertEqual(len(responses.calls), 1)
        self.assertEqual(responses.calls[0].request.url, constants.ENDPOINTS['extract_link'])
        self.assertEqual(responses.calls[0].response.json(), success_response)
        # failed call
        with self.assertRaises(requests.HTTPError) as cm:
            utils.extract_link(self.session, 'https://www.ojbk.com')
        self.assertEqual(len(responses.calls), 2)
        self.assertEqual(cm.exception.response.status_code, 401) 
开发者ID:Sorosliu1029,项目名称:Jike-Metro,代码行数:20,代码来源:test_utils.py


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