本文整理汇总了Python中pants.goal.run_tracker.RunTracker.post_stats方法的典型用法代码示例。如果您正苦于以下问题:Python RunTracker.post_stats方法的具体用法?Python RunTracker.post_stats怎么用?Python RunTracker.post_stats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pants.goal.run_tracker.RunTracker
的用法示例。
在下文中一共展示了RunTracker.post_stats方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_upload_stats
# 需要导入模块: from pants.goal.run_tracker import RunTracker [as 别名]
# 或者: from pants.goal.run_tracker.RunTracker import post_stats [as 别名]
def test_upload_stats(self):
stats = {'stats': {'foo': 'bar', 'baz': 42}}
class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_POST(handler):
try:
self.assertEquals('/upload', handler.path)
self.assertEquals('application/x-www-form-urlencoded', handler.headers['Content-type'])
length = int(handler.headers['Content-Length'])
post_data = urlparse.parse_qs(handler.rfile.read(length).decode('utf-8'))
decoded_post_data = {k: json.loads(v[0]) for k, v in post_data.items()}
self.assertEquals(stats, decoded_post_data)
handler.send_response(200)
except Exception:
handler.send_response(400) # Ensure the main thread knows the test failed.
raise
server_address = ('', 0)
server = BaseHTTPServer.HTTPServer(server_address, Handler)
host, port = server.server_address
server_thread = threading.Thread(target=server.serve_forever)
server_thread.daemon = True
server_thread.start()
self.assertTrue(RunTracker.post_stats('http://{}:{}/upload'.format(host, port), stats))
server.shutdown()
server.server_close()
示例2: test_upload_stats
# 需要导入模块: from pants.goal.run_tracker import RunTracker [as 别名]
# 或者: from pants.goal.run_tracker.RunTracker import post_stats [as 别名]
def test_upload_stats(self):
stats = {'stats': {'foo': 'bar', 'baz': 42}}
class Handler(http.server.BaseHTTPRequestHandler):
def do_POST(handler):
try:
if handler.path.startswith('/redirect'):
code = int(handler.path[-3:])
handler.send_response(code)
handler.send_header('location', mk_url('/upload'))
handler.end_headers()
else:
self.assertEqual('/upload', handler.path)
self.assertEqual('application/x-www-form-urlencoded', handler.headers['Content-type'])
length = int(handler.headers['Content-Length'])
post_data = parse_qs(handler.rfile.read(length).decode('utf-8'))
decoded_post_data = {k: json.loads(v[0]) for k, v in post_data.items()}
self.assertEqual(stats, decoded_post_data)
handler.send_response(200)
handler.end_headers()
except Exception:
handler.send_response(400) # Ensure the main thread knows the test failed.
raise
server_address = ('', 0)
server = http.server.HTTPServer(server_address, Handler)
host, port = server.server_address
def mk_url(path):
return 'http://{}:{}{}'.format(host, port, path)
server_thread = threading.Thread(target=server.serve_forever)
server_thread.daemon = True
server_thread.start()
self.context(for_subsystems=[Cookies])
self.assertTrue(RunTracker.post_stats(mk_url('/upload'), stats))
self.assertTrue(RunTracker.post_stats(mk_url('/redirect307'), stats))
self.assertFalse(RunTracker.post_stats(mk_url('/redirect302'), stats))
server.shutdown()
server.server_close()