Changeset 1641

Show
Ignore:
Timestamp:
06/13/08 20:01:05 (5 months ago)
Author:
JensDiemer
Message:

solution for http://www.pylucid.org/phpBB2/viewtopic.php?p=1138#1138 & http://pylucid.net:8080/pylucid/ticket/87#comment:3

Files:
1 modified

Legend:

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

    r1634 r1641  
    4444    install_url_base ="/%s" % settings.INSTALL_URL_PREFIX 
    4545 
    46     def setUp(self): 
    47         settings.DEBUG = True 
    48  
    49     def test_prepare(self): 
    50         """ 
    51         Check if there is no page. 
    52         """ 
    53         self.failUnlessEqual(Page.objects.all().count(), 0) 
    54  
    5546 
    5647class TestNoPage(TestBase): 
     
    7465        return response 
    7566 
     67    def test_no_page(self): 
     68        """ 
     69        Check if there is no page. 
     70        """ 
     71        self.failUnlessEqual(Page.objects.all().count(), 0) 
     72 
    7673    def test_page_request(self): 
    7774        """ 
     
    191188 
    192189 
    193 class TestMiddlewares:#(TestBase): #DEACTIVATED! 
     190class TestMiddlewares(TestBase): 
    194191    """ 
    195192    Test the PyLucid common middleware. 
     
    198195    page with some informations. 
    199196 
    200     FIXME: How we can delete the tables? 
     197    TODO: Should we find a faster was to run the test without existing database 
     198    tables? 
    201199    See: http://pylucid.org/phpBB2/viewtopic.php?p=1138#1138 
    202200 
     
    205203    This messages comes from ./django/core/management/commands/flush.py 
    206204    """ 
    207     def _rename_tables(self, old_prefix, new_prefix): 
     205    fixtures = [] # Run all test with a empty database 
     206 
     207    def _drop_all_tables(self): 
     208#        print "drop all tables...", 
    208209        from django.db import connection 
    209         from django.core.management.sql import table_list 
     210        from django.core.management.sql import table_names 
    210211 
    211212        cursor = connection.cursor() 
    212         for table_name in table_list(): 
    213             statement = ( 
    214                 "ALTER TABLE %(old_prefix)s%(name)s" 
    215                 " RENAME TO %(new_prefix)s%(name)s;" 
    216             ) % { 
    217                 "old_prefix": old_prefix, 
    218                 "new_prefix": new_prefix, 
    219                 "name": table_name, 
    220             } 
     213        for table_name in table_names(): 
     214            statement = u"DROP TABLE %s;" % table_name 
    221215            cursor.execute(statement) 
     216#        print "done" 
     217 
     218    def _syncdb(self): 
     219#        print "syncdb...", 
     220        from django.core.management import call_command 
     221        call_command('syncdb', verbosity=0, interactive=False) 
     222#        print "done." 
    222223 
    223224    def setUp(self): 
    224         self._rename_tables(old_prefix="", new_prefix="old_") 
    225  
     225        self._drop_all_tables() 
     226# 
    226227    def tearDown(self): 
    227         self._rename_tables(old_prefix="old_", new_prefix="") 
     228        self._syncdb() 
    228229 
    229230    def test(self): 
     
    235236        self.assertResponse(response, 
    236237            must_contain=( 
    237                 #"Can't get a database table", 
     238                "Can't get a database table.", 
    238239                "solutions", "Please read the install guide", 
    239240            ), 
    240             #must_not_contain=("Error getting a cms page",) 
     241            must_not_contain=("Error getting a cms page",) 
    241242        ) 
    242243 
    243244    def test_install_section(self): 
    244245        """ 
    245         Request the install section login. Without any database table, we should 
    246         be see the install secion login page. 
    247         """ 
    248         self.assertInstallSectionLogin() 
     246        Request the install section login. Without any database table, we 
     247        should be see the install secion login page. 
     248        """ 
     249#        self.assertInstallSectionLogin() 
     250        url = self.install_url_base 
     251        response = self.client.get(url) 
     252        self.failUnlessEqual(response.status_code, 200) 
     253        self.assertResponse( 
     254            response, 
     255            must_contain=("Login into the _install section",), 
     256        ) 
    249257 
    250258