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 create(excepted_status, excepted_response):
14 def _create(create_request):
15 @functools.wraps(create_request)
17 request = create_request(self)
18 status, body = self.create(request)
19 if excepted_status == httplib.OK:
20 getattr(self, excepted_response)(body)
22 self.assertIn(excepted_response, body)
27 def get(excepted_status, excepted_response):
28 def _get(get_request):
29 @functools.wraps(get_request)
31 request = get_request(self)
32 status, body = self.get(request)
33 if excepted_status == httplib.OK:
34 getattr(self, excepted_response)(body)
36 self.assertIn(excepted_response, body)
41 def update(excepted_status, excepted_response):
42 def _update(update_request):
43 @functools.wraps(update_request)
45 request, resource = update_request(self)
46 status, body = self.update(request, resource)
47 if excepted_status == httplib.OK:
48 getattr(self, excepted_response)(request, body)
50 self.assertIn(excepted_response, body)
55 def delete(excepted_status, excepted_response):
56 def _delete(delete_request):
57 @functools.wraps(delete_request)
59 request = delete_request(self)
60 if isinstance(request, tuple):
61 status, body = self.delete(request[0], *(request[1]))
63 status, body = self.delete(request)
64 if excepted_status == httplib.OK:
65 getattr(self, excepted_response)(body)
67 self.assertIn(excepted_response, body)
72 def query(excepted_status, excepted_response, number=0):
73 def _query(get_request):
74 @functools.wraps(get_request)
76 request = get_request(self)
77 status, body = self.query(request)
78 if excepted_status == httplib.OK:
79 getattr(self, excepted_response)(body, number)
81 self.assertIn(excepted_response, body)