コード例 #1
0
ファイル: test_portal.py プロジェクト: nive-cms/nive
class portalTest(unittest.TestCase):
    def setUp(self):
        self.portal = Portal()
        self.app = testapp(mApp2)

    def tearDown(self):
        pass

    def test_register(self):
        self.portal.Register(mApp)
        self.portal.Register(self.app, "another")
        self.portal.Register("nive.tests.test_nive.mApp2")
        self.assertRaises(ImportError, self.portal.Register,
                          "nive.tests.test_nive.mApp56875854")
        self.assertRaises(ConfigurationError, self.portal.Register, time)

    def test_portal(self):
        self.portal.Register(mApp2)
        self.portal.Register(self.app, "nive")
        self.portal.RegisterGroups(self.app)
        self.assert_(self.portal.__getitem__("app2"))
        self.assert_(self.portal.__getitem__("nive"))
        try:
            self.portal.Startup(None)
        except OperationalError:
            pass
        self.assert_(len(self.portal.GetApps()) == 2)
        self.assert_(self.portal.GetGroups(sort=u"id", visibleOnly=False))
        self.assert_(self.portal.GetGroups(sort=u"name", visibleOnly=True))
        self.assert_(self.portal.portal)

    def test_portal2(self):
        self.portal.StartConnection(Event())
        self.portal.FinishConnection(Event())
コード例 #2
0
ファイル: db_app.py プロジェクト: comlorda/nive
def app_db(modules=None):
    a = ApplicationBase()
    a.Register(appconf)
    if modules:
        for m in modules:
            a.Register(m)
    p = Portal()
    p.Register(a, "nive")
    a.SetupApplication()
    dbfile = DvPath(a.dbConfiguration.dbName)
    if not dbfile.IsFile():
        dbfile.CreateDirectories()
    root = DvPath(a.dbConfiguration.fileRoot)
    if not root.IsDirectory():
        root.CreateDirectories()

    try:
        a.Query("select id from pool_meta where id=1")
        a.Query("select id from data1 where id=1")
        a.Query("select id from data2 where id=1")
        a.Query("select id from data3 where id=1")
        a.Query("select id from pool_files where id=1")
        a.Query("select id from pool_sys where id=1")
        a.Query("select id from pool_groups where id=1")
        a.Query("select title from pool_meta where id=1")
    except:
        a.GetTool("nive.tools.dbStructureUpdater")()

    # disable this to update test tables each time the tests are called
    #a.GetTool("nive.tools.dbStructureUpdater")()
    a.Startup(None)
    # this will reset all testdata
    #emptypool(a)
    return a
コード例 #3
0
class tViews(unittest.TestCase):

    def setUp(self):
        request = testing.DummyRequest()
        request._LOCALE_ = "en"
        self.request = request
        self.config = testing.setUp(request=request)
        self.app = app_db()
        self.portal = Portal()
        self.portal.Register(self.app, "nive")
        self.app.Register(view.configuration)
        self.app.Register(view.dbAdminConfiguration)
        self.app.Register("nive.cms.cmsview")
        self.app.Startup(self.config)
        self.request.context = self.app
    

    def tearDown(self):
        self.app.Close()
        testing.tearDown()


    def test_basics(self):
        v = view.AdminBasics(context=self.app, request=self.request)
        self.assert_(v.GetAdminWidgets())
        self.assert_(v.RenderConf(view.configuration))
        self.assert_(v.RenderConf(view.dbAdminConfiguration))
        self.assert_(v.Format(view.configuration, view.configuration.id))
        self.assert_(v.Format(view.dbAdminConfiguration, view.configuration.id))
        self.assert_(v.AdministrationLinks(context=None))
        self.assert_(v.AdministrationLinks(context=self.app))


    def test_views(self):
        v = view.AdminView(context=self.app, request=self.request)
        v.view()
        self.assert_(v.index_tmpl())
        self.assert_(v.editbasics())
        self.assert_(v.editdatabase())
        self.assert_(v.editportal())
        self.assert_(v.tools())
        v.doc()


    def test_form(self):
        v = view.AdminBasics(context=self.app, request=self.request)
        form = view.ConfigurationForm(context=view.configuration, request=self.request, view=v, app=self.app)
        form.fields = (
            FieldConf(id=u"title",           datatype="string", size=255,  required=0, name=u"Application title"),
            FieldConf(id=u"description",     datatype="text",   size=5000, required=0, name=u"Application description"),
            FieldConf(id=u"workflowEnabled", datatype="bool",   size=2,    required=0, name=u"Enable workflow engine"),
            FieldConf(id=u"fulltextIndex",   datatype="bool",   size=2,    required=0, name=u"Enable fulltext index"),
            FieldConf(id=u"frontendCodepage",datatype="string", size=10,   required=1, name=u"Codepage used in html frontend"),
        )
        form.Setup()
        self.request.POST = {"name": "testuser", "email": "*****@*****.**"}
        self.request.GET = {}

        self.assert_(form.Start(None))
        self.assert_(form.Update(None))
