def test_mails(self): user = User(u"test") user.data["token"] = "123" values = {"user": user, "url": "uuu", "password": "******"} render("nive_userdb.userview:mails/notify.pt", values) render("nive_userdb.userview:mails/signup.pt", values) render("nive_userdb.userview:mails/verifymail.pt", values) render("nive_userdb.userview:mails/mailpass.pt", values) render("nive_userdb.userview:mails/resetpass.pt", values)
def test_mails(self): user = User(u"test") user.data["token"] = "123" values = {"user": user, "url":"uuu", "password": "******"} render("nive_userdb.userview:mails/notify.pt", values) render("nive_userdb.userview:mails/signup.pt", values) render("nive_userdb.userview:mails/verifymail.pt", values) render("nive_userdb.userview:mails/mailpass.pt", values) render("nive_userdb.userview:mails/resetpass.pt", values)
def test_itemcontext(self): user = User(u"test") user.groups.append("group:manager") r = self.root o1 = create_bookmark(r, user) self.remove.append(o1.id) o2 = create_track(r, user) self.remove.append(o2.id) self.request.context = o1 view = APIv1(o1, self.request) result = view.getItem() self.assert_(result) self.assert_(result["link"] == "the link") self.request.context = o2 view = APIv1(o2, self.request) result = view.getItem() self.assert_(result) self.assert_(result["url"] == "the url") self.request.context = o1 view = APIv1(o1, self.request) self.request.POST = {"link": u"the link new", "comment": u"some text"} result = view.setItem() o = self.root.GetObj(o1.id) self.assert_(o.data.link == u"the link new") self.request.context = o2 view = APIv1(o2, self.request) self.request.POST = {"number": 444} result = view.setItem() self.assert_(result.get("error")) o = self.root.GetObj(o2.id) self.assert_(o.data.number == 123)
def test_objs(self): a = self.app ccc = a.db.GetCountEntries() r = root(a) user = User(u"test") user.groups.append("group:editor") p = create_page(r, user=user) self.remove.append(p.id) r = p #box b1 = create_box(r, user=user) b1.IsContainer() b1.GetPage() b1.GetElementContainer() b1.GetContainer() #column b2 = create_column(r, user=user) self.assert_(b2.IsLocal(r)) b2.GetName() b2.IsContainer() b2.GetPage() b2.GetPages() b2.GetElementContainer() b2.GetContainer() self.assert_(b2.GetColumn("left") == b2) #file b3 = create_file(r, user=user) b3.GetDownloadTitle() b3.FilenameToTitle() #menublock b0 = create_menublock(r, user=user) b0.GetMenuPages() root(a).Delete(r.id, user=user) self.assertEqual(ccc, a.db.GetCountEntries(), "Delete failed")
def tearDown(self): user = User(u"test") r = self.app.root() r.Delete(self.context.id, user=user) r.Delete(self.context2.id, user=user) self.app.Close() testing.tearDown()
def test_deserialize(self): user = User(u"test") view = APIv1(self.root, self.request) r = self.root o1 = create_bookmark(r, user) self.remove.append(o1.id) items = [o1] values = DeserializeItems(view, items, ("comment", "link")) self.assert_(len(values) == 1) values = DeserializeItems(view, items, o1.configuration) self.assert_(len(values) == 1) values = DeserializeItems(view, items, {"bookmark": ("comment", "link")}) self.assert_(len(values) == 1) values = DeserializeItems(view, items, {"default__": ("comment", "link")}) self.assert_(len(values) == 1) values = DeserializeItems(view, items, {"default__": ("comment", "link")}, render=("comment", "link")) self.assert_(len(values) == 1) items = o1 values = DeserializeItems(view, items, ("comment", "link")) self.assert_(len(values) == 1)
def test_setformfailures(self): user = User(u"test") user.groups.append("group:manager") r = self.root o1 = create_bookmark(r, user) self.remove.append(o1.id) view = APIv1(o1, self.request) view.__configuration__ = lambda: Conf(assets=(), views=()) # wrong subset self.request.POST = { "subset": "unknown!", "pool_type": "bookmark", "link": u"the link", "comment": u"some text" } self.assertRaises(ConfigurationError, view.setItemForm) # wrong action objs = len(r.GetObjsList(fields=["id"])) self.request.POST = { "pool_type": "bookmark", "link": u"the link", "comment": u"some text", "unknown$": "1" } result = view.setItemForm() self.assert_(self.request.response.headers["X-Result"]) self.assert_(objs == len(r.GetObjsList(fields=["id"])))
def createObj3(c): type = u"type3" data = data3_1 user = User(u"test") o = c.Create(type, data=data, user=user) #o.Commit() return o
def test_assets(self): view = Editor(self.page, self.request) view.__configuration__ = lambda: Conf( assets=[('cmsview.js', 'http://nive.co/cmsview.js'), ('cmsview.css', 'http://nive.co/cmsview.css')]) user = User(u"test") html = view.Assets() self.assert_(html) self.assert_(html.find("<script") != -1) self.assert_(html.find("<link") != -1) assets = [ ('jquery.js', 'http://nive.co/static/mods/jquery.min.js'), ('toolbox.css', 'http://nive.co/static/toolbox/toolbox.css'), ('overlay.css', 'nive_cms.cmsview:static/overlay/overlay.css'), ('cmseditor.js', 'nive_cms.cmsview:static/cmseditor.js'), ] html = view.Assets(assets=assets) self.assert_(html) self.assert_(html.find(assets[0][1]) != -1) self.assert_(html.find(assets[1][1]) != -1) html = view.Assets(assets=[]) self.assertFalse(html) html = view.Assets(assets=assets, ignore=('jquery.js', 'toolbox.css')) self.assert_(html.find(assets[0][1]) == -1) self.assert_(html.find(assets[1][1]) == -1)
def tearDown(self): u = User(u"test") u.groups.append("group:manager") root = self.app.root() for r in self.remove: root.Delete(r, u) self.app.Close()
def test_newform_noajax(self): user = User(u"test") user.groups.append("group:manager") r = self.root view = APIv1(r, self.request) view.__configuration__ = lambda: Conf(assets=(), views=()) view.GetViewConf = lambda: Conf( settings={ "form": { "fields": ("comment", ), "use_ajax": False }, "includeAssets": False }) self.request.POST = { "pool_type": "bookmark", "link": u"the link", "comment": u"some text" } result = view.newItemForm() self.assert_(self.request.response.headers["X-Result"]) objs = len(r.GetObjsList(fields=["id"])) self.request.POST = { "pool_type": "bookmark", "link": u"the link", "comment": u"some text", "create$": "1" } result = view.newItemForm() self.assert_(self.request.response.headers["X-Result"]) self.assert_(result["content"]) self.assert_(objs + 1 == len(r.GetObjsList(fields=["id"])))
def test_functions(self): user = User(u"test") user.groups.append("group:editor") wf.publish(None, self.page, user, {}) self.assert_(self.page.meta.pool_state == 1) wf.revoke(None, self.page, user, {}) self.assert_(self.page.meta.pool_state == 0)
def setUp(self): self._loadApp() user = self.user = User(u"test") user.groups.append("group:editor") root = self.app.root("editor") self.page0 = db_app.create_page(root, user) self.page = db_app.create_page(self.page0, user)
def test_newform(self): user = User(u"test") user.groups.append("group:manager") r = self.root view = APIv1(r, self.request) view.__configuration__ = lambda: Conf(assets=(), views=()) self.request.POST = { "pool_type": "bookmark", "link": u"the link", "comment": u"some text" } result = view.newItemForm() self.assert_(self.request.response.headers["X-Result"]) objs = len(r.GetObjsList(fields=["id"])) self.request.POST = { "pool_type": "bookmark", "link": u"the link", "comment": u"some text", "create$": "1" } try: view.newItemForm() except ExceptionalResponse, result: self.assert_(self.request.response.headers["X-Result"]) self.assert_(objs + 1 == len(r.GetObjsList(fields=["id"])))
def setUp(self): self._loadApp() r=self.app.root() # create three levels of entries level1 = 5 level2 = 5 level3_1 = 5 level3_2 = 5 c=r ids=[] n=0 user = User(u"test") for i in range(0,level1): o=db_app.createObj1(c) n+=1 ids.append(o.id) for i2 in range(0,level2): o2=db_app.createObj1(o) n+=1 for i3 in range(0,level3_1): db_app.createObj1(o2) n+=1 for i3 in range(0,level3_2): o4 = db_app.createObj2(o2) id = o4.id n+=1 self.ids = ids self.lastid = id
def test_container(self): a = self.app ccc = a.db.GetCountEntries() r = root(a) user = User(u"test") user.groups.append("group:editor") # add to root b1 = create_box(r, user=user) self.assert_(b1) self.remove.append(b1.id) r = b1 b3 = create_file(r, user=user) self.assert_(b3) b4 = create_image(r, user=user) self.assert_(b4) b5 = create_media(r, user=user) self.assert_(b5) b6 = create_note(r, user=user) self.assert_(b6) b7 = create_text(r, user=user) self.assert_(b7) b8 = create_spacer(r, user=user) self.assert_(b8) b9 = create_link(r, user=user) self.assert_(b9) b0 = create_menublock(r, user=user) self.assert_(b0) b10 = create_code(r, user=user) self.assert_(b10) r = root(a) col = r.GetColumn("left") if col: r.Delete(col.id, user=user) b2 = create_column(r, user=user) self.assert_(b2) self.remove.append(b2.id) r = b2 b3 = create_file(r, user=user) self.assert_(b3) b4 = create_image(r, user=user) self.assert_(b4) b5 = create_media(r, user=user) self.assert_(b5) b6 = create_note(r, user=user) self.assert_(b6) b7 = create_text(r, user=user) self.assert_(b7) b8 = create_spacer(r, user=user) self.assert_(b8) b9 = create_link(r, user=user) self.assert_(b9) b0 = create_menublock(r, user=user) self.assert_(b0) b10 = create_code(r, user=user) self.assert_(b10) root(a).Delete(b1.id, user=user, obj=b1) root(a).Delete(b2.id, user=user, obj=b2) self.assertEqual(ccc, a.db.GetCountEntries(), "Delete failed")
def createObj2file(c): type = u"type2" data = data2_1.copy() data["file2"] = File(**file2_1) user = User(u"test") o = c.Create(type, data=data, user=user) #o.Commit() return o
def test_toolobj(self): user = User(u"test") r = self.app.root() o = db_app.createObj1(r) t = o.GetTool("nive.components.tools.example") r1, v = t() self.assert_(r1) r.Delete(o.GetID(), user=user)
def setUp(self): self._loadApp() root = self.app.root("editor") user = User(u"test") user.groups.append("group:editor") self.page = db_app.create_page(root, user) self.text1 = db_app.create_text(root, user) self.text2 = db_app.create_text(root, user) pass
def test_functions(self): root = self.app.root("editor") user = User(u"test") request = {"pepos": 0} self.assert_(root.GetSort()) self.assert_(root.GetSortElements(selection=None)) self.assert_(root.GetSortElements(selection="pages")) self.assert_(root.GetSortElements(selection="elements")) self.assert_(root.GetMaxSort()) root.UpdateSort([self.text2, self.text1], user) root.InsertAtPosition(self.text1.id, u"first", user, selection=None) root.InsertAtPosition(self.text1.id, u"last", user, selection=None) root.InsertAtPosition(self.text1.id, self.text2.id, user, selection=None) root.InsertBefore(self.text1.id, self.text2.id, user, selection=None) root.InsertAfter(self.text1.id, self.text2.id, user, selection=None) root.MoveUp(self.text1.id, user, selection=None) root.MoveDown(self.text1.id, user, selection=None) root.MoveStart(self.text1.id, user, selection=None) root.MoveEnd(self.text1.id, user, selection=None) # element selection root.InsertAtPosition(self.text1.id, u"first", user, selection="elements") root.InsertAtPosition(self.text1.id, u"last", user, selection="elements") root.InsertAtPosition(self.text1.id, self.text2.id, user, selection="elements") root.InsertBefore(self.text1.id, self.text2.id, user, selection="elements") root.InsertAfter(self.text1.id, self.text2.id, user, selection="elements") root.MoveUp(self.text1.id, user, selection="elements") root.MoveDown(self.text1.id, user, selection="elements") root.MoveStart(self.text1.id, user, selection="elements") root.MoveEnd(self.text1.id, user, selection="elements")
def test_searchConf(self): user = User(u"test") user.groups.append("group:manager") view = APIv1(self.root, self.request) r = self.root objs = r.GetObjs() for o in objs: r.Delete(o.id, obj=o, user=user) o1 = create_bookmark(r, user) self.remove.append(o1.id) o3 = create_bookmark(r, user) self.remove.append(o3.id) o2 = create_bookmark(o1, user) create_track(o1, user) create_track(o1, user) create_track(o3, user) self.request.POST = {} result = view.search() self.assert_(len(result["items"]) == 6, result) self.request.POST = {"profile": "bookmarks"} result = view.search() self.assert_(len(result["items"]) == 3) # container activated self.request.POST = {"profile": "tracks"} result = view.search() self.assert_(len(result["items"]) == 0, result) view = APIv1(o1, self.request) self.request.POST = {"profile": "tracks"} result = view.search() self.assert_(len(result["items"]) == 2, result) self.request.POST = {"size": 2} result = view.search() self.assert_(len(result["items"]) == 2) self.assert_(result["size"] == 2) self.assert_(result["start"] == 1, result) self.assert_(result["total"] == 6) self.request.POST = {"size": 2, "start": 3} result = view.search() self.assert_(len(result["items"]) == 2) self.assert_(result["size"] == 2) self.assert_(result["start"] == 3, result) self.assert_(result["total"] == 6) self.request.POST = {"size": 2, "start": 6} result = view.search() self.assert_(len(result["items"]) == 1, result) self.assert_(result["size"] == 1) self.assert_(result["start"] == 6) self.assert_(result["total"] == 6, result)
def test_disabled(self): user = User(u"test") self.page.data["customfilename"] = True self.page.Commit(user=user) self.page.meta["pool_filename"] = u"custom" self.page.Commit(user=user) self.assert_(self.page.meta.pool_filename == u"custom") self.page.meta["title"] = u"new title" self.page.Commit(user=user) self.assert_(self.page.meta.pool_filename == u"custom")
def test_nostate(self): user = User(u"test") user.groups.append("group:manager") r = self.root o1 = create_bookmark(r, user) self.remove.append(o1.id) view = APIv1(o1, self.request) result = view.state() self.assertFalse(result["result"])
def test_renderjson(self): user = User(u"test") user.groups.append("group:manager") view = APIv1(self.root, self.request) r = self.root objs = r.GetObjs() for o in objs: r.Delete(o.id, obj=o, user=user) o1 = create_bookmark(r, user) self.remove.append(o1.id) o3 = create_bookmark(r, user) self.remove.append(o3.id) o2 = create_bookmark(o1, user) create_track(o1, user) create_track(o1, user) create_track(o3, user) values = view.subtree() self.assert_(self.request.response.status.startswith("400")) self.request.POST = {"profile": "none"} values = view.subtree() self.assert_(self.request.response.status.startswith("400")) profile = { "descent": ("nive.definitions.IContainer", ), "addContext": True } view.GetViewConf = lambda: Conf(settings=profile) values = view.subtree() self.assert_(values != {}) self.assert_(len(values["items"]) == 2) self.assert_(len(values["items"][0]["items"]) == 3) profile = { "descent": ("nive.definitions.IContainer", ), "parameter": { "pool_type": "bookmark" }, "addContext": True } view.GetViewConf = lambda: Conf(settings=profile) values = view.subtree() self.assert_(values != {}) self.assert_(len(values["items"]) == 2) self.assert_(len(values["items"][0]["items"]) == 1) view = APIv1(o1, self.request) self.request.POST = {"subtree": "0"} values = view.subtree() self.assert_(values != {}) self.assert_(values.get("items") == None)
def setUp(self): request = testing.DummyRequest() request._LOCALE_ = "en" self.request = request self.config = testing.setUp(request=request) self._loadApp() self.app.Startup(self.config) self.root = self.app.root() user = User(u"test") user.groups.append("group:manager") self.request.context = self.root self.remove = []
def test_views1(self): view = Editor(self.page, self.request) user = User(u"test") user.groups.append("group:editor") view.sortpages() view.sortelements() self.request.GET = {"id": self.text1.id} self.assertRaises(HTTPFound, view.moveup) self.assertRaises(HTTPFound, view.movedown) self.assertRaises(HTTPFound, view.movetop) self.assertRaises(HTTPFound, view.movebottom)
def test_newform_assets(self): user = User(u"test") user.groups.append("group:manager") r = self.root view = APIv1(r, self.request) view.__configuration__ = lambda: Conf(assets=(("jquery.js", "path"), ), views=()) self.request.POST = {"assets": "only"} result = view.newItemForm() self.assert_(result["content"]) self.assert_(result["content"].find("<form") == -1)
def setUp(self): request = testing.DummyRequest() request._LOCALE_ = "en" request.content_type = "" self.request = request self.config = testing.setUp(request=request) self.config.include('pyramid_chameleon') self._loadApp() self.app.Startup(self.config) self.root = self.app.root("editor") user = User(u"test") user.groups.append("group:editor") self.page = create_page(self.root, user) self.request.context = self.page
def test_listings(self): user = User(u"test") user.groups.append("group:manager") view = APIv1(self.root, self.request) r = self.root objs = r.GetObjs() for o in objs: r.Delete(o.id, obj=o, user=user) o1 = create_bookmark(r, user) self.remove.append(o1.id) o2 = create_track(r, user) self.remove.append(o2.id) o3 = create_bookmark(r, user) self.remove.append(o3.id) o4 = create_track(r, user) self.remove.append(o4.id) # testing listings and parameter self.request.POST = {} result = view.listItems() self.assert_(len(result["items"]) == 4) self.request.POST = {"start": 2} result = view.listItems() self.assert_(result["start"] == 2) self.assert_(len(result["items"]) == 2) self.request.POST = {"pool_type": "track"} result = view.listItems() self.assert_(len(result["items"]) == 2) self.request.POST = {"sort": "pool_change", "order": "<", "size": 2} result = view.listItems() self.assert_(len(result["items"]) == 2) self.request.POST = {"sort": "id", "order": "<", "size": 2} result = view.listItems() self.assert_(len(result["items"]) == 2) ids = result["items"] self.request.POST = {"sort": "id", "order": ">", "size": 2} result = view.listItems() self.assert_(result["items"] != ids) self.request.POST = {"sort": "id", "order": "<", "size": 4} result = view.listItems() ids = result["items"] self.request.POST = {"sort": "id", "order": ">", "size": 4} result = view.listItems() self.assert_(ids[0] == result["items"][3]) self.assert_(ids[1] == result["items"][2])
def setUp(self): request = testing.DummyRequest() request._LOCALE_ = "en" self.request = request self.config = testing.setUp(request=request) self.app = db_app.app() self.app.Startup(self.config) self.root = self.app.root("editor") user = User(u"test") user.groups.append("group:editor") self.page = db_app.create_page(self.root, user) self.text1 = db_app.create_text(self.root, user) self.text2 = db_app.create_text(self.root, user) self.request.context = self.page
def test_newSecured(self): user = User(u"test") user.groups.append("group:manager") # add success # single item param = { "pool_type": "bookmark", "link": u"the link", "comment": u"some text" } result, stat = self.root.dispatch("newItem", True, self.request, **param) self.assert_(len(result["result"]) == 1) self.root.Delete(result["result"][0], user=user)
def test_root(self): a=self.app ccc = a.db.GetCountEntries() r=root(a) user = User(u"test") user.groups.append("group:editor") # add to root p = create_page(r, user=user) self.assert_(p) self.remove.append(p.id) b0 = create_menublock(r, user=user) self.assert_(b0) self.remove.append(b0.id) b1 = create_box(r, user=user) self.assert_(b1) self.remove.append(b1.id) col = r.GetColumn("left") if col: r.Delete(col.id, user=user) b2 = create_column(r, user=user) self.assert_(b2) self.remove.append(b2.id) b3 = create_file(r, user=user) self.assert_(b3) self.remove.append(b3.id) b4 = create_image(r, user=user) self.assert_(b4) self.remove.append(b4.id) b5 = create_media(r, user=user) self.assert_(b5) self.remove.append(b5.id) b6 = create_note(r, user=user) self.assert_(b6) self.remove.append(b6.id) b7 = create_text(r, user=user) self.assert_(b7) self.remove.append(b7.id) b8 = create_spacer(r, user=user) self.assert_(b8) self.remove.append(b8.id) b9 = create_link(r, user=user) self.assert_(b9) self.remove.append(b9.id) b10 = create_code(r, user=user) self.assert_(b10) self.remove.append(b10.id) r.Delete(p.id, user=user, obj=p) r.Delete(b0.id, user=user) r.Delete(b1.id, user=user) r.Delete(b2.id, user=user) r.Delete(b3.id, user=user) r.Delete(b4.id, user=user) r.Delete(b5.id, user=user) r.Delete(b6.id, user=user) r.Delete(b7.id, user=user) r.Delete(b8.id, user=user) r.Delete(b9.id, user=user) r.Delete(b10.id, user=user) self.assertEqual(ccc, a.db.GetCountEntries(), "Delete failed") # workflow failure add to root user.groups = ["group:looser"] self.assertRaises(WorkflowNotAllowed, create_page, r, user)