Created
August 31, 2012 13:14
-
-
Save dlitvakb/3552520 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from netdnarws import NetDNA | |
| from funkload.FunkLoadTestCase import FunkLoadTestCase | |
| from unittest import main | |
| from test_data import test_data | |
| class BenchmarkTest(FunkLoadTestCase): | |
| def setUp(self): | |
| self.api = NetDNA("cdnintegration", | |
| "lalala", | |
| "lalalala", | |
| self.conf_get('main', 'url'), | |
| False) | |
| def assert_request(self, request_data): | |
| self.logd("Test: %s" % (request_data['uri'],)) | |
| response = self.api._response_as_json( | |
| request_data.get('method', 'get'), | |
| request_data['uri'], | |
| data=request_data.get('data', {}), | |
| debug_request=True | |
| ) | |
| self.assertEquals( | |
| request_data.get('expected_code', 200), | |
| response.json['code'], | |
| "%s: %s" % (request_data['uri'], response.json) | |
| ) | |
| return response | |
| def assert_request_with_bench_status(self, request_data): | |
| response = self.assert_request(request_data) | |
| self.clearHeaders() | |
| for k, v in response.request.headers.iteritems(): | |
| self.addHeader(k, v) | |
| getattr(self, request_data.get('method', 'get'))( | |
| response.url, | |
| description=request_data['uri'], | |
| ok_codes=[request_data.get('expected_code', 200)], | |
| params=request_data.get('data', {}) | |
| ) | |
| def test_main(self): | |
| for dataset in test_data: | |
| self.assert_request(dataset) | |
| def test_main_with_bench_status(self): | |
| for dataset in test_data: | |
| self.assert_request_with_bench_status(dataset) | |
| if __name__ == '__main__': | |
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test_data = [ | |
| # GET | |
| {'uri': '/account.json'}, | |
| {'uri': '/account.json/address'}, | |
| {'uri': '/users.json'}, | |
| {'uri': '/users.json/2666'}, | |
| # ... | |
| # PUT | |
| {'uri': '/zones/vod.json/49935', 'data': {'label': 'x'}, 'method': 'put'}, | |
| {'uri': '/zones/vod.json/49935', 'data': {'label': 'a vod zone'}, 'method': 'put'}, | |
| # ... etc ... | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment