comparison src/test/test_memory.py @ 1271:2308f8405ffb

test: refactoring: - rename internal init methods to reinit - rename getSentMessage to getSentMessageXml - rename getSentMessageRaw to getSentMessage
author souliane <souliane@mailoo.org>
date Fri, 19 Dec 2014 11:36:00 +0100
parents 854880a31717
children 069ad98b360d
comparison
equal deleted inserted replaced
1270:037ec0795a85 1271:2308f8405ffb
134 if profile_key == '@NONE@': 134 if profile_key == '@NONE@':
135 profile_key = '@DEFAULT@' 135 profile_key = '@DEFAULT@'
136 return self.host.memory.getParams(security_limit, app, profile_key) 136 return self.host.memory.getParams(security_limit, app, profile_key)
137 137
138 def test_updateParams(self): 138 def test_updateParams(self):
139 self.host.memory.init() 139 self.host.memory.reinit()
140 # check if the update works 140 # check if the update works
141 self.host.memory.updateParams(self._getParamXML()) 141 self.host.memory.updateParams(self._getParamXML())
142 self.assertParamExists() 142 self.assertParamExists()
143 previous = self.host.memory.params.dom.cloneNode(True) 143 previous = self.host.memory.params.dom.cloneNode(True)
144 # now check if it is really updated and not duplicated 144 # now check if it is really updated and not duplicated
145 self.host.memory.updateParams(self._getParamXML()) 145 self.host.memory.updateParams(self._getParamXML())
146 self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8")) 146 self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8"))
147 147
148 self.host.memory.init() 148 self.host.memory.reinit()
149 # check successive updates (without intersection) 149 # check successive updates (without intersection)
150 self.host.memory.updateParams(self._getParamXML('1')) 150 self.host.memory.updateParams(self._getParamXML('1'))
151 self.assertParamExists("1") 151 self.assertParamExists("1")
152 self.assertParamNotExists("2") 152 self.assertParamNotExists("2")
153 self.host.memory.updateParams(self._getParamXML('2')) 153 self.host.memory.updateParams(self._getParamXML('2'))
154 self.assertParamExists("1") 154 self.assertParamExists("1")
155 self.assertParamExists("2") 155 self.assertParamExists("2")
156 156
157 previous = self.host.memory.params.dom.cloneNode(True) # save for later 157 previous = self.host.memory.params.dom.cloneNode(True) # save for later
158 158
159 self.host.memory.init() 159 self.host.memory.reinit()
160 # check successive updates (with intersection) 160 # check successive updates (with intersection)
161 self.host.memory.updateParams(self._getParamXML('1')) 161 self.host.memory.updateParams(self._getParamXML('1'))
162 self.assertParamExists("1") 162 self.assertParamExists("1")
163 self.assertParamNotExists("2") 163 self.assertParamNotExists("2")
164 self.host.memory.updateParams(self._getParamXML('12')) 164 self.host.memory.updateParams(self._getParamXML('12'))
166 self.assertParamExists("2") 166 self.assertParamExists("2")
167 167
168 # successive updates with or without intersection should have the same result 168 # successive updates with or without intersection should have the same result
169 self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8")) 169 self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8"))
170 170
171 self.host.memory.init() 171 self.host.memory.reinit()
172 # one update with two params in a new category 172 # one update with two params in a new category
173 self.host.memory.updateParams(self._getParamXML('12')) 173 self.host.memory.updateParams(self._getParamXML('12'))
174 self.assertParamExists("1") 174 self.assertParamExists("1")
175 self.assertParamExists("2") 175 self.assertParamExists("2")
176 176
177 def test_getParams(self): 177 def test_getParams(self):
178 # tests with no security level on the parameter (most secure) 178 # tests with no security level on the parameter (most secure)
179 params = self._getParamXML() 179 params = self._getParamXML()
180 self.host.memory.init() 180 self.host.memory.reinit()
181 self.host.memory.updateParams(params) 181 self.host.memory.updateParams(params)
182 self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async) 182 self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
183 self._getParams(0).addCallback(self.assertParamNotExists_async) 183 self._getParams(0).addCallback(self.assertParamNotExists_async)
184 self._getParams(1).addCallback(self.assertParamNotExists_async) 184 self._getParams(1).addCallback(self.assertParamNotExists_async)
185 # tests with security level 0 on the parameter (not secure) 185 # tests with security level 0 on the parameter (not secure)
186 params = self._getParamXML(security_level=0) 186 params = self._getParamXML(security_level=0)
187 self.host.memory.init() 187 self.host.memory.reinit()
188 self.host.memory.updateParams(params) 188 self.host.memory.updateParams(params)
189 self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async) 189 self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
190 self._getParams(0).addCallback(self.assertParamExists_async) 190 self._getParams(0).addCallback(self.assertParamExists_async)
191 self._getParams(1).addCallback(self.assertParamExists_async) 191 self._getParams(1).addCallback(self.assertParamExists_async)
192 # tests with security level 1 on the parameter (more secure) 192 # tests with security level 1 on the parameter (more secure)
193 params = self._getParamXML(security_level=1) 193 params = self._getParamXML(security_level=1)
194 self.host.memory.init() 194 self.host.memory.reinit()
195 self.host.memory.updateParams(params) 195 self.host.memory.updateParams(params)
196 self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async) 196 self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
197 self._getParams(0).addCallback(self.assertParamNotExists_async) 197 self._getParams(0).addCallback(self.assertParamNotExists_async)
198 return self._getParams(1).addCallback(self.assertParamExists_async) 198 return self._getParams(1).addCallback(self.assertParamExists_async)
199 199
211 self.host.memory.paramsRegisterApp(xml, security_limit, app) 211 self.host.memory.paramsRegisterApp(xml, security_limit, app)
212 logger.setLevel(level) 212 logger.setLevel(level)
213 213
214 # tests with no security level on the parameter (most secure) 214 # tests with no security level on the parameter (most secure)
215 params = self._getParamXML() 215 params = self._getParamXML()
216 self.host.memory.init() 216 self.host.memory.reinit()
217 register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) 217 register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
218 self.assertParamExists() 218 self.assertParamExists()
219 self.host.memory.init() 219 self.host.memory.reinit()
220 register(params, 0, Const.APP_NAME) 220 register(params, 0, Const.APP_NAME)
221 self.assertParamNotExists() 221 self.assertParamNotExists()
222 self.host.memory.init() 222 self.host.memory.reinit()
223 register(params, 1, Const.APP_NAME) 223 register(params, 1, Const.APP_NAME)
224 self.assertParamNotExists() 224 self.assertParamNotExists()
225 225
226 # tests with security level 0 on the parameter (not secure) 226 # tests with security level 0 on the parameter (not secure)
227 params = self._getParamXML(security_level=0) 227 params = self._getParamXML(security_level=0)
228 self.host.memory.init() 228 self.host.memory.reinit()
229 register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) 229 register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
230 self.assertParamExists() 230 self.assertParamExists()
231 self.host.memory.init() 231 self.host.memory.reinit()
232 register(params, 0, Const.APP_NAME) 232 register(params, 0, Const.APP_NAME)
233 self.assertParamExists() 233 self.assertParamExists()
234 self.host.memory.init() 234 self.host.memory.reinit()
235 register(params, 1, Const.APP_NAME) 235 register(params, 1, Const.APP_NAME)
236 self.assertParamExists() 236 self.assertParamExists()
237 237
238 # tests with security level 1 on the parameter (more secure) 238 # tests with security level 1 on the parameter (more secure)
239 params = self._getParamXML(security_level=1) 239 params = self._getParamXML(security_level=1)
240 self.host.memory.init() 240 self.host.memory.reinit()
241 register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) 241 register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
242 self.assertParamExists() 242 self.assertParamExists()
243 self.host.memory.init() 243 self.host.memory.reinit()
244 register(params, 0, Const.APP_NAME) 244 register(params, 0, Const.APP_NAME)
245 self.assertParamNotExists() 245 self.assertParamNotExists()
246 self.host.memory.init() 246 self.host.memory.reinit()
247 register(params, 1, Const.APP_NAME) 247 register(params, 1, Const.APP_NAME)
248 self.assertParamExists() 248 self.assertParamExists()
249 249
250 # tests with security level 1 and several parameters being registered 250 # tests with security level 1 and several parameters being registered
251 params = self._getParamXML("12", security_level=1) 251 params = self._getParamXML("12", security_level=1)
252 self.host.memory.init() 252 self.host.memory.reinit()
253 register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) 253 register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
254 self.assertParamExists() 254 self.assertParamExists()
255 self.assertParamExists("2") 255 self.assertParamExists("2")
256 self.host.memory.init() 256 self.host.memory.reinit()
257 register(params, 0, Const.APP_NAME) 257 register(params, 0, Const.APP_NAME)
258 self.assertParamNotExists() 258 self.assertParamNotExists()
259 self.assertParamNotExists("2") 259 self.assertParamNotExists("2")
260 self.host.memory.init() 260 self.host.memory.reinit()
261 register(params, 1, Const.APP_NAME) 261 register(params, 1, Const.APP_NAME)
262 self.assertParamExists() 262 self.assertParamExists()
263 self.assertParamExists("2") 263 self.assertParamExists("2")
264 264
265 # tests with several parameters being registered in an existing category 265 # tests with several parameters being registered in an existing category
266 self.host.memory.init() 266 self.host.memory.reinit()
267 self.host.memory.updateParams(self._getParamXML("3")) 267 self.host.memory.updateParams(self._getParamXML("3"))
268 register(self._getParamXML("12"), Const.NO_SECURITY_LIMIT, Const.APP_NAME) 268 register(self._getParamXML("12"), Const.NO_SECURITY_LIMIT, Const.APP_NAME)
269 self.assertParamExists() 269 self.assertParamExists()
270 self.assertParamExists("2") 270 self.assertParamExists("2")
271 self.host.memory.init() 271 self.host.memory.reinit()
272 272
273 def test_paramsRegisterApp_getParams(self): 273 def test_paramsRegisterApp_getParams(self):
274 # test retrieving the parameter for a specific frontend 274 # test retrieving the parameter for a specific frontend
275 self.host.memory.init() 275 self.host.memory.reinit()
276 params = self._getParamXML(security_level=1) 276 params = self._getParamXML(security_level=1)
277 self.host.memory.paramsRegisterApp(params, 1, Const.APP_NAME) 277 self.host.memory.paramsRegisterApp(params, 1, Const.APP_NAME)
278 self._getParams(1, '').addCallback(self.assertParamExists_async) 278 self._getParams(1, '').addCallback(self.assertParamExists_async)
279 self._getParams(1, Const.APP_NAME).addCallback(self.assertParamExists_async) 279 self._getParams(1, Const.APP_NAME).addCallback(self.assertParamExists_async)
280 self._getParams(1, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async) 280 self._getParams(1, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async)
281 281
282 # the same with several parameters registered at the same time 282 # the same with several parameters registered at the same time
283 self.host.memory.init() 283 self.host.memory.reinit()
284 params = self._getParamXML('12', security_level=0) 284 params = self._getParamXML('12', security_level=0)
285 self.host.memory.paramsRegisterApp(params, 5, Const.APP_NAME) 285 self.host.memory.paramsRegisterApp(params, 5, Const.APP_NAME)
286 self._getParams(5, '').addCallback(self.assertParamExists_async) 286 self._getParams(5, '').addCallback(self.assertParamExists_async)
287 self._getParams(5, '').addCallback(self.assertParamExists_async, "2") 287 self._getParams(5, '').addCallback(self.assertParamExists_async, "2")
288 self._getParams(5, Const.APP_NAME).addCallback(self.assertParamExists_async) 288 self._getParams(5, Const.APP_NAME).addCallback(self.assertParamExists_async)