1 ##############################################################################
2 # Copyright (c) 2017 ZTE Corp
3 # feng.xiaowei@zte.com.cn
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 def upload(excepted_status, excepted_response):
14 def _upload(create_request):
15 @functools.wraps(create_request)
17 request = create_request(self)
18 status, body = self.upload(request)
19 if excepted_status == httplib.OK:
20 getattr(self, excepted_response)(body)
22 self.assertIn(excepted_response, body)
27 def create(excepted_status, excepted_response):
28 def _create(create_request):
29 @functools.wraps(create_request)
31 request = create_request(self)
32 status, body = self.create(request)
33 if excepted_status == httplib.OK:
34 getattr(self, excepted_response)(body)
36 self.assertIn(excepted_response, body)
41 def get(excepted_status, excepted_response):
42 def _get(get_request):
43 @functools.wraps(get_request)
45 request = get_request(self)
46 status, body = self.get(request)
47 if excepted_status == httplib.OK:
48 getattr(self, excepted_response)(body)
50 self.assertIn(excepted_response, body)
55 def update(excepted_status, excepted_response):
56 def _update(update_request):
57 @functools.wraps(update_request)
59 request, resource = update_request(self)
60 status, body = self.update(request, resource)
61 if excepted_status == httplib.OK:
62 getattr(self, excepted_response)(request, body)
64 self.assertIn(excepted_response, body)
69 def delete(excepted_status, excepted_response):
70 def _delete(delete_request):
71 @functools.wraps(delete_request)
73 request = delete_request(self)
74 if isinstance(request, tuple):
75 status, body = self.delete(request[0], *(request[1]))
77 status, body = self.delete(request)
78 if excepted_status == httplib.OK:
79 getattr(self, excepted_response)(body)
81 self.assertIn(excepted_response, body)
86 def query(excepted_status, excepted_response, number=0):
87 def _query(get_request):
88 @functools.wraps(get_request)
90 request = get_request(self)
91 status, body = self.query(request)
92 if excepted_status == httplib.OK:
93 getattr(self, excepted_response)(body, number)
95 self.assertIn(excepted_response, body)