root / snf-quotaholder-app / quotaholder_django / test / createrelease.py @ e6f3e652
History | View | Annotate | Download (6.5 kB)
1 |
# Copyright 2012 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
from config import QHTestCase |
35 |
from config import run_test_case |
36 |
from config import rand_string |
37 |
from config import printf |
38 |
import os |
39 |
|
40 |
#def create_entity OK
|
41 |
#def set_entity_key OK
|
42 |
#def list_entities OK
|
43 |
#def get_entity OK
|
44 |
#def get_limits LOVERDOS
|
45 |
#def set_limits LOVERDOS
|
46 |
#def release_entity OK
|
47 |
#def get_holding
|
48 |
#def set_holding
|
49 |
#def list_resources
|
50 |
#def get_quota
|
51 |
#def set_quota
|
52 |
#def issue_commission
|
53 |
#def accept_commission
|
54 |
#def reject_commission
|
55 |
#def get_pending_commissions
|
56 |
#def resolve_pending_commissions
|
57 |
#def get_timeline
|
58 |
|
59 |
class Context(object): |
60 |
entityName = rand_string() |
61 |
entityKey = "key1"
|
62 |
parentName = "pgerakios"
|
63 |
parentKey = "key1"
|
64 |
|
65 |
class create_release(object): |
66 |
|
67 |
def __init__(self, f): |
68 |
"""
|
69 |
If there are no decorator arguments, the function
|
70 |
to be decorated is passed to the constructor.
|
71 |
"""
|
72 |
print "Inside __init__()" |
73 |
self.f = f
|
74 |
|
75 |
def __call__(self, *args): |
76 |
"""
|
77 |
The __call__ method is not called until the
|
78 |
decorated function is called.
|
79 |
"""
|
80 |
print "Inside __call__()" |
81 |
self.f(*args)
|
82 |
print "After self.f(*args)" |
83 |
|
84 |
|
85 |
class CreateReleaseListAPITest(QHTestCase): |
86 |
|
87 |
entityName = rand_string() |
88 |
entityKey = "key1"
|
89 |
parentName = "pgerakios"
|
90 |
parentKey = "key1"
|
91 |
|
92 |
def createEntity(self): |
93 |
printf("Creating entity: {0}", self.entityName) |
94 |
rejected = self.qh.create_entity(context={},
|
95 |
create_entity=[(self.entityName,
|
96 |
self.parentName,
|
97 |
self.entityKey,
|
98 |
self.parentKey)])
|
99 |
self.assertEqual(rejected,[])
|
100 |
|
101 |
def releaseEntity(self): |
102 |
printf("Releasing entity: {0}", self.entityName) |
103 |
rejected = self.qh.release_entity(context={},release_entity=[(self.entityName, |
104 |
self.entityKey)])
|
105 |
self.assertEqual(rejected,[])
|
106 |
|
107 |
def checkEntityList(self,exists): |
108 |
entityList = self.qh.list_entities(context={},entity=self.parentName,key=self.parentKey) |
109 |
if(exists):
|
110 |
self.assertTrue(self.entityName in entityList) |
111 |
else:
|
112 |
self.assertFalse(self.entityName in entityList) |
113 |
|
114 |
def setNewEntityKey(self): |
115 |
entityKey2 = rand_string() |
116 |
rejected = self.qh.set_entity_key(context={},set_entity_key=[(self.entityName, |
117 |
self.entityKey,
|
118 |
entityKey2)]) |
119 |
self.assertEqual(rejected,[])
|
120 |
self.entityKey = entityKey2
|
121 |
|
122 |
def checkGetEntity(self,exists): |
123 |
entityList = self.qh.get_entity(context={},get_entity=[(self.entityName, |
124 |
self.entityKey)])
|
125 |
if(exists):
|
126 |
self.assertEqual([(self.entityName,self.parentName)],entityList) |
127 |
else:
|
128 |
self.assertEqual(entityList,[])
|
129 |
|
130 |
def listResources(self,expected): |
131 |
resList = self.qh.list_resources(context={},entity=self.entityName,key=self.entityKey) |
132 |
self.assertEqual(expected,resList)
|
133 |
|
134 |
def setQuota(self,r,q,c,i,e,f): |
135 |
rejected = self.qh.set_quota(context={},set_quota=[(self.entityName,r,self.entityKey,q,c,i,e,f)]) |
136 |
self.assertEqual(rejected,[])
|
137 |
resList = self.qh.get_quota(context={},get_quota=[(self.entityName,r,self.entityKey)]) |
138 |
(e0,r1,q1,c1,i1,e1,t0,t1,t2,t3,f1),tail = resList[0],resList[1:] |
139 |
self.assertEqual(tail,[])
|
140 |
self.assertEqual((self.entityName,r,q,c,i,e,f), |
141 |
(e0,r1,q1,c1,i1,e1,f1)) |
142 |
|
143 |
# def issueCommission(self):
|
144 |
# self.qh.issue_commission
|
145 |
def setUp(self): |
146 |
self.qh.create_entity(create_entity=[("pgerakios", "system", "key1", "")]) |
147 |
self.parentName = "pgerakios" |
148 |
self.parentKey = "key1" |
149 |
|
150 |
|
151 |
|
152 |
#BUG: max empty name <= 72
|
153 |
def test_001(self): |
154 |
self.createEntity()
|
155 |
self.releaseEntity()
|
156 |
|
157 |
# Test create, list and release
|
158 |
def test_002(self): |
159 |
self.checkEntityList(False) |
160 |
self.createEntity()
|
161 |
self.checkEntityList(True) |
162 |
self.releaseEntity()
|
163 |
self.checkEntityList(False) |
164 |
|
165 |
|
166 |
# Test create,set key and release
|
167 |
def test_003(self): |
168 |
self.createEntity()
|
169 |
self.setNewEntityKey()
|
170 |
self.setNewEntityKey()
|
171 |
self.releaseEntity()
|
172 |
|
173 |
# test get_entity
|
174 |
def test_004(self): |
175 |
self.checkGetEntity(False) |
176 |
self.createEntity()
|
177 |
self.checkGetEntity(True) |
178 |
self.releaseEntity()
|
179 |
self.checkGetEntity(False) |
180 |
|
181 |
def test_005(self): |
182 |
self.createEntity()
|
183 |
self.setQuota("res1",10,100,10,10,0) |
184 |
# self.listResources([])
|
185 |
self.releaseEntity()
|
186 |
|
187 |
if __name__ == "__main__": |
188 |
import sys |
189 |
printf("Using {0}", sys.executable)
|
190 |
run_test_case(CreateReleaseListAPITest) |