Changeset 1612
- Timestamp:
- 05/31/08 22:01:20 (22 months ago)
- Location:
- trunk
- Files:
-
- 8 modified
-
dev_scripts/local_tests/models_test.py (modified) (7 diffs)
-
pylucid/PyLucid/models/Plugin.py (modified) (6 diffs)
-
pylucid/PyLucid/system/plugin_manager.py (modified) (5 diffs)
-
pylucid/PyLucid/template_addons/lucidTag.py (modified) (1 diff)
-
pylucid/tests/test_plugin_api.py (modified) (6 diffs)
-
pylucid/tests/unittest_plugin/unittest_plugin.py (modified) (6 diffs)
-
pylucid/tests/unittest_plugin/unittest_plugin_cfg.py (modified) (1 diff)
-
pylucid/tests/__init__.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/dev_scripts/local_tests/models_test.py
r1607 r1612 19 19 from django.contrib.auth.models import User 20 20 21 # Use the models from the test plugin 22 from tests.unittest_plugin.unittest_plugin import TestArtist, TestAlbum 21 23 22 24 23 class Musician(models.Model): 24 first_name = models.CharField(max_length=50) 25 last_name = models.CharField(max_length=50) 26 instrument = models.CharField(max_length=100) 27 class Meta: 28 # db_table is optional 29 # db_table = 'PyLucid_test' 30 app_label = 'PyLucid' # must be set to "PyLucid" 25 print "-----------------------------------------------------------------------" 31 26 32 class Album(models.Model): 33 artist = models.ForeignKey("Musician") 34 name = models.CharField(max_length=100) 35 num_stars = models.IntegerField() 36 37 createtime = models.DateTimeField(auto_now_add=True) 38 lastupdatetime = models.DateTimeField(auto_now=True) 39 40 createby = models.ForeignKey(User, related_name="test_createby", 41 null=True, blank=True 42 ) 43 lastupdateby = models.ForeignKey(User, related_name="test_lastupdateby", 44 null=True, blank=True 45 ) 46 class Meta: 47 # db_table is optional 48 # db_table = 'PyLucid_test' 49 app_label = 'PyLucid' # must be set to "PyLucid" 27 print "XXX" 28 print TestAlbum._meta.app_label 29 #t = TestAlbum._meta 30 #for i in dir(t): 31 # print i, getattr(t, i) 50 32 51 33 52 print "----------------------------------------------------------------------- -------------------------------"34 print "-----------------------------------------------------------------------" 53 35 try: 54 36 # Here the table doesn't exist 55 m = Musician(first_name = "foo", last_name = "bar", instrument= "foobar")37 m = TestArtist(name = "foobar") 56 38 m.save() 57 39 except Exception, err: 58 40 print err 59 41 60 print "----------------------------------------------------------------------- -------------------------------"42 print "-----------------------------------------------------------------------" 61 43 62 44 def get_create_table(models): … … 72 54 return statements 73 55 74 statements = get_create_table(models = (Musician, Album)) 56 def get_create_table2(*plugin_models): 57 from django.conf import settings 58 from django.core.management.color import no_style 59 style = no_style() 60 from django.core.management import sql 61 from django.db import models 62 63 models.loading.register_models("PyLucidPlugins", *plugin_models) 64 65 # get all delete statements for the given App 66 app = models.get_app("PyLucidPlugins") 67 statements = sql.sql_create(app, style) 68 69 #cleanup 70 app_models = models.loading.cache.app_models 71 del(app_models["PyLucidPlugins"]) 72 # settings.INSTALLED_APPS = old_inst_apps 73 74 return statements 75 76 statements = get_create_table(models = (TestArtist, TestAlbum)) 77 #statements = get_create_table2(TestArtist, TestAlbum) 75 78 76 79 from django.db import connection … … 80 83 cursor.execute(statement) 81 84 82 print "----------------------------------------------------------------------- -------------------------------"85 print "-----------------------------------------------------------------------" 83 86 84 87 # Now we can use the created tables 85 m = Musician(first_name = "foo", last_name = "bar", instrument= "foobar")88 m = TestArtist(name = "foobar") 86 89 m.save() 87 a = Album(90 a = TestAlbum( 88 91 artist = m, 89 92 name = "jup", … … 91 94 ) 92 95 a.save() 93 print Album.objects.all().values()96 print TestAlbum.objects.all().values() 94 97 95 print "----------------------------------------------------------------------- -------------------------------"98 print "-----------------------------------------------------------------------" 96 99 97 100 # Not needed to "insert" the models: 98 101 #from PyLucid.system.PyLucidPlugins import models as PluginModels 99 #PluginModels. Musician = Musician100 #PluginModels. Album =Album102 #PluginModels.TestArtist = TestArtist 103 #PluginModels.TestAlbum = TestAlbum 101 104 102 105 def get_delete_sql(*plugin_models): … … 107 110 from django.db import models 108 111 109 # Insert app in installed apps110 old_inst_apps = settings.INSTALLED_APPS111 inst_apps = list(old_inst_apps)112 inst_apps.append("PyLucid.system.PyLucidPlugins")113 settings.INSTALLED_APPS = inst_apps112 # # Insert app in installed apps 113 # old_inst_apps = settings.INSTALLED_APPS 114 # inst_apps = list(old_inst_apps) 115 # inst_apps.append("PyLucid.system.PyLucidPlugins") 116 # settings.INSTALLED_APPS = inst_apps 114 117 115 118 models.loading.register_models("PyLucidPlugins", *plugin_models) … … 122 125 app_models = models.loading.cache.app_models 123 126 del(app_models["PyLucidPlugins"]) 124 settings.INSTALLED_APPS = old_inst_apps127 # settings.INSTALLED_APPS = old_inst_apps 125 128 126 129 return statements 127 130 128 statements = get_delete_sql( Musician)131 statements = get_delete_sql(TestArtist) 129 132 print "1:", statements 130 133 131 statements = get_delete_sql( Musician,Album)134 statements = get_delete_sql(TestArtist, TestAlbum) 132 135 print "2:", statements 133 136 … … 139 142 140 143 # After this no tables left: 141 statements = get_delete_sql( Musician,Album)144 statements = get_delete_sql(TestArtist, TestAlbum) 142 145 print statements 143 146 144 statements = get_delete_sql( Album)147 statements = get_delete_sql(TestAlbum) 145 148 print statements 146 149 147 print "----------------------------------------------------------------------- -------------------------------"150 print "-----------------------------------------------------------------------" 148 151 149 152 # No tables error: 150 153 try: 151 m = Musician(first_name = "foo", last_name = "bar", instrument= "foobar")154 m = TestArtist(name = "foobar") 152 155 m.save() 153 156 except Exception, err: -
trunk/pylucid/PyLucid/models/Plugin.py
r1609 r1612 19 19 from pprint import pformat 20 20 21 from django.conf import settings 22 21 23 from django.db import models, transaction, connection 22 24 from django.core.cache import cache … … 32 34 preference_cache = {} 33 35 36 PLUGIN_MODEL_LABEL = "PyLucidPlugins" 37 PLUGIN_MODEL_APP = "PyLucid.system.PyLucidPlugins" 38 39 40 def get_plugin_models(package_name, plugin_name, debug=False): 41 """ 42 returns a list of all existing plugin models. 43 If no models exist, returns None! 44 45 Seperated function, because must be accessible from manager- and plugin 46 class, too. 47 """ 48 plugin_module = get_plugin_module(package_name, plugin_name, debug) 49 if not hasattr(plugin_module, "PLUGIN_MODELS"): 50 # Plugin has no models 51 return None 52 53 if not PLUGIN_MODEL_APP in settings.INSTALLED_APPS: 54 from django.core.exceptions import ImproperlyConfigured 55 raise ImproperlyConfigured( 56 "Error '%s' not in settings.INSTALLED_APPS!" % PLUGIN_MODEL_APP 57 ) 58 59 plugin_models = plugin_module.PLUGIN_MODELS 60 61 # Check app_label for every plugin model 62 for model in plugin_models: 63 app_label = model._meta.app_label 64 assert app_label == PLUGIN_MODEL_LABEL, ( 65 "Plugin models must defined in class Meta: app_label = '%s'" 66 ) % PLUGIN_MODEL_LABEL 67 68 return plugin_models 69 70 71 72 73 34 74 class PluginManager(models.Manager): 35 75 """ … … 51 91 plugin = self.get(plugin_name = plugin_name) 52 92 return plugin.get_preferences() 93 94 def get_plugin_models(self, package_name, plugin_name, debug=False): 95 """ returns a list of all existing plugin models or None """ 96 return get_plugin_models(package_name, plugin_name, debug) 97 53 98 54 99 … … 152 197 return get_plugin_version(self.package_name, self.plugin_name, debug) 153 198 199 def get_plugin_models(self, debug=False): 200 """ returns a list of all existing plugin models or None """ 201 return get_plugin_models(self.package_name, self.plugin_name, debug) 202 154 203 #___________________________________________________________________________ 155 204 # SAVE … … 173 222 174 223 def get_delete_sql(self, plugin_models): 175 # from django.conf import settings 224 """ 225 Returns a list of sql statements for deleting the plugin model tabels. 226 For this, we used the fake django app "PyLucidPlugins" and attach 227 all models to this add temporarly. 228 """ 229 from django.core.management import sql 176 230 from django.core.management.color import no_style 177 231 style = no_style() 178 from django.core.management import sql179 232 180 233 models.loading.register_models("PyLucidPlugins", *plugin_models) 181 234 182 # get all delete statements for the given App183 235 app = models.get_app("PyLucidPlugins") 236 184 237 statements = sql.sql_delete(app, style) 185 238 186 print sql.table_list() 187 188 #cleanup 239 # cleanup 189 240 app_models = models.loading.cache.app_models 190 241 del(app_models["PyLucidPlugins"]) 191 # settings.INSTALLED_APPS = old_inst_apps192 242 193 243 return statements 194 244 195 def get_delete_tables(self): 196 plugin_module = get_plugin_module( 197 self.package_name, 198 self.plugin_name, 199 debug=True, 200 ) 201 if not hasattr(plugin_module, "PLUGIN_MODELS"): 245 def _delete_tables(self): 246 """ 247 Delete all plugin model tabels. 248 """ 249 plugin_models = self.get_plugin_models() 250 if not plugin_models: 202 251 # Plugin has no models 203 252 return 204 253 205 plugin_models = plugin_module.PLUGIN_MODELS206 207 254 statements = self.get_delete_sql(plugin_models) 208 255 209 256 cursor = connection.cursor() 210 257 for statement in statements: 211 print repr(statement)258 #print repr(statement) 212 259 cursor.execute(statement) 213 260 … … 215 262 @transaction.commit_on_success 216 263 def delete(self): 217 self. get_delete_tables()264 self._delete_tables() 218 265 219 266 super(Plugin, self).delete() -
trunk/pylucid/PyLucid/system/plugin_manager.py
r1609 r1612 30 30 from django.db.models import Model 31 31 from django.core.management.sql import sql_model_create, \ 32 sql_indexes_for_model, custom_sql_for_model32 sql_indexes_for_model, custom_sql_for_model 33 33 from django.http import HttpResponse, Http404 34 34 … … 36 36 from PyLucid.system.exceptions import * 37 37 from PyLucid.system.plugin_import import get_plugin_module, \ 38 get_plugin_config, get_plugin_version 39 40 38 get_plugin_config, get_plugin_version 41 39 42 40 … … 53 51 ) 54 52 request.page_msg(msg) 55 msg2 = '<i title="(Error details in page messages.)">["%s.%s" error.]</i>' %(56 plugin_name, method_name57 ) 53 msg2 = ( 54 '<i title="(Error details in page messages.)">["%s.%s" error.]</i>' 55 ) % (plugin_name, method_name) 58 56 local_response.write(msg2) 59 57 … … 198 196 199 197 200 def get_create_table( models):198 def get_create_table(plugin_models): 201 199 from django.core.management.color import no_style 202 200 style = no_style() 203 201 204 202 statements = [] 205 for model in models:203 for model in plugin_models: 206 204 statements += sql_model_create(model, style)[0] 207 205 statements += sql_indexes_for_model(model, style) … … 210 208 211 209 212 213 210 def create_plugin_tables(plugin, extra_verbose): 214 plugin_mod ule = get_plugin_module(211 plugin_models = Plugin.objects.get_plugin_models( 215 212 plugin.package_name, 216 213 plugin.plugin_name, 217 214 debug=extra_verbose, 218 215 ) 219 if not hasattr(plugin_module, "PLUGIN_MODELS"):216 if not plugin_models: 220 217 # Plugin has no models 221 if extra_verbose:222 print "Info: No 'plugin_models' list defined, ok."223 218 return 224 225 plugin_models = plugin_module.PLUGIN_MODELS226 219 227 220 statements = get_create_table(plugin_models) 228 221 cursor = connection.cursor() 229 222 for statement in statements: 230 print repr(statement)223 #print repr(statement) 231 224 cursor.execute(statement) 232 225 -
trunk/pylucid/PyLucid/template_addons/lucidTag.py
r1365 r1612 116 116 # method Keywords must be Strings 117 117 key = key.encode(settings.DEFAULT_CHARSET) 118 if value in ("True", "true", "on", "ON", "1"): 118 value_lower = value.lower() 119 if value_lower in ("true", "on"): 119 120 value = True 120 elif value in ("False", "false", "off", "OFF", "0"):121 elif value_lower in ("false", "off"): 121 122 value = False 122 123 method_kwargs[key] = value -
trunk/pylucid/tests/test_plugin_api.py
r1609 r1612 13 13 """ 14 14 15 import os, re 16 15 17 import tests 16 18 … … 18 20 19 21 from PyLucid.models import Page, Plugin 22 from PyLucid.system.plugin_manager import install_plugin 20 23 21 24 22 25 TEST_PLUGIN_NAME = "unittest_plugin" 23 CONTENT_START = ( 24 '<div class="PyLucidPlugins unittest_plugin"' 25 ) 26 CONTENT_END = "</div>" 27 28 29 class PluginAPI_TestCase(tests.TestCase): 26 CONTENT_START = "<pre>" 27 CONTENT_END = "</pre>" 28 CONTENT_RE = re.compile("<pre>(.*?)<\/pre>(?usm)") 29 30 MODEL_TEST = """<pre> 31 Test the plugin models 32 Create TestArtist 33 entry with ID '%(no)s' created 34 Create TestAlbum 35 entry with ID '%(no)s' created: 36 TestAlbum 'A test Album', ID %(no)s, createby: superuser 37 </pre>""" 38 39 40 41 42 class PluginAPI_Base(tests.TestCase): 30 43 """ 31 44 Unit tests for detect_page function. 32 45 """ 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): 60 47 Page.objects.all().delete() # Delete all existins pages 61 48 … … 80 67 self.test_url = self.test_page.get_absolute_url() 81 68 69 #___________________________________________________________________________ 70 # SHARED UTILS 71 82 72 def _get_plugin_content(self, url, debug=False): 83 73 """ 84 74 request the url and returns the plugin content output 85 75 """ 86 print "22222222"87 76 response = self.client.get(url) 88 77 # Check that the respose is 200 Ok. … … 95 84 print "-"*79 96 85 97 lines = raw_content.splitlines() 98 in_content = False 99 result = "" 100 for line in lines: 101 if line.startswith(CONTENT_START): 102 in_content = True 103 continue 104 elif in_content: 105 if line == CONTENT_END: 106 return result 107 else: 108 result += line 86 content = CONTENT_RE.findall(raw_content) 87 if len(content) == 1: 88 return content[0].strip() 109 89 110 90 msg = ( … … 116 96 self.fail(msg) 117 97 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 123 149 url = self.command % "plugin_models" 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() 138 190 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 """ 149 228 def test_lucidTag(self): 150 229 content = self._get_plugin_content(self.test_url) 151 self.assertEqual (content, "args: (), kwargs:{}")230 self.assertEqual2(content, "args:\n()\npformarted kwargs:\n{}") 152 231 153 232 def test_plugin_args1(self): 154 233 """ 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}" 174 271 ) 175 272 … … 181 278 url += "some/stuff/here/1/2/3/" 182 279 content = self._get_plugin_content(url, debug=False) 183 self.assertEqual( 184 content, "args: (u'some/stuff/here/1/2/3/',), kwargs: {}" 280 self.assertEqual2( 281 content, 282 "args:\n" 283 "(u'some/stuff/here/1/2/3/',)\n" 284 "pformarted kwargs:\n" 285 "{}" 185 286 ) 186 287 -
trunk/pylucid/tests/unittest_plugin/unittest_plugin.py
r1609 r1612 17 17 """ 18 18 19 from pprint import pformat 20 19 21 from PyLucid.system.BasePlugin import PyLucidBasePlugin 20 22 … … 34 36 # db_table is optional 35 37 # db_table = 'PyLucid_test' 36 #app_label = 'PyLucidPlugins'37 app_label = 'PyLucid'38 app_label = 'PyLucidPlugins' 39 # app_label = 'PyLucid' 38 40 39 41 class TestAlbum(models.Model): … … 46 48 47 49 createby = models.ForeignKey(User, related_name="test_createby", 48 null=True, blank=True49 )50 lastupdateby = models.ForeignKey(User, related_name="test_lastupdateby",51 50 null=True, blank=True 52 51 ) … … 54 53 # db_table is optional 55 54 # db_table = 'PyLucid_test' 56 #app_label = 'PyLucidPlugins'57 app_label = 'PyLucid'55 app_label = 'PyLucidPlugins' 56 # app_label = 'PyLucid' 58 57 59 58 def __unicode__(self): 60 return u"TestAlbum '%s', ID %s" % (self.name, self.id) 59 return u"TestAlbum '%s', ID %s, createby: %s" % ( 60 self.name, self.id, self.createby 61 ) 61 62 62 63 PLUGIN_MODELS = (TestArtist, TestAlbum) … … 72 73 PyLucid.template_addons.lucidTag 73 74 """ 74 self.response.write("args: %r, kwargs: %r" % (args, kwargs)) 75 self.response.write("<pre>\n") 76 self.response.write("args:\n") 77 self.response.write("%s\n" % pformat(args)) 78 self.response.write("pformarted kwargs:\n") 79 self.response.write("%s\n" % pformat(kwargs)) 80 self.response.write("</pre>") 75 81 76 82 def hello_world(self): … … 90 96 self.response.write("Test the plugin models\n") 91 97 self.response.write("Create TestArtist\n") 92 artist 1= TestArtist(name="A test Artist\n")93 artist 1.save()94 self.response.write("entry with ID '%s' created\n" % artist 1.id)98 artist = TestArtist(name="A test Artist\n") 99 artist.save() 100 self.response.write("entry with ID '%s' created\n" % artist.id) 95 101 self.response.write("Create TestAlbum\n") 96 album 1= TestAlbum(97 artist = artist 1,102 album = TestAlbum( 103 artist = artist, 98 104 name = "A test Album", 99 105 num_stars = 10, 106 createby = self.request.user 100 107 ) 101 album1.save() 102 self.response.write("entry with ID '%s' created\n" % album1.id) 108 album.save() 109 self.response.write("entry with ID '%s' created:\n" % album.id) 110 self.response.write(u"%s\n" % album) 111 self.response.write("</pre>") 112 113 def all_models(self): 114 """ 115 Display all existing models 116 """ 117 self.response.write("<pre>\n") 103 118 self.response.write("All Albums:\n") 104 119 albums = TestAlbum.objects.all() 105 120 for album in albums: 106 121 self.response.write(u"%s: %s\n" % (album.id, album)) 122 123 self.response.write("</pre>") 107 124 108 125 -
trunk/pylucid/tests/unittest_plugin/unittest_plugin_cfg.py
r1609 r1612 65 65 }, 66 66 }, 67 "all_models": { 68 "must_login": True, 69 "must_admin": True, 70 "admin_sub_menu": { 71 "section" : _("unittest"), # The sub menu section 72 "title" : _("all models"), 73 "help_text" : _("Display all existing models"), 74 "open_in_window": False, # Should be create a new JavaScript window? 75 "weight" : 0, # sorting wieght for every section entry 76 }, 77 }, 67 78 } -
trunk/pylucid/tests/__init__.py
r1609 r1612 111 111 112 112 from PyLucid.tools.db_dump import loaddb 113 from PyLucid.tools.Diff import make_diff 113 from PyLucid.tools.Diff import make_diff, diff_lines 114 114 from PyLucid.install.install import DB_DumpFakeOptions 115 115 from PyLucid.models import Page, Style, Template, Plugin … … 190 190 # (relative path here! Because the current work dir can chaned!) 191 191 TEST_PLUGIN_SRC = "tests/unittest_plugin/" 192 TEST_PLUGIN_DST = "PyLucid/plugins_ external/unittest_plugin"192 TEST_PLUGIN_DST = "PyLucid/plugins_internal/unittest_plugin" 193 193 194 194 … … 243 243 if txt in response.content: 244 244 error(response, "Text should not be in response: '%s'" % txt) 245 246 def assertEqual2(self, first, second): 247 """ 248 Same as the original, but display a diff on error. 249 Makes only sence if the string contains more lines (\n) 250 """ 251 if first == second: 252 # is equal, ok 253 return 254 255 error_msg = "Strings not equal:\n" 256 error_msg += "1: %r\n" % first 257 error_msg += "2: %r\n" % second 258 error_msg += "Diff:\n" 259 error_msg += diff_lines(first, second) 260 261 self.fail(error_msg) 245 262 246 263 def assertLists(self, is_list, should_be_list, sort=True): … … 434 451 """ 435 452 initialize the unittest plugin 436 -copy ./tests/unittest_plugin/ into ./PyLucid/plugins_external/ 437 -install+activate the plugin into the database 453 -copy ./tests/unittest_plugin/ into ./PyLucid/plugins_internal/ 454 455 The plugin would be installed in install_internal_plugins() as a normal Plugin. 438 456 """ 439 457 print "initialize the unittest plugin" … … 456 474 raise 457 475 458 # install_plugin(459 # package_name = "PyLucid.plugins_external",460 # plugin_name = "unittest_plugin",461 # debug = True,462 # active=True,463 # extra_verbose=True,464 # )465 476 466 477 … … 576 587 """ 577 588 load_db_dumps(verbosity) 589 init_unittest_plugin() 578 590 install_internal_plugins(verbosity) 579 591 create_users() # Create all test users 580 592 create_pages(TEST_PAGES) # Create the test pages 581 init_unittest_plugin()582 593 create_test_fixture(verbosity) 583 install_plugin( 584 package_name = "PyLucid.plugins_external", 585 plugin_name = "unittest_plugin", 586 debug = True, 587 active=True, 588 extra_verbose=True, 589 ) 594 590 595 591 596 def teardown_pylucid():