Statistics
| Branch: | Tag: | Revision:

root / snf-quotaholder-app / quotaholder_django / test / createrelease.py @ 763b4da1

History | View | Annotate | Download (6.5 kB)

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