コード例 #4
0
ファイル: test_application.py プロジェクト: comlorda/nive
def app():
    app = testapp()
    app.Register(mApp2)
    app.Startup(None)
    portal = Portal()
    portal.Register(app, "nive")
    return app
コード例 #5
0
ファイル: db_app.py プロジェクト: comlorda/nive_datastore
def app_nodb():
    a = DataStorage()
    a.Register(appconf)
    a.Register(DatabaseConf())
    p = Portal()
    p.Register(a)
    #a.Startup(None)
    return a
コード例 #6
0
def app_nodb():
    a = WebsitePublisher()
    a.Register(appconf)
    a.Register(DatabaseConf())
    p = Portal()
    p.Register(a)
    #a.Startup(None)
    return a
コード例 #7
0
def app_nodb():
    appconf = AppConf("nive.userdb.app")
    appconf.modules.append("nive.userdb.userview.view")
    appconf.modules.append("nive.components.tools.sendMail")

    a = UserDB(appconf)
    a.dbConfiguration = DatabaseConf()
    p = Portal()
    p.Register(a)
    a.Startup(None)
    return a
コード例 #8
0
ファイル: db_app.py プロジェクト: comlorda/nive
def app_nodb():
    a = ApplicationBase()
    a.Register(appconf)
    a.Register(DatabaseConf())
    p = Portal()
    p.Register(a, "nive")
    a.SetupApplication()
    try:
        a.Startup(None)
    except OperationalError:
        pass
    return a
コード例 #9
0
 def test_app(self):
     
     appconf = AppConf("nive.userdb.app")
     #appconf.modules.append("nive.components.extensions.sessionuser")
     
     app = UserDB(appconf)
     app.dbConfiguration=db_app.dbconf
     p = Portal()
     p.Register(app)
     app.Startup(None)
     
     self.assert_(app.usercache)
     
     self.assert_(app.root())
コード例 #10
0
ファイル: test_portal.py プロジェクト: comlorda/nive
class portalTest(unittest.TestCase):
    
    def setUp(self):
        self.request = testing.DummyRequest()
        self.config = testing.setUp(request=self.request)
        self.portal = Portal()
        self.app = testapp(mApp2)

    def tearDown(self):
        pass


    def test_register(self):
        self.portal.Register(mApp)
        self.portal.Register(self.app, "another")
        self.portal.Register("nive.tests.test_application.mApp2")
        self.assertRaises(ImportError, self.portal.Register, "nive.tests.test_application.mApp56875854")
        self.assertRaises(ConfigurationError, self.portal.Register, time)

    def test_module(self):
        testconf = ModuleConf(
            id = "module",
            name = "Module",
            context = "nive.tests.test_portal.DummyClass1",
            extensions = (DummyClass2,),
            events = None,
            description = ""
        )
        self.portal.Register(testconf, "test")
        m=self.portal["test"]
        self.assert_(self.portal["test"].hello()=="hello")

    def test_portal(self):
        self.portal.Register(mApp2)
        self.portal.Register(self.app, "nive")
        self.portal.RegisterGroups(self.app)
        self.assert_(self.portal.__getitem__("app2"))
        self.assert_(self.portal.__getitem__("nive"))
        try:
            self.portal.Startup(None)
        except OperationalError:
            pass
        self.assert_(len(self.portal.GetApps())==2)
        self.assert_(self.portal.GetGroups(sort=u"id", visibleOnly=False))
        self.assert_(self.portal.GetGroups(sort=u"name", visibleOnly=True))
        self.assert_(self.portal.portal)


    def test_portal2(self):
        self.portal.StartConnection(Event(self.request))
        self.portal.FinishConnection(Event(self.request))
