def test_project_add(connection, project_name, project_payload,
project_type, upload_token):
"""Verifies project creation."""
httpretty.register_uri(
httpretty.POST, '{}/project/add'.format(
matchlight.MATCHLIGHT_API_URL_V2),
body=json.dumps({'data': project_payload}),
content_type='application/json', status=200)
project = connection.projects.add(project_name, project_type)
assert project.upload_token == upload_token
python类POST的实例源码
def test_create(self):
"""Method defined to test plan creation."""
httpretty.register_uri(
httpretty.POST,
"https://api.paystack.co/plan",
content_type='text/json',
body='{"status": true, "contributors": true}',
status=201,
)
response = Plan.create(
name="John Doe", description="Payment plan for awesome people contributions",
amount=50000, interval="daily", send_invoices=True, )
self.assertTrue(response['status'])
def test_post_method_called(self):
httpretty.register_uri(
httpretty.POST,
"https://api.paystack.co/transaction/charge_token",
content_type='text/json',
body='{"status": true, "contributors": null}',
status=302,
)
req = PayStackRequests()
response = req.post('transaction/charge_token',
data={'track': 'requests'})
self.assertTrue(response['status'])
def test_charge(self):
httpretty.register_uri(
httpretty.POST,
"https://api.paystack.co/transaction/charge_authorization",
content_type='text/json',
body='{"status": true, "contributors": true}',
status=201,
)
response = Transaction.charge(
reference='getupall', authorization_code='authorization_code',
email='email', amount='amount')
self.assertTrue(response['status'])
def step_impl(context):
d = context.bad_login
assert d['source']['username'] != 'ValidUser'
httpretty.enable()
httpretty.register_uri(
httpretty.POST,
context.good_build_url,
body='{"errors":[{"context":null,"message":"Authentication failed. Please check your credentials and try again.","exceptionName":"com.atlassian.bitbucket.auth.IncorrectPasswordAuthenticationException"}]}',
status=401
)
from scripts.bitbucket import post_result, err
result = post_result(context.good_build_url, d['source']['username'], d['source']['password'], False, good_status_dict(), True)
assert result.status_code == 401
httpretty.disable()
httpretty.reset()
def step_impl(context):
d = context.good_login
assert context.good_login['source']['username'] == 'ValidUser'
httpretty.enable()
httpretty.register_uri(
httpretty.POST,
context.bad_build_url,
body='{"errors":[{"context":null,"message":"You are not permitted to access this resource","exceptionName":"com.atlassian.bitbucket.AuthorisationException"}]}',
status=403
)
from scripts.bitbucket import post_result, err
result = post_result(context.bad_build_url, d['source']['username'], d['source']['password'], False, good_status_dict(), True)
assert result.status_code == 403
httpretty.disable()
httpretty.reset()
def step_impl(context):
d = context.good_login
assert context.good_login['source']['username'] == 'ValidUser'
assert 'somethingicantaccess' not in context.good_build_url
httpretty.enable()
httpretty.register_uri(
httpretty.POST,
context.good_build_url,
status=204
)
from scripts.bitbucket import post_result, err
result = post_result(context.good_build_url, d['source']['username'], d['source']['password'], False, good_status_dict(), True)
assert result.status_code == 204
context.goodresult = result
def given_that_there_is_no_default_acl(self):
self.start_mocking_http()
self.fake_response('/streams/$settings', status=404)
self.expect_call('/streams/$settings', httpretty.POST)
def given_that_there_is_no_default_acl(self):
self.start_mocking_http()
self.fake_response('/streams/$settings', status=404)
self.expect_call('/streams/$settings', httpretty.POST)
def given_a_default_acl(self):
self.start_mocking_http()
self.fake_response('/streams/$settings', file='settings-stream.js')
self.fake_response('/streams/$settings/6', file='settings.json')
self.expect_call('/streams/$settings', httpretty.POST)
def given_a_default_acl(self):
self.start_mocking_http()
self.fake_response('/streams/$settings', file='settings-stream.js')
self.fake_response('/streams/$settings/6', file='settings.json')
self.expect_call('/streams/$settings', httpretty.POST)
def given_a_default_acl(self):
self.start_mocking_http()
self.fake_response('/streams/$settings', file='settings-stream.js')
self.fake_response('/streams/$settings/6', file='settings.json')
self.expect_call('/streams/$settings', httpretty.POST)
def given_a_client(self):
self.start_mocking_http()
self.expect_call('/streams/my-stream/metadata', httpretty.POST)
def given_a_client(self):
self.start_mocking_http()
self.expect_call('/streams/my-stream/metadata', httpretty.POST)
def given_an_existing_stream_with_no_metadata(self):
self.start_mocking_http()
self.fake_response('/streams/my-stream/metadata', status=200, body='{}')
self.expect_call('/streams/my-stream/metadata', httpretty.POST)
def given_a_stream_with_an_acl(self):
self.start_mocking_http()
self.expect_call('/streams/my-stream/metadata', httpretty.POST)
self.fake_response('/streams/my-stream/metadata', status=200,
body = """
{
"$acl" : {
"$w" : "greg",
"$r" : ["greg", "john"],
"$d" : "$admins",
"$mw" : "$admins",
"$mr" : "$admins"
}
}""")
def given_the_absence_of_a_stream(self):
self.start_mocking_http()
self.expect_call('/streams/my-stream/metadata', httpretty.POST)
self.fake_response('/streams/missing-stream/metadata', status=404)
def given_a_stream_with_an_acl(self):
self.start_mocking_http()
self.expect_call('/streams/my-stream/metadata', httpretty.POST)
self.fake_response('/streams/my-stream/metadata', status=200,
body = """
{
"$acl" : {
"$w" : "greg",
"$r" : ["greg", "john"],
"$d" : "$admins",
"$mw" : "$admins",
"$mr" : "$admins"
}
}""")