Kiln » Kiln Extensions
Clone URL:  
kilntest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import json import sys import os import time import getpass import urllib2 from urllib import urlencode from custom import * # Ensure that the home directory is set appropriately so that the kilnauth # cookies will be found. This is important because Mercurial 1.9 and later # changes the home directory in the test script. os.environ['HOME'] = os.path.expanduser('~' + getpass.getuser()); # Paths for the individual extensions KBFILESPATH = KILNEXTPATH + '/bfiles/kbfiles' KILNAUTHPATH = KILNEXTPATH + '/kilnauth.py' GESTALTPATH = KILNEXTPATH + '/gestalt.py' KILNPATHPATH = KILNEXTPATH + '/kilnpath.py' BIGPUSHPATH = KILNEXTPATH + '/big-push.py' KILNPATH = KILNEXTPATH + '/kiln.py' CASEGUARDPATH = KILNEXTPATH + '/caseguard.py' def api(url): return KILNURL + '/api/1.0/' + url def slurp(url, params={}, post=False, raw=False): params = urlencode(params, doseq=True) handle = urllib2.urlopen(url, params) if post else urllib2.urlopen(url + '?' + params) content = handle.read() obj = content if raw else json.loads(content) handle.close() return obj def gettoken(): return slurp(api('Auth/Login'), dict(sUser=USER, sPassword=PASSWORD)) def createtest(hgt, token): projects = slurp(api('Project'), dict(token=token)) found = False for project in projects: if project['sName'] == 'Test': ixProject = project['ixProject'] for group in project['repoGroups']: if group['sName'] == 'Test': ixRepoGroup = group['ixRepoGroup'] found = True if not found: return None repo = slurp(api('Repo/Create'), dict(sName='Test', sDescription='test', ixRepoGroup=ixRepoGroup, sDefaultPermission='write', token=token)) ixRepo = repo['ixRepo'] hgt.asserttrue(isinstance(ixRepo, int), 'Create failed %s' % (str(ixRepo))) time.sleep(1) while slurp(api('Repo/%d' % ixRepo), dict(token=token))['sStatus'] != 'good': time.sleep(0.1) return (KILNURL + '/Repo/Test/Test/Test', ixRepo) def createtestbranch(hgt, token, ixParent): projects = slurp(api('Project'), dict(token=token)) found = False for project in projects: if project['sName'] == 'Test': ixProject = project['ixProject'] for group in project['repoGroups']: if group['sName'] == 'Test': ixRepoGroup = group['ixRepoGroup'] found = True if not found: return None time.sleep(1) while slurp(api('Repo/%d' % ixParent), dict(token=token))['sStatus'] != 'good': time.sleep(0.1) repo = slurp(api('Repo/Create'), dict(sName='TestBranch', sDescription='test branch', ixRepoGroup=ixRepoGroup, ixParent=ixParent, fCentral=False, sDefaultPermission='write', token=token)) ixRepo = repo['ixRepo'] hgt.asserttrue(isinstance(ixRepo, int), 'Create failed %s' % (str(ixRepo))) time.sleep(1) while slurp(api('Repo/%d' % ixRepo), dict(token=token))['sStatus'] != 'good': time.sleep(0.1) return (KILNURL + '/Repo/Test/Test/TestBranch', ixRepo) def deletetest(hgt, token): projects = slurp(api('Project'), dict(token=token)) found = False foundbranch = False for project in projects: if project['sName'] == 'Test': ixProject = project['ixProject'] for group in project['repoGroups']: if group['sName'] == 'Test': ixRepoGroup = group['ixRepoGroup'] for repo in group['repos']: if repo['sName'] == 'Test': ixRepo = repo['ixRepo'] found = True if repo['sName'] == 'TestBranch': ixBranch = repo['ixRepo'] foundbranch = True if foundbranch: slurp(api('Repo/%d/Delete' % ixBranch), dict(token=token), post=True) try: while True: slurp(api('Repo/%d' % ixBranch), dict(token=token)) time.sleep(0.1) except urllib2.HTTPError: pass if found: slurp(api('Repo/%d/Delete' % ixRepo), dict(token=token), post=True) try: while True: slurp(api('Repo/%d' % ixRepo), dict(token=token)) time.sleep(0.1) except urllib2.HTTPError: pass