Mercurial > wikked
comparison benchmarks/test_benchmark.py @ 325:8b45c5ba5d47
Add benchmark tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 15 Oct 2014 08:11:14 -0700 |
parents | |
children | f7a741bc5770 |
comparison
equal
deleted
inserted
replaced
324:5f809e691124 | 325:8b45c5ba5d47 |
---|---|
1 import re | |
2 import urllib | |
3 import random | |
4 import unittest | |
5 from funkload.FunkLoadTestCase import FunkLoadTestCase | |
6 | |
7 | |
8 class Benchmark(FunkLoadTestCase): | |
9 """This test uses a configuration file Benchmark.conf.""" | |
10 def setUp(self): | |
11 self.server_url = self.conf_get('main', 'url') | |
12 | |
13 def test_simple(self): | |
14 server_url = self.server_url | |
15 if not re.match('https?://', server_url): | |
16 raise Exception("The `server_url` setting doesn't have a scheme.") | |
17 | |
18 username = self.conf_get('test_benchmark', 'username', None) | |
19 password = self.conf_get('test_benchmark', 'password', None) | |
20 if username and password: | |
21 self.post(self.server_url + "/api/user/login", | |
22 params=[['username', username], | |
23 ['password', password]], | |
24 description="Login as %s" % username) | |
25 | |
26 nb_times = self.conf_getInt('test_benchmark', 'nb_times') | |
27 names = self.conf_get('test_benchmark', 'page_names').split(';') | |
28 for i in range(nb_times): | |
29 r = random.randint(0, len(names) - 1) | |
30 url = server_url + '/api/read/' + urllib.quote(names[r]) | |
31 self.get(url, description='Getting %s' % names[r]) | |
32 | |
33 | |
34 if __name__ in ('main', '__main__'): | |
35 unittest.main() | |
36 |