annotate src/test/test_memory_memory.py @ 890:10bb8574ab11

plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
author souliane <souliane@mailoo.org>
date Tue, 25 Feb 2014 11:32:21 +0100
parents 9bac2fc74968
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
3
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
4 # SAT: a jabber client
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 795
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
6
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # (at your option) any later version.
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
11
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
16
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
19
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
20 from sat.core.i18n import _
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
21 from sat.test import helpers
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
22 from twisted.trial import unittest
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
23 import traceback
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
24 import logging
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
25 from constants import Const
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
26 from xml.dom import minidom
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
27
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
28
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
29 class MemoryTest(unittest.TestCase):
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
30
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
31 def setUp(self):
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
32 self.host = helpers.FakeSAT()
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
33
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
34 def _getParamXML(self, param="1", security_level=None):
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
35 def getParam(name):
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
36 return """
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
37 <param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" %(security)s/>
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
38 """ % {'param_name': name,
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
39 'param_label': _(name),
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
40 'security': '' if security_level is None else ('security="%d"' % security_level)
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
41 }
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
42 if param == "1":
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
43 params = getParam(Const.ENABLE_UNIBOX_PARAM)
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
44 elif param == "2":
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
45 params = getParam(Const.PARAM_IN_QUOTES)
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
46 else:
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
47 params = getParam(Const.ENABLE_UNIBOX_PARAM) + getParam(Const.PARAM_IN_QUOTES)
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
48 return """
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
49 <params>
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
50 <individual>
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
51 <category name="%(category_name)s" label="%(category_label)s">
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
52 %(params)s
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
53 </category>
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
54 </individual>
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
55 </params>
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
56 """ % {
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
57 'category_name': Const.COMPOSITION_KEY,
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
58 'category_label': _(Const.COMPOSITION_KEY),
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
59 'params': params
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
60 }
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
61
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
62 def _paramExists(self, param="1", src=None):
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
63 """@return: True is the param (category, name) exists"""
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
64 if param == "1":
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
65 name = Const.ENABLE_UNIBOX_PARAM
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
66 else:
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
67 name = Const.PARAM_IN_QUOTES
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
68 category = Const.COMPOSITION_KEY
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
69 if src is None:
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
70 src = self.host.memory.params.dom.documentElement
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
71 for type_node in src.childNodes:
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
72 # when src comes self.host.memory.params.dom, we have here
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
73 # some "individual" or "general" elements, when it comes
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
74 # from Memory.getParams we have here a "params" elements
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
75 if type_node.nodeName not in ("individual", "general", "params"):
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
76 continue
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
77 for cat_node in type_node.childNodes:
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
78 if cat_node.nodeName != "category" or cat_node.getAttribute("name") != category:
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
79 continue
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
80 for param in cat_node.childNodes:
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
81 if param.nodeName == "param" and param.getAttribute("name") == name:
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
82 return True
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
83 return False
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
84
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
85 def assertParam_generic(self, param="1", src=None, exists=True, deferred=False):
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
86 msg = "Expected parameter not found!\n" if exists else "Unexpected parameter found!\n"
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
87 if deferred == False:
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
88 # in this stack we can see the line where the error came from,
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
89 # if limit=5, 6 is not enough you can increase the value
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
90 msg += "\n".join(traceback.format_stack(limit=5 if exists else 6))
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
91 assertion = self._paramExists(param, src)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
92 getattr(self, "assert%s" % exists)(assertion, msg)
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
93
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
94 def assertParamExists(self, param="1", src=None):
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
95 self.assertParam_generic(param, src, True)
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
96
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
97 def assertParamNotExists(self, param="1", src=None):
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
98 self.assertParam_generic(param, src, False)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
99
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
100 def assertParamExists_async(self, src, param="1"):
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
101 """@param src: a deferred result from Memory.getParams"""
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
102 self.assertParam_generic(param, minidom.parseString(src.encode("utf-8")), True, True)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
103
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
104 def assertParamNotExists_async(self, src, param="1"):
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
105 """@param src: a deferred result from Memory.getParams"""
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
106 self.assertParam_generic(param, minidom.parseString(src.encode("utf-8")), False, True)
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
107
786
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 782
diff changeset
108 def _getParams(self, security_limit, app='', profile_key='@NONE@'):
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 782
diff changeset
109 if profile_key == '@NONE@':
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 782
diff changeset
110 profile_key = '@DEFAULT@'
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 782
diff changeset
111 return self.host.memory.getParams(security_limit, app, profile_key)
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 782
diff changeset
112
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
113 def test_updateParams(self):
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
114 self.host.memory.init()
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
115 # check if the update works
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
116 self.host.memory.updateParams(self._getParamXML())
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
117 self.assertParamExists()
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
118 previous = self.host.memory.params.dom.cloneNode(True)
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
119 # now check if it is really updated and not duplicated
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
120 self.host.memory.updateParams(self._getParamXML())
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
121 self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8"))
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
122
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
123 self.host.memory.init()
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
124 # check successive updates (without intersection)
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
125 self.host.memory.updateParams(self._getParamXML('1'))
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
126 self.assertParamExists("1")
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
127 self.assertParamNotExists("2")
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
128 self.host.memory.updateParams(self._getParamXML('2'))
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
129 self.assertParamExists("1")
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
130 self.assertParamExists("2")
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
131
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
132 previous = self.host.memory.params.dom.cloneNode(True) # save for later
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
133
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
134 self.host.memory.init()
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
135 # check successive updates (with intersection)
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
136 self.host.memory.updateParams(self._getParamXML('1'))
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
137 self.assertParamExists("1")
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
138 self.assertParamNotExists("2")
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
139 self.host.memory.updateParams(self._getParamXML('both'))
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
140 self.assertParamExists("1")
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
141 self.assertParamExists("2")
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
142
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
143 # successive updates with or without intersection should have the same result
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
144 self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8"))
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
145
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
146 def test_getParams(self):
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
147 # tests with no security level on the parameter (most secure)
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
148 params = self._getParamXML()
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
149 self.host.memory.init()
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
150 self.host.memory.updateParams(params)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
151 self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
152 self._getParams(0).addCallback(self.assertParamNotExists_async)
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
153 self._getParams(1).addCallback(self.assertParamNotExists_async)
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
154 # tests with security level 0 on the parameter (not secure)
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
155 params = self._getParamXML(security_level=0)
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
156 self.host.memory.init()
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
157 self.host.memory.updateParams(params)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
158 self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
159 self._getParams(0).addCallback(self.assertParamExists_async)
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
160 self._getParams(1).addCallback(self.assertParamExists_async)
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
161 # tests with security level 1 on the parameter (more secure)
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
162 params = self._getParamXML(security_level=1)
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
163 self.host.memory.init()
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
164 self.host.memory.updateParams(params)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
165 self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
166 self._getParams(0).addCallback(self.assertParamNotExists_async)
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
167 self._getParams(1).addCallback(self.assertParamExists_async)
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
168
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
169 def test_paramsRegisterApp(self):
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
170
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
171 def register(*args):
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
172 logger = logging.getLogger()
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
173 level = logger.getEffectiveLevel()
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
174 logger.setLevel(logging.INFO)
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
175 self.host.memory.paramsRegisterApp(*args)
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
176 logger.setLevel(level)
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
177
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
178 # tests with no security level on the parameter (most secure)
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
179 params = self._getParamXML()
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
180 self.host.memory.init()
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
181 register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
182 self.assertParamExists()
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
183 self.host.memory.init()
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
184 register(params, 0, Const.APP_NAME)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
185 self.assertParamNotExists()
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
186 self.host.memory.init()
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
187 register(params, 1, Const.APP_NAME)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
188 self.assertParamNotExists()
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
189
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
190 # tests with security level 0 on the parameter (not secure)
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
191 params = self._getParamXML(security_level=0)
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
192 self.host.memory.init()
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
193 register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
194 self.assertParamExists()
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
195 self.host.memory.init()
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
196 register(params, 0, Const.APP_NAME)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
197 self.assertParamExists()
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
198 self.host.memory.init()
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
199 register(params, 1, Const.APP_NAME)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
200 self.assertParamExists()
833
9bac2fc74968 memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents: 811
diff changeset
201
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
202 # tests with security level 1 on the parameter (more secure)
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
203 params = self._getParamXML(security_level=1)
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
204 self.host.memory.init()
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
205 register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
206 self.assertParamExists()
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
207 self.host.memory.init()
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
208 register(params, 0, Const.APP_NAME)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
209 self.assertParamNotExists()
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
210 self.host.memory.init()
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 789
diff changeset
211 register(params, 1, Const.APP_NAME)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
212 self.assertParamExists()
782
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
213
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
214 def test_paramsRegisterApp_getParams(self):
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
215 # test retrieving the parameter for a specific frontend
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
216 self.host.memory.init()
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
217 params = self._getParamXML(security_level=1)
0e5807193721 test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
diff changeset
218 self.host.memory.paramsRegisterApp(params, 1, Const.APP_NAME)
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
219 self._getParams(1, '').addCallback(self.assertParamExists_async)
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
220 self._getParams(1, Const.APP_NAME).addCallback(self.assertParamExists_async)
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 786
diff changeset
221 self._getParams(1, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async)