コード例 #11
0
ファイル: db_app.py プロジェクト: comlorda/nive_datastore
def app_db(confs=None):
    a = DataStorage()
    a.Register(appconf)
    if confs:
        for c in confs:
            a.Register(c)
    p = Portal()
    p.Register(a)
    a.Startup(None)
    dbfile = DvPath(a.dbConfiguration.dbName)
    if not dbfile.IsFile():
        dbfile.CreateDirectories()
    try:
        a.Query("select id from pool_meta where id=1")
        a.Query("select pool_wfp from pool_meta where id=1")
        a.Query("select id from bookmarks where id=1")
        a.Query("select id from tracks where id=1")
        a.Query("select id from pool_files where id=1")
    except:
        a.GetTool("nive.tools.dbStructureUpdater")()
    return a
コード例 #12
0
def app(confs=[]):
    a = WebsitePublisher()
    a.Register(appconf)
    a.Register(dbconf)
    for c in confs:
        a.Register(c)
    p = Portal()
    p.Register(a)
    a.Startup(None)
    dbfile = DvPath(a.dbConfiguration.dbName)
    if not dbfile.IsFile():
        dbfile.CreateDirectories()
    try:
        a.Query("select id from pool_meta where id=1")
        a.Query("select id from data1 where id=1")
        a.Query("select id from data2 where id=1")
        a.Query("select id from data3 where id=1")
        a.Query("select id from pool_files where id=1")
    except:
        a.GetTool("nive.components.tools.dbStructureUpdater")()
    return a
コード例 #13
0
def app(extmodules=None):
    appconf = AppConf("nive.userdb.app")
    appconf.modules.append("nive.userdb.userview.view")
    appconf.modules.append("nive.components.tools.sendMail")

    a = UserDB(appconf)
    a.dbConfiguration = dbconf
    p = Portal()
    p.Register(a)
    a.Startup(None)
    dbfile = DvPath(a.dbConfiguration.dbName)
    if not dbfile.IsFile():
        dbfile.CreateDirectories()
    try:
        a.Query("select id from pool_meta where id=1")
        a.Query("select id from data1 where id=1")
        a.Query("select id from data2 where id=1")
        a.Query("select id from data3 where id=1")
        a.Query("select id from pool_files where id=1")
    except:
        a.GetTool("nive.components.tools.dbStructureUpdater")()
    return a
コード例 #14
0
ファイル: db_app.py プロジェクト: timgates42/nive_cms
def app_db(confs=None):
    appconf = AppConf("nive_cms.app")
    a = WebsitePublisher()
    a.Register(appconf)
    if confs:
        for c in confs:
            a.Register(c)
    p = Portal()
    p.Register(a)
    a.Startup(None)
    dbfile = DvPath(a.dbConfiguration.dbName)
    if not dbfile.IsFile():
        dbfile.CreateDirectories()
    try:
        a.Query("select id from pool_meta where id=1")
        a.Query("select id from box where id=1")
        a.Query("select id from columnbox where id=1")
        a.Query("select id from texts where id=1")
        a.Query("select id from pool_files where id=1")
    except:
        a.GetTool("nive.tools.dbStructureUpdater")()
    return a
