Changeset 1593

Show
Ignore:
Timestamp:
05/26/08 16:35:14 (13 months ago)
Author:
JensDiemer
Message:

unittests: add a test plugin...

Location:
trunk/pylucid/tests
Files:
5 added
1 modified

Legend:

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

    r1592 r1593  
    8989""" 
    9090 
    91 import sys 
    9291import os 
    9392import re 
     93import sys 
     94import pprint 
     95import shutil 
    9496import tempfile 
    9597import unittest 
    96 import pprint 
    97  
    9898from StringIO import StringIO 
    9999 
     
    104104 
    105105from django.conf import settings 
    106 from PyLucid.install.install import DB_DumpFakeOptions 
     106 
     107from django.contrib.auth.models import User, UNUSABLE_PASSWORD 
     108from django.test import TestCase as DjangoTestCase 
     109 
     110from tests.utils.BrowserDebug import debug_response 
     111 
    107112from PyLucid.tools.db_dump import loaddb 
    108113from PyLucid.tools.Diff import make_diff 
    109 from tests.utils.BrowserDebug import debug_response 
    110  
     114from PyLucid.install.install import DB_DumpFakeOptions 
    111115from PyLucid.models import Page, Style, Template, Plugin 
    112 from django.contrib.auth.models import User, UNUSABLE_PASSWORD 
    113 from django.test import TestCase as DjangoTestCase 
     116from PyLucid.system.plugin_manager import auto_install_plugins, install_plugin 
     117 
    114118 
    115119# Display invalid (e.g. misspelled, unused) template variables 
     
    183187FIXTURE_FILE = tempfile.NamedTemporaryFile(prefix='PyLucid_',suffix='.json') 
    184188 
     189# unittest plugin paths 
     190# (relative path here! Because the current work dir can chaned!) 
     191TEST_PLUGIN_SRC = "tests/unittest_plugin/" 
     192TEST_PLUGIN_DST = "PyLucid/plugins_external/unittest_plugin" 
     193 
     194 
    185195def change_preferences(plugin_name, **kwargs): 
    186196    """ 
     
    416426    """ 
    417427    print "Installing PyLucid internal plugins ", 
    418     from PyLucid.system.plugin_manager import auto_install_plugins 
    419  
    420428    auto_install_plugins(debug=True, extra_verbose=extra_verbose) 
    421429    print "" 
     430 
     431 
     432 
     433def init_unittest_plugin(): 
     434    """ 
     435    initialize the unittest plugin 
     436    -copy ./tests/unittest_plugin/ into ./PyLucid/plugins_external/ 
     437    -install+activate the plugin into the database 
     438    """ 
     439    print "initialize the unittest plugin" 
     440    print "copy %s to %s" % (TEST_PLUGIN_SRC, TEST_PLUGIN_DST) 
     441    try: 
     442        shutil.copytree( 
     443            os.path.abspath(TEST_PLUGIN_SRC), os.path.abspath(TEST_PLUGIN_DST) 
     444        ) 
     445    except OSError, err: 
     446        import errno 
     447        if err.errno == errno.EEXIST: # [Errno 17] File exists 
     448            # A prior unittest run aborted? 
     449            print "Info:", err 
     450        else: 
     451            print "os.getcwd():", os.getcwd() 
     452            raise 
     453 
     454    install_plugin( 
     455        package_name = "PyLucid.plugins_external", 
     456        plugin_name = "unittest_plugin", 
     457        debug = True, 
     458        active=True, 
     459        extra_verbose=True, 
     460    ) 
     461 
     462 
     463def remove_unittest_plugin(): 
     464    print "remove unittest plugin (%s)" % TEST_PLUGIN_DST 
     465    shutil.rmtree(os.path.abspath(TEST_PLUGIN_DST)) 
     466 
    422467 
    423468def create_user(username, password, email, is_staff, is_superuser): 
     
    472517 
    473518 
    474 def create_page(data): 
    475     """ 
    476     Creates Page object with given data. 
     519def create_page(**kwargs): 
     520    """ 
     521    Creates Page object with given kwargs. 
    477522    """ 
    478523    default_user = User.objects.get( 
     
    484529 
    485530    page = Page( 
    486         name             = data.get("name", "New Page"), 
    487         shortcut         = data.get("shortcut", None), 
    488         content          = data.get("content", "TestPageContent"), 
    489         template         = data.get("template", default_template), 
    490         style            = data.get("style", default_style), 
    491         markup           = data.get("markup", default_markup), 
    492         createby         = data.get("user", default_user), 
    493         lastupdateby     = data.get("user", default_user), 
    494         showlinks        = data.get("showlinks", True), 
    495         permitViewPublic = data.get("permitViewPublic", True), 
    496         permitViewGroup  = data.get("permitViewGroup", None), 
    497         permitEditGroup  = data.get("permitEditGroup", None), 
    498         parent           = data.get("parent", None), 
     531        name             = kwargs.get("name", "New Page"), 
     532        shortcut         = kwargs.get("shortcut", None), 
     533        content          = kwargs.get("content", "TestPageContent"), 
     534        template         = kwargs.get("template", default_template), 
     535        style            = kwargs.get("style", default_style), 
     536        markup           = kwargs.get("markup", default_markup), 
     537        createby         = kwargs.get("user", default_user), 
     538        lastupdateby     = kwargs.get("user", default_user), 
     539        showlinks        = kwargs.get("showlinks", True), 
     540        permitViewPublic = kwargs.get("permitViewPublic", True), 
     541        permitViewGroup  = kwargs.get("permitViewGroup", None), 
     542        permitEditGroup  = kwargs.get("permitEditGroup", None), 
     543        parent           = kwargs.get("parent", None), 
    499544        ) 
    500545    page.save() 
     
    509554        page_data.update(kwargs) 
    510555        page_data["parent"] = parent 
    511         last_page = create_page(page_data) 
     556        last_page = create_page(**page_data) 
    512557        if "subitems" in page_data: 
    513558            create_pages( 
     
    530575    create_users() # Create all test users 
    531576    create_pages(TEST_PAGES) # Create the test pages 
     577    init_unittest_plugin() 
    532578    create_test_fixture(verbosity) 
     579 
     580def teardown_pylucid(): 
     581    """ 
     582    cleanup 
     583    """ 
     584    remove_unittest_plugin() 
    533585 
    534586def _import_test(module_name,class_name=None): 
     
    626678    destroy_test_db(old_name, verbosity) 
    627679    teardown_test_environment() 
     680    teardown_pylucid() 
    628681 
    629682    return len(result.failures) + len(result.errors)