本文整理汇总了Python中httpretty.GET属性的典型用法代码示例。如果您正苦于以下问题:Python httpretty.GET属性的具体用法?Python httpretty.GET怎么用?Python httpretty.GET使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类httpretty
的用法示例。
在下文中一共展示了httpretty.GET属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testDonostia
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def testDonostia(self):
httpretty.register_uri(
httpretty.GET,
self.geocoder.url,
body='{"thanks":"For using an OpenCage Data API","status":{"message":"OK","code":200},"rate":{"remaining":2482,"limit":"2500","reset":1402185600},"total_results":7,"results":[{"geometry":{"lat":"43.3213324","lng":"-1.9856227"},"annotations":{},"components":{"postcode":"20001;20002;20003;20004;20005;20006;20007;20008;20009;20010;20011;20012;20013;20014;20015;20016;20017;20018","county":"Donostialdea/Donostia-San Sebasti\u00e1n","state":"Basque Country","country":"Spain","city":"San Sebasti\u00e1n","country_code":"es"},"formatted":"San Sebasti\u00e1n, Donostialdea/Donostia-San Sebasti\u00e1n, 20001;20002;20003;20004;20005;20006;20007;20008;20009;20010;20011;20012;20013;20014;20015;20016;20017;20018, Basque Country, Spain, es","bounds":{"southwest":{"lat":"43.2178373","lng":"-2.086808"},"northeast":{"lng":"-1.8878838","lat":"43.3381344"}}},{"formatted":"Donostia, Irun, Bidasoa Beherea / Bajo Bidasoa, Basque Country, Spain, es","components":{"county":"Bidasoa Beherea / Bajo Bidasoa","state":"Basque Country","country":"Spain","city":"Irun","country_code":"es","road":"Donostia"},"bounds":{"southwest":{"lat":"43.3422299","lng":"-1.8022744"},"northeast":{"lng":"-1.8013452","lat":"43.3449598"}},"geometry":{"lng":"-1.8019153","lat":"43.3432784"},"annotations":{}},{"annotations":{},"geometry":{"lng":"-1.8022744","lat":"43.3422299"},"formatted":"Donostia, Anaka, Irun, Bidasoa Beherea / Bajo Bidasoa, Basque Country, Spain, es","components":{"county":"Bidasoa Beherea / Bajo Bidasoa","state":"Basque Country","country":"Spain","city":"Irun","suburb":"Anaka","country_code":"es","road":"Donostia"},"bounds":{"southwest":{"lng":"-1.8022971","lat":"43.3421635"},"northeast":{"lng":"-1.8022744","lat":"43.3422299"}}},{"geometry":{"lng":"-2.69312049872164","lat":"42.868297"},"annotations":{},"bounds":{"southwest":{"lng":"-2.6933154","lat":"42.8681484"},"northeast":{"lat":"42.8684357","lng":"-2.6929252"}},"formatted":"Donostia kalea, Ibaiondo, Vitoria-Gasteiz, Vitoria-Gasteizko Eskualdea / Cuadrilla de Vitoria, Basque Country, Spain, es","components":{"county":"Vitoria-Gasteizko Eskualdea / Cuadrilla de Vitoria","state":"Basque Country","country":"Spain","city":"Vitoria-Gasteiz","suburb":"Ibaiondo","country_code":"es","road":"Donostia kalea"}},{"bounds":{"southwest":{"lng":"-2.6889534","lat":"42.8620967"},"northeast":{"lat":"42.8623764","lng":"-2.6885774"}},"formatted":"Donostia kalea, Lakua, Vitoria-Gasteiz, Vitoria-Gasteizko Eskualdea / Cuadrilla de Vitoria, Basque Country, Spain, es","components":{"county":"Vitoria-Gasteizko Eskualdea / Cuadrilla de Vitoria","state":"Basque Country","country":"Spain","city":"Vitoria-Gasteiz","suburb":"Lakua","country_code":"es","road":"Donostia kalea"},"geometry":{"lat":"42.8622515","lng":"-2.68876582144679"},"annotations":{}},{"annotations":{},"geometry":{"lat":"51.5146888","lng":"-0.1609307"},"components":{"restaurant":"Donostia","country":"United Kingdom","state_district":"Greater London","country_code":"gb","county":"London","state":"England","suburb":"Marylebone","city":"City of Westminster","road":"Great Cumberland Mews"},"formatted":"Donostia, Great Cumberland Mews, Marylebone, City of Westminster, London, Greater London, England, United Kingdom, gb","bounds":{"northeast":{"lng":"-0.1608807","lat":"51.5147388"},"southwest":{"lat":"51.5146388","lng":"-0.1609807"}}},{"geometry":{"lat":43.31283,"lng":-1.97499},"annotations":{},"bounds":{"northeast":{"lng":"-1.92020404339","lat":"43.3401603699"},"southwest":{"lat":"43.2644081116","lng":"-2.04920697212"}},"formatted":"San Sebastian, Gipuzkoa, Basque Country, Spain, Donostia / San Sebasti\u00e1n","components":{"county":"Gipuzkoa","state":"Basque Country","country":"Spain","town":"San Sebastian","local administrative area":"Donostia / San Sebasti\u00e1n"}}],"timestamp":{"created_unix":1402136556,"created_http":"Sat, 07 Jun 2014 10:22:36 GMT"},"licenses":[{"name":"CC-BY-SA","url":"http://creativecommons.org/licenses/by-sa/3.0/"},{"name":"ODbL","url":"http://opendatacommons.org/licenses/odbl/summary/"}]}',
)
results = self.geocoder.geocode("Donostia")
self.assertTrue(
any((abs(result['geometry']['lat'] - 43.300836) < 0.05 and abs(result['geometry']['lng'] - -1.9809529) < 0.05) for result in results),
msg="Bad result"
)
# test that the results are in unicode
self.assertEqual(results[0]['formatted'], six.u('San Sebasti\xe1n, Donostialdea/Donostia-San Sebasti\xe1n, 20001;20002;20003;20004;20005;20006;20007;20008;20009;20010;20011;20012;20013;20014;20015;20016;20017;20018, Basque Country, Spain, es'))
示例2: testRateLimitExceeded
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def testRateLimitExceeded(self):
httpretty.register_uri(
httpretty.GET,
self.geocoder.url,
body='{"status":{"code":402,"message":"OK"},"thanks":"For using an OpenCage Data API","total_results":0,"licenses":[{"url":"http://creativecommons.org/licenses/by-sa/3.0/","name":"CC-BY-SA"},{"url":"http://opendatacommons.org/licenses/odbl/summary/","name":"ODbL"}],"rate":{"reset":1402185600,"limit":"2500","remaining":0},"results":[],"timestamp":{"created_http":"Sat, 07 Jun 2014 10:38:45 GMT","created_unix":1402137525}}',
status=402,
adding_headers={'X-RateLimit-Limit': '2500', 'X-RateLimit-Remaining': '0', 'X-RateLimit-Reset': '1402185600'},
)
self.assertRaises(RateLimitExceededError, self.geocoder.geocode, "whatever")
# check the exception
try:
self.geocoder.geocode("whatever")
except RateLimitExceededError as ex:
self.assertEqual(str(ex), 'Your rate limit has expired. It will reset to 2500 on 2014-06-08T00:00:00')
self.assertEqual(ex.reset_to, 2500)
示例3: setup
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def setup(self):
httpretty.enable()
self.key = RSAKey(kid='testkey').load(os.path.join(FIXTURE_ROOT, 'testkey.pem'))
def jwks(_request, _uri, headers): # noqa: E306
ks = KEYS()
ks.add(self.key.serialize())
return 200, headers, ks.dump_jwks()
httpretty.register_uri(
httpretty.GET, oidc_rp_settings.PROVIDER_JWKS_ENDPOINT, status=200, body=jwks)
httpretty.register_uri(
httpretty.POST, oidc_rp_settings.PROVIDER_TOKEN_ENDPOINT,
body=json.dumps({
'id_token': self.generate_jws(), 'access_token': 'accesstoken',
'refresh_token': 'refreshtoken', }),
content_type='text/json')
httpretty.register_uri(
httpretty.GET, oidc_rp_settings.PROVIDER_USERINFO_ENDPOINT,
body=json.dumps({'sub': '1234', 'email': 'test@example.com', }),
content_type='text/json')
yield
httpretty.disable()
示例4: test_descriptor_dereferencing_uri_remote
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def test_descriptor_dereferencing_uri_remote():
# Mocks
httpretty.register_uri(httpretty.GET,
'http://example.com/schema', body='{"fields": [{"name": "name"}]}')
httpretty.register_uri(httpretty.GET,
'https://example.com/dialect', body='{"delimiter": ","}')
# Tests
descriptor = {
'resources': [
{'name': 'name1', 'data': 'data', 'schema': 'http://example.com/schema'},
{'name': 'name2', 'data': 'data', 'dialect': 'https://example.com/dialect'},
],
}
package = Package(descriptor)
assert package.descriptor['resources'] == list(map(helpers.expand_resource_descriptor, [
{'name': 'name1', 'data': 'data', 'schema': {'fields': [{'name': 'name'}]}},
{'name': 'name2', 'data': 'data', 'dialect': {'delimiter': ','}},
]))
示例5: configure_httpretty
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def configure_httpretty(sitedir):
httpretty.enable()
dir = Path(f"tests/test_sites/data/test_{sitedir}/")
data_file = dir / 'data.json'
data = None
with open(data_file) as f:
data = json.load(f)
for obj in data:
method = httpretty.POST
if obj['method'] == 'GET':
method = httpretty.GET
with open(dir / obj['file']) as f:
httpretty.register_uri(
method,
obj['url'],
f.read(),
)
示例6: test_get_attribute_with_dict
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def test_get_attribute_with_dict(self):
driver = android_w3c_driver()
rect_dict = {
'y': 200,
'x': 100,
'width': 300,
'height': 56
}
httpretty.register_uri(
httpretty.GET,
appium_command('/session/1234567890/element/element_id/attribute/rect'),
body=json.dumps({"value": rect_dict})
)
element = MobileWebElement(driver, 'element_id', w3c=True)
ef = element.get_attribute('rect')
d = httpretty.last_request()
assert isinstance(ef, dict)
assert ef == rect_dict
示例7: test_get_system_bars
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def test_get_system_bars(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.GET,
appium_command('/session/1234567890/appium/device/system_bars'),
body=''' {"value":
{"statusBar":
{"visible": true, "x": 0, "y": 0, "width": 1080, "height": 1920},
"navigationBar":
{"visible": true, "x": 0, "y": 0, "width": 1080, "height": 126}}}'''
)
d = driver.get_system_bars()
assert d['statusBar']['visible'] is True
assert d['statusBar']['x'] == 0
assert d['statusBar']['y'] == 0
assert d['statusBar']['width'] == 1080
assert d['statusBar']['height'] == 1920
assert d['navigationBar']['visible'] is True
assert d['navigationBar']['x'] == 0
assert d['navigationBar']['y'] == 0
assert d['navigationBar']['width'] == 1080
assert d['navigationBar']['height'] == 126
示例8: test_get_events_catches_missing_events
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def test_get_events_catches_missing_events(self):
driver = ios_w3c_driver()
httpretty.register_uri(
httpretty.GET,
appium_command('/session/1234567890'),
body=json.dumps({'value': {}})
)
events = driver.events
assert events == {}
httpretty.register_uri(
httpretty.GET,
appium_command('/session/1234567890'),
body=json.dumps({})
)
events = driver.events
assert events == {}
示例9: test_get_all_ok
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def test_get_all_ok(self):
httpretty.register_uri(httpretty.GET, "http://localhost:8000/service1/",
body='{"objects": [{"id": "3"}], "total": 3}',
content_type="application/json",
status=200)
httpretty.register_uri(httpretty.GET, "http://localhost:8000/service1/",
body='{"objects": [{"id": "1"}, {"id": "2"}], "total": 3}',
content_type="application/json",
status=200)
response = ApiClient().get_all('/service1/', limit=2)
response_list = list(response)
assert len(response) == 3
assert len(response_list) == 3
assert response_list[0]['id'] == '1'
assert response_list[1]['id'] == '2'
assert response_list[2]['id'] == '3'
示例10: test_get_all_not_ok_second_page
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def test_get_all_not_ok_second_page(self):
httpretty.register_uri(httpretty.GET, "http://localhost:8000/service1/",
body='{"error": "deu merda"}',
content_type="application/json",
status=500)
httpretty.register_uri(httpretty.GET, "http://localhost:8000/service1/",
body='{"objects": [{"id": "1"}, {"id": "2"}], "total": 3}',
content_type="application/json",
status=200)
response = ApiClient().get_all('/service1/', limit=2)
assert len(response) == 3
with pytest.raises(HTTPException):
response_list = list(response)
示例11: test_last_response_not_executed
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def test_last_response_not_executed(self):
json_body = json.dumps({"result": [{"number": self.mock_incident["number"]}]})
httpretty.register_uri(
httpretty.GET,
"http://%s/%s" % (self.mock_connection["host"], self.mock_incident["path"]),
body=json_body,
status=200,
content_type="application/json",
)
try:
str(self.client.query(table="incident", query={}).last_response)
self.assertFalse(
"Getting last_response should fail when no `Request` has been executed"
)
except NoRequestExecuted:
pass
示例12: test_last_response
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def test_last_response(self):
json_body = json.dumps({"result": [{"number": self.mock_incident["number"]}]})
httpretty.register_uri(
httpretty.GET,
"http://%s/%s" % (self.mock_connection["host"], self.mock_incident["path"]),
body=json_body,
status=200,
content_type="application/json",
)
r = self.client.query(table="incident", query={})
r.get_one()
# Make sure we get the expected status code back
self.assertEqual(r.status_code, 200)
# Make sure last_response is not None
self.assertNotEqual(r.last_response, None)
示例13: test_get_incident_by_dict_query
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def test_get_incident_by_dict_query(self):
"""
Make sure fetching by dict type query works
"""
json_body = json.dumps({"result": [{"number": self.mock_incident["number"]}]})
httpretty.register_uri(
httpretty.GET,
"http://%s/%s" % (self.mock_connection["host"], self.mock_incident["path"]),
body=json_body,
status=200,
content_type="application/json",
)
r = self.client.query(
table="incident", query={"number": self.mock_incident["number"]}
)
# Make sure we got an incident back with the expected number
self.assertEqual(r.get_one()["number"], self.mock_incident["number"])
示例14: test_get_content_without_result
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def test_get_content_without_result(self):
"""
Make sure content without `result` fails
"""
json_body = json.dumps({})
httpretty.register_uri(
httpretty.GET,
"http://%s/%s" % (self.mock_connection["host"], self.mock_incident["path"]),
body=json_body,
status=200,
content_type="application/json",
)
r = self.client.query(table="incident", query={})
self.assertRaises(MissingResult, r.get_one)
示例15: test_get_incident_by_string_query
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import GET [as 别名]
def test_get_incident_by_string_query(self):
"""
Make sure fetching by string type query works
"""
json_body = json.dumps({"result": [{"number": self.mock_incident["number"]}]})
httpretty.register_uri(
httpretty.GET,
"http://%s/%s" % (self.mock_connection["host"], self.mock_incident["path"]),
body=json_body,
status=200,
content_type="application/json",
)
r = self.client.query(
table="incident", query="nameINincident,task^elementLIKEstate"
)
# Make sure we got an incident back with the expected number
self.assertEqual(r.get_one()["number"], self.mock_incident["number"])