| 33 | | # def tearDown(self): |
| 34 | | |
| 35 | | |
| 36 | | def _init(self): |
| 37 | | print "init" |
| 38 | | try: |
| 39 | | self.plugin = Plugin.objects.get(plugin_name=TEST_PLUGIN_NAME) |
| 40 | | except Plugin.DoesNotExist, err: |
| 41 | | from PyLucid.system.plugin_manager import install_plugin |
| 42 | | self.plugin = install_plugin( |
| 43 | | package_name = "PyLucid.plugins_external", |
| 44 | | plugin_name = "unittest_plugin", |
| 45 | | debug = True, |
| 46 | | active=True, |
| 47 | | extra_verbose=True, |
| 48 | | ) |
| 49 | | else: |
| 50 | | print "Plugin exists ID:", self.plugin.id |
| 51 | | |
| 52 | | def _delete(self): |
| 53 | | print "delete" |
| 54 | | try: |
| 55 | | self.plugin.delete() |
| 56 | | except Exception, err: |
| 57 | | print "tearDown Error:", err |
| 58 | | |
| 59 | | def setUp(self): |
| | 46 | def setUp(self): |
| 118 | | def test_init_plugin(self): |
| 119 | | """ |
| 120 | | First we must install the plugin |
| 121 | | """ |
| 122 | | print "XXXXXXXXX" |
| | 98 | def _get_plugin(self): |
| | 99 | return Plugin.objects.get(plugin_name=TEST_PLUGIN_NAME) |
| | 100 | |
| | 101 | #___________________________________________________________________________ |
| | 102 | # PRETESTS |
| | 103 | |
| | 104 | def test_plugin_exist(self): |
| | 105 | """ |
| | 106 | Test if the unittest plugin is normal installed and active |
| | 107 | """ |
| | 108 | try: |
| | 109 | self.plugin = self._get_plugin() |
| | 110 | except Plugin.DoesNotExist, err: |
| | 111 | self.fail("Plugin doesn't exist: %s" % err) |
| | 112 | |
| | 113 | self.failUnless(self.plugin.active, True) |
| | 114 | #print "Plugin exists ID:", self.plugin.id |
| | 115 | |
| | 116 | def test_hello_world(self): |
| | 117 | """ |
| | 118 | Checks via _command url the hello world response |
| | 119 | """ |
| | 120 | url = self.command % "hello_world" |
| | 121 | response = self.client.get(url) |
| | 122 | # Check that the respose is 200 Ok. |
| | 123 | self.failUnlessEqual(response.status_code, 200) |
| | 124 | self.assertEqual2( |
| | 125 | response.content.strip(), |
| | 126 | ( |
| | 127 | '<div class="PyLucidPlugins unittest_plugin"' |
| | 128 | ' id="unittest_plugin_hello_world">\n' |
| | 129 | 'Hello world!\n' |
| | 130 | '</div>' |
| | 131 | ) |
| | 132 | ) |
| | 133 | |
| | 134 | |
| | 135 | class PluginModel(PluginAPI_Base): |
| | 136 | """ |
| | 137 | Tests around the plugin models. |
| | 138 | """ |
| | 139 | def test_plugin_models(self): |
| | 140 | """ |
| | 141 | Test the plugin models. |
| | 142 | Request three times the plugin_models view. This view creates on |
| | 143 | every request a new model entry in both test models and display |
| | 144 | some informations around this. |
| | 145 | After this, we request a view with a list of all existing model entries. |
| | 146 | """ |
| | 147 | self.login("superuser") # login client as superuser |
| | 148 | |
| 124 | | content = self._get_plugin_content(url) |
| 125 | | |
| 126 | | |
| 127 | | def test_first_check(self): |
| 128 | | """ |
| 129 | | Check if the test plugin exist and is active |
| 130 | | """ |
| 131 | | # self._init() |
| 132 | | try: |
| 133 | | plugin = Plugin.objects.get(plugin_name=TEST_PLUGIN_NAME) |
| 134 | | except Plugin.DoesNotExist, err: |
| 135 | | self.fail("test plugin doesn't exist in the database: %s" % err) |
| 136 | | |
| 137 | | self.failUnless(plugin.active, True) |
| | 150 | |
| | 151 | content = self._get_plugin_content(url)#, debug=True) |
| | 152 | self.assertEqual2( |
| | 153 | content, |
| | 154 | MODEL_TEST % {"no": 1} |
| | 155 | ) |
| | 156 | |
| | 157 | content = self._get_plugin_content(url)#, debug=True) |
| | 158 | self.assertEqual2( |
| | 159 | content, |
| | 160 | MODEL_TEST % {"no": 2} |
| | 161 | ) |
| | 162 | |
| | 163 | content = self._get_plugin_content(url)#, debug=True) |
| | 164 | self.assertEqual2( |
| | 165 | content, |
| | 166 | MODEL_TEST % {"no": 3} |
| | 167 | ) |
| | 168 | |
| | 169 | # Test all models view: A list of all existing models. |
| | 170 | url = self.command % "all_models" |
| | 171 | content = self._get_plugin_content(url)#, debug=True) |
| | 172 | self.assertEqual2( |
| | 173 | content, |
| | 174 | ( |
| | 175 | "<pre>\n" |
| | 176 | "All Albums:\n" |
| | 177 | "1: TestAlbum 'A test Album', ID 1, createby: superuser\n" |
| | 178 | "2: TestAlbum 'A test Album', ID 2, createby: superuser\n" |
| | 179 | "3: TestAlbum 'A test Album', ID 3, createby: superuser\n" |
| | 180 | "</pre>" |
| | 181 | ) |
| | 182 | ) |
| | 183 | |
| | 184 | def test_reinit(self): |
| | 185 | """ |
| | 186 | reinit the plugin and check if the plugin model tabels would be |
| | 187 | droped and re-created. |
| | 188 | """ |
| | 189 | plugin = self._get_plugin() |
| 139 | | # self._delete() |
| 140 | | |
| 141 | | def test_hello_world(self): |
| 142 | | """ |
| 143 | | Checks via _command url the hello world response |
| 144 | | """ |
| 145 | | url = self.command % "hello_world" |
| 146 | | content = self._get_plugin_content(url) |
| 147 | | self.assertEqual(content, "Hello world!") |
| 148 | | |
| | 191 | package_name = plugin.package_name |
| | 192 | plugin_name = plugin.plugin_name |
| | 193 | |
| | 194 | # remove the plugin completely from the database |
| | 195 | # plugin model tables should be droped |
| | 196 | plugin.delete() |
| | 197 | |
| | 198 | # install the plugin |
| | 199 | # plugin model tables should be re-created, too. |
| | 200 | install_plugin(package_name, plugin_name, debug=True, active=True, |
| | 201 | extra_verbose=True) |
| | 202 | |
| | 203 | # Check 1: |
| | 204 | content = self._get_plugin_content(url)#, debug=True) |
| | 205 | self.assertEqual2( |
| | 206 | content, |
| | 207 | MODEL_TEST % {"no": 1} |
| | 208 | ) |
| | 209 | |
| | 210 | # Check 2: |
| | 211 | url = self.command % "all_models" |
| | 212 | content = self._get_plugin_content(url)#, debug=True) |
| | 213 | self.assertEqual2( |
| | 214 | content, |
| | 215 | ( |
| | 216 | "<pre>\n" |
| | 217 | "All Albums:\n" |
| | 218 | "1: TestAlbum 'A test Album', ID 1, createby: superuser\n" |
| | 219 | "</pre>" |
| | 220 | ) |
| | 221 | ) |
| | 222 | |
| | 223 | |
| | 224 | class PluginModel(PluginAPI_Base): |
| | 225 | """ |
| | 226 | pass parameters to the plugin method. |
| | 227 | """ |
| 155 | | Test arguments in a _command url |
| 156 | | """ |
| 157 | | content = self._get_plugin_content(self.test_url, debug=False) |
| 158 | | self.assertEqual( |
| 159 | | content, "args: (), kwargs: {}" |
| 160 | | ) |
| 161 | | |
| 162 | | self.test_page.content = '{% lucidTag unittest_plugin arg1="test1" %}' |
| 163 | | self.test_page.save() |
| 164 | | content = self._get_plugin_content(self.test_url, debug=False) |
| 165 | | self.assertEqual( |
| 166 | | content, "args: (), kwargs: {'arg1': u'test1'}" |
| 167 | | ) |
| 168 | | |
| 169 | | self.test_page.content = '{% lucidTag unittest_plugin arg1=True %}' |
| 170 | | self.test_page.save() |
| 171 | | content = self._get_plugin_content(self.test_url, debug=True) |
| 172 | | self.assertEqual( |
| 173 | | content, "args: (), kwargs: {'arg1': True}" |
| | 234 | Test arguments in the lucidTag |
| | 235 | Handled in PyLucid.template_addons.lucidTag |
| | 236 | """ |
| | 237 | def get_args_info(page_content): |
| | 238 | self.test_page.content = page_content |
| | 239 | self.test_page.save() |
| | 240 | content = self._get_plugin_content(self.test_url, debug=False) |
| | 241 | args_info = content.split("\n") |
| | 242 | return (args_info[1], args_info[3]) |
| | 243 | |
| | 244 | |
| | 245 | args, kwargs = get_args_info('{% lucidTag unittest_plugin %}') |
| | 246 | self.assertEqual2(args, "()") |
| | 247 | self.assertEqual2(kwargs, "{}") |
| | 248 | |
| | 249 | |
| | 250 | args, kwargs = get_args_info( |
| | 251 | '{% lucidTag unittest_plugin arg1="test1" %}' |
| | 252 | ) |
| | 253 | self.assertEqual2(args, "()") |
| | 254 | self.assertEqual2(kwargs, "{'arg1': u'test1'}") |
| | 255 | |
| | 256 | |
| | 257 | args, kwargs = get_args_info( |
| | 258 | '{% lucidTag unittest_plugin a="0" b="1" c="2" %}' |
| | 259 | ) |
| | 260 | self.assertEqual2(args, "()") |
| | 261 | self.assertEqual2(kwargs, "{'a': u'0', 'b': u'1', 'c': u'2'}") |
| | 262 | |
| | 263 | |
| | 264 | args, kwargs = get_args_info( |
| | 265 | '{% lucidTag unittest_plugin' |
| | 266 | ' t1="True" f1="False" t2="true" f2="false" %}' |
| | 267 | ) |
| | 268 | self.assertEqual2(args, "()") |
| | 269 | self.assertEqual2(kwargs, |
| | 270 | "{'f1': False, 'f2': False, 't1': True, 't2': True}" |