コード例 #15
0
class tTemplates(unittest.TestCase):

    def setUp(self):
        request = testing.DummyRequest()
        request._LOCALE_ = "en"
        self.request = request
        self.config = testing.setUp(request=request)
        self.app = app_db()
        self.portal = Portal()
        self.portal.Register(self.app, "nive")
        self.app.Register(view.configuration)
        self.app.Register(view.dbAdminConfiguration)
        self.app.Register("nive.cms.cmsview")
        self.app.Startup(self.config)
        self.request.context = self.app

    def tearDown(self):
        self.app.Close()
        testing.tearDown()

    def test_templates(self):
        v = view.AdminView(context=self.app, request=self.request)
        vrender = {"context":self.app, "view":v, "request": self.request}

        values = v.editbasics()
        values.update(vrender)
        render("nive.adminview:form.pt", values)
        
        values = v.tools()
        values.update(vrender)
        render("nive.adminview:tools.pt", values)
        
        render("nive.adminview:modules.pt", vrender)
        render("nive.adminview:root.pt", vrender)
        render("nive.adminview:views.pt", vrender)
        render("nive.adminview:help.pt", values)
コード例 #16
0
ファイル: db_app.py プロジェクト: comlorda/nive_userdb
def app_db(confs=None):
    appconf = AppConf("nive_userdb.app")
    appconf.modules.append("nive_userdb.userview.view")
    appconf.modules.append("nive.tools.sendMailTester")
    a = UserDB()
    a.Register(appconf)
    if confs:
        for c in confs:
            a.Register(c)
    p = Portal()
    p.Register(a)
    a.Startup(None)
    dbfile = DvPath(a.dbConfiguration.dbName)
    if not dbfile.IsFile():
        dbfile.CreateDirectories()
    try:
        a.Query("select id from pool_meta where id=1")
        a.Query("select id from users where id=1")
        a.Query("select id from users where token='1'")
        a.Query("select id from users where tempcache='1'")
        a.Query("select id from pool_files where id=1")
    except:
        a.GetTool("nive.tools.dbStructureUpdater")()
    return a
