1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 __all__ = (
24 "ProjectService",
25 )
26
27 import sys
28 import json
29 from rest.client import RestClient
30 from project import Project
31 from project import Iteration
32 from error import *
33
35 """
36 Provides services to interact with Project, handle operaions of list, create and retrieve Project Resources
37 """
38 - def __init__(self, base_url, usrname, apikey):
39 self.restclient = RestClient(base_url)
40 self.iterations = IterationService(base_url, usrname, apikey)
41 self.username = usrname
42 self.apikey = apikey
43
45 """
46 List the Project Resources on the Flies server
47 @return: list of Project object
48 """
49 res, content = self.restclient.request_get('/projects')
50
51 if res['status'] == '200':
52 projects = []
53 projects_json = json.loads(content)
54
55 for p in projects_json:
56 projects.append(Project(json = p))
57 return projects
58
59 - def get(self, projectid):
60 """
61 Retrieve a specified Project Resource on Flies server
62 @param projectid: Id of Project Resource
63 @return: Project object
64 @raise NoSuchProjectException:
65 """
66 res, content = self.restclient.request_get('/projects/p/%s'%projectid)
67 if res['status'] == '200':
68 return Project(json = json.loads(content), iterations = self.iterations)
69 elif res['status'] == '404':
70 raise NoSuchProjectException('Error 404', 'No Such project')
71
73 """
74 Create a Project Resource on Flies Server
75 @param project: Project object
76 @return: Success if status of response is 201
77 @raise ProjectExistException:
78 @raise NoSuchProjectException:
79 @raise UnAuthorizedException:
80 @raise BadRequestException:
81 """
82 exist = False
83 headers = {}
84 headers['X-Auth-User'] = self.username
85 headers['X-Auth-Token'] = self.apikey
86 try:
87 self.get(project.id)
88 raise ProjectExistException('Status 200', 'The project is already exist')
89 except NoSuchProjectException:
90 exist = False
91
92 body ='''{"name":"%s","id":"%s","description":"%s","type":"IterationProject"}'''%(project.name,project.id,project.desc)
93 res, content = self.restclient.request_put('/projects/p/%s'%project.id, args=body, headers=headers)
94
95 if res['status'] == '201':
96 return "Success"
97 elif rest['status'] == '200':
98 raise ProjectExistException('Status 200', 'The project is already exist')
99 elif res['status'] == '404':
100 raise NoSuchProjectException('Error 404', 'No Such project')
101 elif res['status'] == '401':
102 raise UnAuthorizedException('Error 401', 'Un Authorized Operation')
103 elif res['status'] == '400':
104 raise BadRequestException('Error 400', 'Bad Request')
105
108
111
113 """
114 Provides services to interact with Project iteration, handle operaions of list, create and retrieve iteration Resources
115 """
116 - def __init__(self, base_url, usrname = None, apikey = None):
117 self.restclient = RestClient(base_url)
118 self.username = usrname
119 self.apikey = apikey
120
121 - def get(self, projectid, iterationid):
122 """
123 Retrieve a specified Iteration Resource on Flies server
124 @param projectid: Id of Project Resource
125 @param iterationid: Id of Iteration Resource
126 @return: Iteration object
127 @raise NoSuchProjectException:
128 """
129 res, content = self.restclient.request_get('/projects/p/%s/iterations/i/%s'%(projectid,iterationid))
130 if res['status'] == '200':
131 return Iteration(json.loads(content))
132 elif res['status'] == '404':
133 raise NoSuchProjectException('Error 404', 'No Such project')
134
135 - def create(self, projectid, iteration):
136 """
137 Create a Iteration Resource on Flies Server
138 @param projectid: Id of Project Resource
139 @param iteration: Iteration object
140 @return: Success if status of response is 201
141 @raise ProjectExistException:
142 @raise NoSuchProjectException:
143 @raise UnAuthorizedException:
144 @raise BadRequestException:
145 """
146 headers = {}
147 headers['X-Auth-User'] = self.username
148 headers['X-Auth-Token'] = self.apikey
149
150 body = '''{"name":"%s","id":"%s","description":"%s"}'''%(iteration.name, iteration.id, iteration.desc)
151 res, content = self.restclient.request_put('/projects/p/%s/iterations/i/%s'%(projectid,iteration.id), args=body, headers=headers)
152 if res['status'] == '201':
153 return "Success"
154 elif res['status'] == '200':
155 raise ProjectExistException('Status 200', 'The project is already exist')
156 elif res['status'] == '404':
157 raise NoSuchProjectException('Error 404', 'No Such project')
158 elif res['status'] == '401':
159 raise UnAuthorizedException('Error 401', 'UnAuthorized Operation')
160
163