本文整理汇总了Python中responses.start方法的典型用法代码示例。如果您正苦于以下问题:Python responses.start方法的具体用法?Python responses.start怎么用?Python responses.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类responses
的用法示例。
在下文中一共展示了responses.start方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mock_request
# 需要导入模块: import responses [as 别名]
# 或者: from responses import start [as 别名]
def mock_request():
with open(path.join(path.dirname(path.realpath(__file__)),
'fake_response.json')) as f:
fake_response = json.load(f)
responses.add(
responses.GET,
url=("https://www.bing.com/HPImageArchive.aspx?format"
"=js&idx=0&n=1&nc=1409879295618&pid=hp"),
json=fake_response,
status=200,
match_querystring=True
)
responses.add(
responses.GET,
url=('https://www.bing.com/th?id=OHR.OldManWhiskers_ZH-CN9321160932_'
'1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp'),
status=200,
body='Hello, world'
)
responses.start()
yield responses
responses.stop()
示例2: setUp
# 需要导入模块: import responses [as 别名]
# 或者: from responses import start [as 别名]
def setUp(self):
await super(HollowmanAppTest, self).setUp()
fixture = get_fixture("single_full_app.json")
self.user = UserDB(
tx_email="user@host.com.br",
tx_name="John Doe",
tx_authkey="69ed620926be4067a36402c3f7e9ddf0",
)
self.account_dev = AccountDB(
id=4, name="Dev Team", namespace="dev", owner="company"
)
responses.add(
method="GET",
url=conf.MARATHON_ADDRESSES[0] + "/v2/apps",
body=json.dumps({"apps": [fixture]}),
status=200,
headers={"Content-Encoding": "chunked"},
)
responses.start()
示例3: pytest_runtest_setup
# 需要导入模块: import responses [as 别名]
# 或者: from responses import start [as 别名]
def pytest_runtest_setup(item):
if not get_withoutresponses_marker(item):
responses_.start()
示例4: mock_api
# 需要导入模块: import responses [as 别名]
# 或者: from responses import start [as 别名]
def mock_api():
with open(path.join(ROOT, 'signin.html'), encoding='utf-8') as f:
mock_signin_body = f.read()
responses.add(responses.POST, 'https://www.v2ex.com/signin',
body=mock_signin_body)
responses.add(responses.GET, 'https://www.v2ex.com/signin',
body=mock_signin_body)
with open(path.join(ROOT, 'once.html'), encoding='utf-8') as f:
mock_once_body = f.read()
responses.add(responses.GET,
'https://www.v2ex.com/mission/daily/redeem?once=51947',
body=mock_once_body)
with open(path.join(ROOT, 'balance.html'), encoding='utf-8') as f:
mock_balance_body = f.read()
responses.add(responses.GET, 'https://www.v2ex.com/balance',
body=mock_balance_body)
with open(path.join(ROOT, 'mission.html'), encoding='utf-8') as f:
mock_mission_body = f.read()
responses.add(responses.GET, 'https://www.v2ex.com/mission/daily',
body=mock_mission_body)
responses.start()
yield responses
responses.stop()
示例5: response_fixture_factory
# 需要导入模块: import responses [as 别名]
# 或者: from responses import start [as 别名]
def response_fixture_factory(url, data=None, status=200):
@pytest.yield_fixture
def fixture():
responses.add(
responses.POST,
url,
status=status,
body=json.dumps(data or {}),
content_type='application/json',
)
responses.start()
yield responses
responses.stop()
responses.reset()
return fixture
示例6: setUp
# 需要导入模块: import responses [as 别名]
# 或者: from responses import start [as 别名]
def setUp(self, single_full_app_fixture):
self.single_full_app_fixture = single_full_app_fixture
self.user = User(tx_name="User", tx_email="user@host.com")
self.user.current_account = Account(
name="Some Account", namespace="dev", owner="company"
)
responses.add(
method="GET",
url=conf.MARATHON_ADDRESSES[0] + "/v2/apps//dev/foo",
body=json.dumps({"app": self.single_full_app_fixture}),
status=200,
)
responses.start()
示例7: setUp
# 需要导入模块: import responses [as 别名]
# 或者: from responses import start [as 别名]
def setUp(self):
self.user = User(tx_name="User One", tx_email="user@host.com")
self.user.current_account = Account(
name="Dev", namespace="dev", owner="company"
)
responses.start()
示例8: _setup
# 需要导入模块: import responses [as 别名]
# 或者: from responses import start [as 别名]
def _setup():
responses.add(
responses.GET,
"http://api.com/users/1/",
json={"id": 1, "name": "John", "surname": "Doe"},
)
responses.start()
示例9: setup_method
# 需要导入模块: import responses [as 别名]
# 或者: from responses import start [as 别名]
def setup_method(self, method):
responses.start()
request_data = self.requests_mock.get(method.__name__, {})
responses.add(
method=request_data.get('method', responses.GET),
url=request_data.get('uri', self.default_uri),
body=request_data.get('body', '{}'),
status=request_data.get('status', codes.ok),
content_type=request_data.get('content_type', 'application/json')
)
示例10: setUp
# 需要导入模块: import responses [as 别名]
# 或者: from responses import start [as 别名]
def setUp(self):
await super(AuthenticationTest, self).setUp()
fixture = get_fixture("single_full_app.json")
self.user = User(**USER_WITH_MULTIPLE_ACCOUNTS_DICT)
self.account_dev = Account(**ACCOUNT_DEV_DICT)
self.account_infra = Account(**ACCOUNT_INFRA_DICT)
self.account_sup = AccountDB(
name="Support Team", namespace="sup", owner="company"
)
# self.user.accounts = [self.account_dev, self.account_infra]
# self.session.add(self.user)
# self.session.add(self.account_dev)
# self.session.add(self.account_infra)
# self.session.add(self.account_sup)
self.user_with_no_accounts = User(**USER_WITH_NO_ACCOUNTS_DICT)
self.account_with_no_user = Account(**ACCOUNT_WITH_NO_USERS_DICT)
self.response_http_200 = MagicMock(status_code=200)
responses.add(
method="GET",
url=conf.MARATHON_ADDRESSES[0] + "/v2/apps",
body=json.dumps({"apps": [fixture]}),
status=200,
)
responses.add(
method="GET",
url=conf.MARATHON_ADDRESSES[0] + "/v2/groups//dev/",
body=json.dumps({"apps": [fixture]}),
status=200,
)
responses.add(
method="GET",
url=conf.MARATHON_ADDRESSES[0] + "/v2/groups//infra/",
body=json.dumps({"apps": [fixture]}),
status=200,
)
responses.add(
method="GET",
url=conf.MARATHON_ADDRESSES[0] + "/v2/apps//foo",
body=json.dumps({"app": fixture}),
status=200,
)
responses.start()
示例11: setUp
# 需要导入模块: import responses [as 别名]
# 或者: from responses import start [as 别名]
def setUp(self):
self.mock = mock_s3()
self.mock.start()
#
# Populate the data in mock S3
#
conn = boto.connect_s3()
# s3+dir lists_served bucket first
b = conn.create_bucket(self.lists_served_bucket_name)
for fname in ['mozpub-track-digest256.ini',
'testpub-bananas-digest256.ini']:
k = Key(b)
k.name = fname
f = open(os.path.join(
os.path.dirname(__file__), 'lists_served_s3', fname
))
k.set_contents_from_file(f)
# s3+file contents
b = conn.create_bucket(self.bucket_name)
k = Key(b)
k.name = self.key_name
with open(test_file(self.key_name), 'rb') as f:
k.set_contents_from_file(f)
# s3+dir keys and contents
b = conn.create_bucket(self.dir_bucket_name)
for fname in ('index.json', '1', '2', '3', '4', '5', '6'):
k = Key(b)
k.name = posixpath.join(self.dir_list_name, fname)
with open(test_file(posixpath.join('delta_dir_source', fname)),
'rb') as f:
k.set_contents_from_file(f)
responses.start()
GITHUB_API_URL = 'https://api.github.com'
SHAVAR_PROD_LISTS_BRANCHES_PATH = (
'/repos/mozilla-services/shavar-prod-lists/branches'
)
resp_body = """
[{
"name": "69.0",
"commit": {
"sha": "35665559e9e4a85c12bb8211b5f9217fbb96062d",
"url": "https://api.github.com/repos/mozilla-services/\
shavar-prod-lists/commits/\
35665559e9e4a85c12bb8211b5f9217fbb96062d"
}
}]
"""
responses.add(
responses.GET, GITHUB_API_URL + SHAVAR_PROD_LISTS_BRANCHES_PATH,
body=resp_body
)
# initialize the internal list data structure via the normal method
super(S3SourceListsTest, self).setUp()