當前位置: 首頁>>代碼示例>>Python>>正文


Python responses.POST屬性代碼示例

本文整理匯總了Python中responses.POST屬性的典型用法代碼示例。如果您正苦於以下問題:Python responses.POST屬性的具體用法?Python responses.POST怎麽用?Python responses.POST使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在responses的用法示例。


在下文中一共展示了responses.POST屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_client_get_nodes_for_filter_post

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [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

示例2: test_client_validate_design_post

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [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

示例3: test_post

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [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

示例4: test_invalid_confidentials_should_raise

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [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

示例5: test_cli_mapmatching

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [as 別名]
def test_cli_mapmatching():

    responses.add(
        responses.POST,
        'https://api.mapbox.com/matching/v4/mapbox.cycling.json?gps_precision=4&access_token=bogus',
        match_querystring=True,
        body="", status=200,
        content_type='application/json')

    runner = CliRunner()
    result = runner.invoke(
        main_group,
        ['--access-token', 'bogus',
         "mapmatching",
         "--gps-precision", "4",
         "--profile", "mapbox.cycling",
         "tests/line_feature.geojson"])
    assert result.exit_code == 0 
開發者ID:mapbox,項目名稱:mapbox-cli-py,代碼行數:20,代碼來源:test_mapmatching.py

示例6: mock_response

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [as 別名]
def mock_response(command, **kvargs):
    resp = RAIBIRD_COMMANDS["ControllerResponses"][command]
    data = command + ("00" * (resp["length"] - 1))
    for k in resp:
        if k in ["type", "length"]:
            continue
        param_template = "%%0%dX" % (resp[k]["length"])
        start_ = resp[k]["position"]
        end_ = start_ + resp[k]["length"]
        data = "%s%s%s" % (
            data[:start_],
            (param_template % kvargs[k]),
            data[end_:],
        )

    responses.add(
        responses.POST,
        "http://%s/stick" % MOCKED_RAINBIRD_URL,
        body=encrypt(
            (u'{"jsonrpc": "2.0", "result": {"data":"%s"}, "id": 1} ' % data),
            MOCKED_PASSWORD,
        ),
        content_type="application/octet-stream",
    ) 
開發者ID:jbarrancos,項目名稱:pyrainbird,代碼行數:26,代碼來源:integration_test.py

示例7: test_simple_geolocate

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [as 別名]
def test_simple_geolocate(self):
        responses.add(
            responses.POST,
            "https://www.googleapis.com/geolocation/v1/geolocate",
            body='{"location": {"lat": 51.0,"lng": -0.1},"accuracy": 1200.4}',
            status=200,
            content_type="application/json",
        )

        results = self.client.geolocate()

        self.assertEqual(1, len(responses.calls))
        self.assertURLEqual(
            "https://www.googleapis.com/geolocation/v1/geolocate?" "key=%s" % self.key,
            responses.calls[0].request.url,
        ) 
開發者ID:googlemaps,項目名稱:google-maps-services-python,代碼行數:18,代碼來源:test_geolocation.py

示例8: test_request_sources_error

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [as 別名]
def test_request_sources_error(status_code, error, error_body, caplog):
    responses.add(
        responses.POST,
        '{}/api/v1/requests'.format(CACHITO_URL),
        content_type='application/json',
        body=error_body,
        status=status_code,
    )

    with pytest.raises(error):
        CachitoAPI(CACHITO_URL).request_sources(CACHITO_REQUEST_REPO, CACHITO_REQUEST_REF)

    try:
        response_data = json.loads(error_body)
    except ValueError:  # json.JSONDecodeError in py3
        assert 'Cachito response' not in caplog.text
    else:
        response_json = 'Cachito response:\n{}'.format(json.dumps(response_data, indent=4))
        # Since Python 3.7 logger adds additional whitespaces by default -> checking without them
        assert re.sub(r'\s+', " ", response_json) in re.sub(r'\s+', " ", caplog.text) 
開發者ID:containerbuildsystem,項目名稱:atomic-reactor,代碼行數:22,代碼來源:test_cachito.py

示例9: test_create_identity

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [as 別名]
def test_create_identity(self):
        """
        The create_identity method should make the correct request to create an identity with the correct details in the
        identity store.
        """
        identity_store = IdentityStore("http://identitystore.org/", "auth-token", "msisdn")

        url = "http://identitystore.org/api/v1/identities/"
        responses.add_callback(
            responses.POST,
            url,
            callback=self.create_identity_callback,
            match_querystring=True,
            content_type="application/json",
        )

        identity = identity_store.create_identity(["tel:+1234"], name="Test identity", language="eng")
        self.assertEqual(identity["details"], {"addresses": {"msisdn": {"+1234": {}}}, "default_addr_type": "msisdn"}) 
開發者ID:rapidpro,項目名稱:casepro,代碼行數:20,代碼來源:test_junebug.py

示例10: test_okta_auth_value_error

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [as 別名]
def test_okta_auth_value_error(
            self,
            mock_print_tty,
            mock_makedirs
    ):
        responses.add(
            responses.POST,
            'https://organization.okta.com/api/v1/authn',
            body="NOT JSON",
            status=500
        )

        with self.assertRaises(SystemExit):
            Okta(
                user_name="user_name",
                user_pass="user_pass",
                organization="organization.okta.com"
            )

        print_tty_calls = [
            call("Error: Status Code: 500"),
            call("Error: Invalid JSON")
        ]

        mock_print_tty.assert_has_calls(print_tty_calls) 
開發者ID:godaddy,項目名稱:aws-okta-processor,代碼行數:27,代碼來源:test_okta.py

示例11: test_okta_connection_timeout

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [as 別名]
def test_okta_connection_timeout(
            self,
            mock_print_tty,
            mock_makedirs,
            mock_open,
            mock_chmod
    ):
        responses.add(
            responses.POST,
            'https://organization.okta.com/api/v1/authn',
            body=ConnectTimeout()
        )

        with self.assertRaises(SystemExit):
            Okta(
                user_name="user_name",
                user_pass="user_pass",
                organization="organization.okta.com"
            )

        print_tty_calls = [
            call("Error: Timed Out")
        ]

        mock_print_tty.assert_has_calls(print_tty_calls) 
開發者ID:godaddy,項目名稱:aws-okta-processor,代碼行數:27,代碼來源:test_okta.py

示例12: test_should_post_changelog

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [as 別名]
def test_should_post_changelog(self, mock_token):
        def request_callback(request):
            payload = json.loads(request.body)
            self.assertEqual(payload["tag_name"], "v1.0.0")
            self.assertEqual(payload["body"], "text")
            self.assertEqual(payload["draft"], False)
            self.assertEqual(payload["prerelease"], False)
            self.assertEqual("token super-token", request.headers["Authorization"])

            return 201, {}, json.dumps({})

        responses.add_callback(
            responses.POST,
            self.url,
            callback=request_callback,
            content_type="application/json",
        )
        status = Github.post_release_changelog("relekang", "rmoq", "1.0.0", "text")
        self.assertTrue(status) 
開發者ID:relekang,項目名稱:python-semantic-release,代碼行數:21,代碼來源:test_hvcs.py

示例13: test_should_return_false_status_if_it_failed

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [as 別名]
def test_should_return_false_status_if_it_failed(self):
        responses.add(
            responses.POST,
            self.url,
            status=400,
            body="{}",
            content_type="application/json",
        )
        responses.add(
            responses.GET,
            self.get_url,
            status=200,
            body='{"id": 1}',
            content_type="application/json",
        )
        responses.add(
            responses.POST,
            self.edit_url,
            status=400,
            body="{}",
            content_type="application/json",
        )
        self.assertFalse(
            Github.post_release_changelog("relekang", "rmoq", "1.0.0", "text")
        ) 
開發者ID:relekang,項目名稱:python-semantic-release,代碼行數:27,代碼來源:test_hvcs.py

示例14: test_add_txt_record

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [as 別名]
def test_add_txt_record(dnspod):
    responses.add(
        responses.POST, "https://dnsapi.cn/Record.Create",
        json={"status": {"code": "1"}}
    )
    dnspod.add_txt_record(RECORD_NAME, RECORD_VALUE)
    expected = get_params({
        "record_type": "TXT",
        "record_line": "默認",
        "ttl": str(TTL),
        "domain": DOMAIN,
        "sub_domain": SUB_DOMAIN,
        "value": RECORD_VALUE
    })
    assert len(responses.calls) == 1
    assert parse_data(responses.calls[0].request.body) == expected 
開發者ID:SkyLothar,項目名稱:certbot-dns-dnspod,代碼行數:18,代碼來源:client_test.py

示例15: test_remove_txt_record

# 需要導入模塊: import responses [as 別名]
# 或者: from responses import POST [as 別名]
def test_remove_txt_record(dnspod):
    responses.add(
        responses.POST, "https://dnsapi.cn/Record.List",
        json={
            "status": {"code": "1"},
            "records": [
                {"id": "err-0", "type": "A", "value": RECORD_VALUE},
                {"id": "err-1", "type": "TXT", "value": "some-value"},
                {"id": RECORD_ID, "type": "TXT", "value": RECORD_VALUE}
            ]
        }
    )
    responses.add(
        responses.POST, "https://dnsapi.cn/Record.Remove",
        json={"status": {"code": "1"}}
    )
    dnspod.remove_txt_record(RECORD_NAME, RECORD_VALUE)
    assert len(responses.calls) == 2

    expected_list = get_params({"domain": DOMAIN, "sub_domain": SUB_DOMAIN})
    assert parse_data(responses.calls[0].request.body) == expected_list

    expected_remove = get_params({"domain": DOMAIN, "record_id": RECORD_ID})
    assert parse_data(responses.calls[1].request.body), expected_remove 
開發者ID:SkyLothar,項目名稱:certbot-dns-dnspod,代碼行數:26,代碼來源:client_test.py


注:本文中的responses.POST屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。