Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 1 | import random |
Rohit Karajgi | e1b050d | 2011-12-02 16:13:18 -0800 | [diff] [blame] | 2 | import urllib |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 3 | |
| 4 | |
Rohit Karajgi | cb5d954 | 2011-12-02 14:17:06 -0800 | [diff] [blame] | 5 | def rand_name(name='test'): |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 6 | return name + str(random.randint(1, 99999999999)) |
Rohit Karajgi | e1b050d | 2011-12-02 16:13:18 -0800 | [diff] [blame] | 7 | |
| 8 | |
| 9 | def build_url(host, port, apiVer=None, path=None, params=None, https=False): |
| 10 | """Build the request URL from given host, port, path and parameters""" |
| 11 | |
| 12 | if https: |
| 13 | url = "https://" + host |
| 14 | else: |
| 15 | url = "http://" + host |
| 16 | |
| 17 | if port is not None: |
| 18 | url += ":" + port |
| 19 | url += "/" |
| 20 | |
| 21 | if apiVer is not None: |
| 22 | url += apiVer + "/" |
| 23 | |
| 24 | if path is not None: |
| 25 | url += path |
| 26 | |
| 27 | if params is not None: |
| 28 | url += "?" |
| 29 | url += urllib.urlencode(params) |
| 30 | |
| 31 | return url |