コード例 #17
0
ファイル: test_application.py プロジェクト: comlorda/nive
class appTest(unittest.TestCase):
    
    def setUp(self):
        self.app = testapp()
        self.app.Register(mApp2)
        self.portal = Portal()
        self.portal.Register(self.app, "nive")
        self.app.Startup(None)

    def tearDown(self):
        pass


    def test_include2(self):
        s = self.app._structure.structure
        self.assert_("pool_meta" in s)
        self.assert_("object" in s)
        self.assert_(len(s["pool_meta"])>10)
        self.assert_(len(s["object"])==2)
        pass


    def test_fncs(self):
        self.assert_(self.app.GetVersion())
        self.assert_(self.app.CheckVersion())
        self.assert_(self.app.GetApp())
        

    def test_del(self):
        self.app.__del__()
        
    def test_getitem(self):
        self.assert_(self.app["root"])
        try:
            self.app["no_root"]
            self.assert_(False)
        except KeyError:
            pass
        conf=self.app.root().configuration
        conf.unlock()
        conf.urlTraversal=False
        conf.lock()
        try:
            self.app["root"]
            conf.unlock()
            conf.urlTraversal=True
            conf.lock()
            self.assert_(False)
        except KeyError:
            conf.unlock()
            conf.urlTraversal=True
            conf.lock()
            pass
        
    def test_props(self):
        self.assert_(self.app.root())
        self.assert_(self.app.portal)
        self.assert_(self.app.db)
        self.assert_(self.app.app)
    
    def test_roots(self):
        self.assert_(self.app.root(name=""))
        self.assert_(self.app.root(name="root"))
        self.assert_(self.app.root(name="aaaaaaaa")==None)

        self.assert_(self.app.__getitem__("root"))
        self.assert_(self.app.GetRoot(name="root"))
        self.assert_(len(self.app.GetRoots())==1)

    def test_tools(self):
        self.assert_(self.app.GetTool("tool"))
        self.assert_(self.app.GetTool("nive.tools.example"))
        self.assertRaises(ImportError, self.app.GetTool, ("no_tool"))
        self.assertRaises(ImportError, self.app.GetTool, (""))

    def test_wfs(self):
        self.assertFalse(self.app.GetWorkflow(""))
        self.assertFalse(self.app.GetWorkflow("no_wf"))
        self.assertFalse(self.app.GetWorkflow("wfexample"))
        self.app.configuration.unlock()
        self.app.configuration.workflowEnabled = True
        self.assert_(self.app.GetWorkflow("nive.tests.test_workflow.wf1"))
        self.app.configuration.workflowEnabled = False
        self.app.configuration.lock()

    def test_confs(self):
        self.assert_(self.app.QueryConf(IRootConf))
        self.assert_(self.app.QueryConf("nive.definitions.IRootConf"))
        self.assert_(self.app.QueryConf(IToolConf, _GlobalObject()))
        self.assertFalse(self.app.QueryConf("nive.definitions.no_conf"))
        
        self.assert_(self.app.QueryConfByName(IRootConf, "root"))
        self.assert_(self.app.QueryConfByName("nive.definitions.IRootConf", "root"))
        self.assert_(self.app.QueryConfByName(IToolConf, "tool", _GlobalObject()))
        self.assertFalse(self.app.QueryConfByName("nive.definitions.no_conf", "root"))

        self.assert_(self.app.Factory(IRootConf, "root"))
        self.assert_(self.app.Factory("nive.definitions.IRootConf", "root"))
        self.assert_(self.app.Factory(IToolConf, "tool", _GlobalObject()))
        self.assertFalse(self.app.Factory("nive.definitions.no_conf", "root"))
        
    def test_rootconfs(self):
        self.assert_(self.app.GetRootConf(name=""))
        self.assert_(self.app.GetRootConf(name="root"))
        self.assert_(len(self.app.GetAllRootConfs()))
        self.assert_(len(self.app.GetRootIds())==1)
        self.assert_(self.app.GetDefaultRootName()=="root")

    def test_objconfs(self):
        self.assert_(self.app.GetObjectConf("object", skipRoot=False))
        self.assert_(self.app.GetObjectConf("root", skipRoot=True)==None)
        self.assert_(self.app.GetObjectConf("oooooh", skipRoot=False)==None)
        self.assert_(len(self.app.GetAllObjectConfs(visibleOnly = False))==1)
        self.assert_(self.app.GetTypeName("object")=="Object")

    def test_toolconfs(self):
        self.assert_(self.app.GetToolConf("tool"))
        self.assert_(len(self.app.GetAllToolConfs()))
        
    def test_categoriesconf(self):
        self.assert_(self.app.GetCategory(categoryID = "c1"))
        self.assert_(len(self.app.GetAllCategories(sort=u"name", visibleOnly=False))==1)
        self.assert_(self.app.GetCategoryName("c1")=="C1")
        self.assert_(self.app.GetCategoryName("no_cat")=="")

    def test_groups(self):
        self.assert_(self.app.GetGroups(sort=u"name", visibleOnly=False))
        self.assert_(self.app.GetGroups(sort=u"name", visibleOnly=True))
        self.assert_(self.app.GetGroups(sort=u"id", visibleOnly=False))
        self.assert_(self.app.GetGroupName("g1")=="G1")
        self.assert_(self.app.GetGroupName("no_group")=="")

    def test_flds(self):
        self.assert_(self.app.GetFld("pool_type", typeID = None))
        self.assert_(self.app.GetFld("aaaaa", typeID = None)==None)
        self.assert_(self.app.GetFld("pool_stag", typeID = "object"))
        self.assert_(self.app.GetFld("a1", typeID = "object"))
        self.assert_(self.app.GetFld("a1", typeID = None)==None)
        self.assert_(self.app.GetFld("a2", typeID = "object"))
        self.assert_(self.app.GetFld("a2", typeID = "ooooo")==None)
        self.assert_(self.app.GetFld("ooooo", typeID = "object")==None)
        
        self.assert_(self.app.GetFldName("a2", typeID = "object")=="A2")
        self.assert_(self.app.GetObjectFld("a1", "object"))
        self.assert_(len(self.app.GetAllObjectFlds("object"))==2)
        self.assert_(self.app.GetMetaFld("pool_type"))
        self.assert_(len(self.app.GetAllMetaFlds(ignoreSystem = True)))
        self.assert_(len(self.app.GetAllMetaFlds(ignoreSystem = False)))
        self.assert_(self.app.GetMetaFldName("pool_type")=="Type")
        self.assert_(self.app.GetMetaFldName("no_field")=="")
        
    def test_flds_conf(self):
        self.assert_(self.app.GetFld(FieldConf(id="pool_type"), typeID = None))
        self.assert_(self.app.GetFld(FieldConf(id="aaaaa"), typeID = None)==None)
        self.assert_(self.app.GetFld(FieldConf(id="pool_stag"), typeID = "object"))
        self.assert_(self.app.GetFld(FieldConf(id="a1"), typeID = "object"))
        self.assert_(self.app.GetFld(FieldConf(id="a1"), typeID = None)==None)
        self.assert_(self.app.GetFld(FieldConf(id="a2"), typeID = "object"))
        self.assert_(self.app.GetFld(FieldConf(id="a2"), typeID = "ooooo")==None)
        self.assert_(self.app.GetFld(FieldConf(id="ooooo"), typeID = "object")==None)

        self.assert_(self.app.GetObjectFld(FieldConf(id="a1"), "object"))
        self.assert_(self.app.GetMetaFld(FieldConf(id="pool_type")))

    def test_structure(self):
        self.app._LoadStructure(forceReload = False)
        self.assert_(self.app._structure)
        self.app._LoadStructure(forceReload = True)
        self.assert_(self.app._structure)

    def test_factory(self):
        self.assert_(self.app._GetDataPoolObj())
        self.assert_(self.app._GetRootObj("root"))
        self.app._CloseRootObj(name="root")
        self.assert_(self.app._GetRootObj("root"))
        self.assert_(self.app._GetToolObj("nive.tools.example", None))
