Show
Ignore:
Timestamp:
05/31/08 22:01:20 (22 months ago)
Author:
JensDiemer
Message:
  • add a few test for the new plugin models
  • unittest: test plugin would be copied to the normal plugins. So this plugin would be auto installed with all other plugins.
  • Bugfix in lucidTag.py: 1 should not be converted to True ;)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/tests/unittest_plugin/unittest_plugin.py

    r1609 r1612  
    1717""" 
    1818 
     19from pprint import pformat 
     20 
    1921from PyLucid.system.BasePlugin import PyLucidBasePlugin 
    2022 
     
    3436        # db_table is optional 
    3537#        db_table = 'PyLucid_test' 
    36 #        app_label = 'PyLucidPlugins' 
    37         app_label = 'PyLucid' 
     38        app_label = 'PyLucidPlugins' 
     39#        app_label = 'PyLucid' 
    3840 
    3941class TestAlbum(models.Model): 
     
    4648 
    4749    createby = models.ForeignKey(User, related_name="test_createby", 
    48         null=True, blank=True 
    49     ) 
    50     lastupdateby = models.ForeignKey(User, related_name="test_lastupdateby", 
    5150        null=True, blank=True 
    5251    ) 
     
    5453        # db_table is optional 
    5554#        db_table = 'PyLucid_test' 
    56 #        app_label = 'PyLucidPlugins' 
    57         app_label = 'PyLucid' 
     55        app_label = 'PyLucidPlugins' 
     56#        app_label = 'PyLucid' 
    5857 
    5958    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        ) 
    6162 
    6263PLUGIN_MODELS = (TestArtist, TestAlbum) 
     
    7273        PyLucid.template_addons.lucidTag 
    7374        """ 
    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>") 
    7581 
    7682    def hello_world(self): 
     
    9096        self.response.write("Test the plugin models\n") 
    9197        self.response.write("Create TestArtist\n") 
    92         artist1 = TestArtist(name="A test Artist\n") 
    93         artist1.save() 
    94         self.response.write("entry with ID '%s' created\n" % artist1.id) 
     98        artist = TestArtist(name="A test Artist\n") 
     99        artist.save() 
     100        self.response.write("entry with ID '%s' created\n" % artist.id) 
    95101        self.response.write("Create TestAlbum\n") 
    96         album1 = TestAlbum( 
    97             artist = artist1, 
     102        album = TestAlbum( 
     103            artist = artist, 
    98104            name = "A test Album", 
    99105            num_stars = 10, 
     106            createby = self.request.user 
    100107        ) 
    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") 
    103118        self.response.write("All Albums:\n") 
    104119        albums = TestAlbum.objects.all() 
    105120        for album in albums: 
    106121            self.response.write(u"%s: %s\n" % (album.id, album)) 
     122 
     123        self.response.write("</pre>") 
    107124 
    108125