コード例 #18
0
ファイル: test_nive.py プロジェクト: nive-cms/nive
class appTest(unittest.TestCase):
    
    def setUp(self):
        self.app = testapp()
        self.app.Register(mApp2)
        self.app.Register(dbConfiguration2)
        self.portal = Portal()
        self.portal.Register(self.app, "nive")
        self.app.Startup(None)

    def tearDown(self):
        pass


    def test_include2(self):
        s = self.app._structure.structure
        self.assert_("pool_meta" in s)
        self.assert_("object" in s)
        self.assert_(len(s["pool_meta"])>10)
        self.assert_(len(s["object"])==2)
        pass


    def test_fncs(self):
        self.assert_(self.app.GetVersion())
        self.assert_(self.app.CheckVersion())
        

    def test_objs(self):
        self.assert_(self.app.root(name=""))
        self.assert_(self.app.root(name="root"))
        self.assert_(self.app.root(name="aaaaaaaa")==None)
        #self.assert_(self.app.portal)
        self.assert_(self.app.__getitem__("root"))
        self.assert_(self.app.GetRoot(name="root"))
        self.assert_(len(self.app.GetRoots())==1)
        self.assert_(self.app.GetApp())
        #self.assert_(self.app.portal)
        self.assert_(self.app.GetTool("nive.components.tools.example"))
        #!!! self.app.GetWorkflow(wfProcID)

    def test_confs(self):
        self.assert_(self.app.GetRootConf(name=""))
        self.assert_(self.app.GetRootConf(name="root"))
        self.assert_(len(self.app.GetAllRootConfs()))
        self.assert_(len(self.app.GetRootIds())==1)
        self.assert_(self.app.GetDefaultRootName()=="root")

    def test_confs2(self):
        self.assert_(self.app.GetObjectConf("object", skipRoot=False))
        self.assert_(self.app.GetObjectConf("root", skipRoot=True)==None)
        self.assert_(self.app.GetObjectConf("oooooh", skipRoot=False)==None)
        self.assert_(len(self.app.GetAllObjectConfs(visibleOnly = False))==1)
        self.assert_(self.app.GetTypeName("object")=="Object")

    def test_confs3(self):
        self.assert_(self.app.GetToolConf("tool"))
        self.assert_(len(self.app.GetAllToolConfs()))
        
    def test_confs4(self):
        self.assert_(self.app.GetCategory(categoryID = "c1"))
        self.assert_(len(self.app.GetAllCategories(sort=u"name", visibleOnly=False))==1)
        self.assert_(self.app.GetCategoryName("c1")=="C1")
        self.assert_(self.app.GetGroups(sort=u"name", visibleOnly=False))
        self.assert_(self.app.GetGroupName("g1")=="G1")

    def test_flds(self):
        self.assert_(self.app.GetFld("title", typeID = None))
        self.assert_(self.app.GetFld("aaaaa", typeID = None)==None)
        self.assert_(self.app.GetFld("pool_stag", typeID = "object"))
        self.assert_(self.app.GetFld("a1", typeID = "object"))
        self.assert_(self.app.GetFld("a1", typeID = None)==None)
        self.assert_(self.app.GetFld("a2", typeID = "object"))
        self.assert_(self.app.GetFld("a2", typeID = "ooooo")==None)
        self.assert_(self.app.GetFld("ooooo", typeID = "object")==None)
        
        self.assert_(self.app.GetFldName("a2", typeID = "object")=="A2")
        self.assert_(self.app.GetObjectFld("a1", "object"))
        self.assert_(len(self.app.GetAllObjectFlds("object"))==2)
        self.assert_(self.app.GetMetaFld("title"))
        self.assert_(len(self.app.GetAllMetaFlds(ignoreSystem = True)))
        self.assert_(len(self.app.GetAllMetaFlds(ignoreSystem = False)))
        self.assert_(self.app.GetMetaFldName("title")=="Title")
        
    def test_flds2(self):    
        self.app.LoadStructure(forceReload = False)
        self.assert_(self.app._structure)
        self.app.LoadStructure(forceReload = True)
        self.assert_(self.app._structure)

    def test_flds4(self):    
        self.assert_(self.app._GetDataPoolObj())
        self.assert_(self.app._GetRootObj("root"))
        self.app._CloseRootObj(name="root")
        self.assert_(self.app._GetRootObj("root"))
        self.assert_(self.app._GetToolObj("nive.components.tools.example", None))
コード例 #19
0
ファイル: test_views.py プロジェクト: nive-cms/nive
class tViews(unittest.TestCase):
    def setUp(self):
        request = testing.DummyRequest()
        request._LOCALE_ = "en"
        self.request = request
        self.config = testing.setUp(request=request)
        self.app = app()
        self.portal = Portal()
        self.portal.Register(self.app, "nive")
        self.app.Register("nive.cms.cmsview.view")
        self.app.Register(adminroot.configuration)
        self.app.Startup(self.config)
        self.root = self.app.root("usermanagement")
        self.request.context = self.root

    def tearDown(self):
        self.app.Close()
        testing.tearDown()

    def test_views(self):
        v = view.UsermanagementView(context=self.root, request=self.request)
        self.assert_(v.GetAdminWidgets())
        self.assert_(v.add())
        self.assert_(v.edit())
        self.assert_(v.delete())
        v.view()

    def test_templates(self):
        user = User(u"test")
        v = view.UsermanagementView(context=self.root, request=self.request)
        vrender = {"context": self.root, "view": v, "request": self.request}

        values = v.add()
        values.update(vrender)
        render("nive.userdb.useradmin:add.pt", values)
        u = self.root.Create("user", {
            "name": "testuser",
            "password": "******",
            "email": "*****@*****.**",
            "groups": ("group:admin", )
        },
                             user=user)
        v.context = u
        values = v.edit()
        values.update(vrender)
        values["context"] = u
        render("nive.userdb.useradmin:edit.pt", values)
        v.context = self.root
        values = v.view()
        values.update(vrender)
        render("nive.userdb.useradmin:root.pt", values)
        values = v.delete()
        values.update(vrender)
        render("nive.userdb.useradmin:delete.pt", values)

        self.root.Delete(u.id, user=user)

    def test_add(self):
        user = self.root.GetUserByName("testuser")
        if user:
            self.root.DeleteUser("testuser")
        v = view.UsermanagementView(context=self.root, request=self.request)
        r = v.add()
        self.assert_(r["result"])
        if self.root.GetUserByName("testuser"):
            self.assert_(False, "User should not exist")
        self.request.POST = {
            "name": "testuser",
            "password": "",
            "email": "*****@*****.**",
            "groups": ("group:admin", )
        }
        r = v.add()
        self.assert_(r["result"])
        if self.root.GetUserByName("testuser"):
            self.assert_(False, "User should not exist")

        self.request.POST["create$"] = "create"
        r = v.add()
        self.assertFalse(r["result"])
        if self.root.GetUserByName("testuser"):
            self.assert_(False, "User should not exist")
        self.request.POST["password"] = "******"
        self.request.POST["password-confirm"] = "password"

        self.assertRaises(HTTPFound, v.add)
        self.assert_(self.root.GetUserByName("testuser"))

        self.root.DeleteUser("testuser")

    def test_edit(self):
        user = self.root.GetUserByName("testuser")
        if user:
            self.root.DeleteUser("testuser")
        v = view.UsermanagementView(context=self.root, request=self.request)
        self.request.POST = {
            "name": "testuser",
            "email": "*****@*****.**",
            "groups": ("group:admin", )
        }
        self.request.POST["password"] = "******"
        self.request.POST["password-confirm"] = "password"
        self.request.POST["create$"] = "create"
        self.assertRaises(HTTPFound, v.add)
        user = self.root.GetUserByName("testuser")
        if not user:
            self.assert_(False, "User should exist")

        v = view.UsermanagementView(context=user, request=self.request)
        self.request.POST = {}
        r = v.edit()
        self.assert_(r["result"])

        self.request.POST = {
            "name": "testuser",
            "email": "test",
            "groups": ("group:admin", )
        }
        self.request.POST["edit$"] = "edit"
        r = v.edit()
        self.assertFalse(r["result"])
        user = self.root.GetUserByName("testuser")
        self.assert_(user.data.email != "test")

        self.request.POST = {
            "name": "testuser",
            "email": "*****@*****.**",
            "groups": ("group:admin", )
        }
        self.request.POST["edit$"] = "edit"
        r = v.edit()
        self.assert_(r["result"])
        user = self.root.GetUserByName("testuser")
        self.assert_(user.data.email == "*****@*****.**")

        self.root.DeleteUser("testuser")

    def test_delete(self):
        v = view.UsermanagementView(context=self.root, request=self.request)
        user = self.root.GetUserByName("testuser")
        if not user:
            self.request.POST = {
                "name": "testuser",
                "email": "*****@*****.**",
                "groups": ("group:admin", )
            }
            self.request.POST["password"] = "******"
            self.request.POST["password-confirm"] = "password"
            self.request.POST["create$"] = "create"
            self.assertRaises(HTTPFound, v.add)
        user = self.root.GetUserByName("testuser")
        if not user:
            self.assert_(False, "User should exist")

        r = v.delete()
        self.assert_(r["result"])
        self.assertFalse(r["confirm"])

        ids = (user.id, )
        self.request.POST = {"ids": ids}
        r = v.delete()
        self.assert_(r["result"])
        self.assertFalse(r["confirm"])
        self.assert_(len(r["users"]) == 1)

        self.request.POST = {"ids": ids, "confirm": 1}
        self.assertRaises(HTTPFound, v.delete)
        self.assertFalse(self.root.GetUserByName("testuser"))