def testversioning(self): assert Page.query_live.get_or_404 is not None # pass # with self.app.app_context(): p = Page() p.name = "Test Page" p.content = "Voll Krazy" p.content_json = "asdasd" p.sabdj = 100 db.session.add(p) db.session.commit() print("RUNNING") # assert len(p.versions.all()) == 1 assert Page.LiveType.query.filter(Page.name == "Test Page").first() == None assert Page.query_live.get(1) == None del p p = Page.query.get(1) assert p.content == "Voll Krazy" print(p.as_dict()) p.mark_as_published() db.session.commit() assert Page.LiveType.query.filter(Page.LiveType.name == "Test Page").first() is not None p.name = "Test 123" p.content = "aaa" db.session.commit() assert Page.query_live.first().name == "Test Page" assert Page.query_live.first().content == "Voll Krazy" assert Page.query.first().content == "aaa" print(Page.LiveType.query.first().name) assert Page.query.first().name == "Test 123" p.mark_as_published() assert Page.LiveType.query.first().name == "Test 123" assert(len(p.versions.all()) == 2) versions = p.versions.all() assert versions[0].name == "Test Page" assert versions[1].name == "Test 123" print(Page.LiveType.query.first().name)
def setUp(self): from silverflask.models import User from silverflask.models.User import Role if not len(Role.query.all()): admin_role = Role("admin", "Admin has all privileges") db.session.add(admin_role) db.session.commit() if not len(User.query.all()): # create standard user u = User("admin", "admin") u.email = "admin" db.session.add(u) admin_role = Role.query.filter(Role.name == "admin").first() u.roles.append(admin_role) db.session.commit() from silverflask.models import SiteConfig if not len(SiteConfig.query.all()): sc = SiteConfig() db.session.add(sc) db.session.commit() if not len(Page.query.all()): page = Page() page.content = "<p>Please proceed to the admin interface at <a href='/admin'>admin</a>!</p>" page.name = "home" page.urlsegment = "home" db.session.add(page) db.session.commit() page.mark_as_published() db.session.commit()
def createdb(): """ Creates a database with the defined models and also adds the default records that are needed for the CMS: Admin User, Admin Role, Default first page, and stuff """ db.create_all() from silverflask.models import User from silverflask.models.User import Role if not len(Role.query.all()): admin_role = Role("admin", "Admin has all privileges") db.session.add(admin_role) db.session.commit() if not len(User.query.all()): # create standard user u = User("admin", "admin") u.firstname = "Default" u.lastname = "Admin" u.email = "admin" db.session.add(u) admin_role = Role.query.filter(Role.name == "admin").first() u.roles.append(admin_role) db.session.commit() from silverflask.models import SiteConfig if not len(SiteConfig.query.all()): sc = SiteConfig() sc.title = "Your SilverFlask Website" sc.tagline = "This is a default installation" db.session.add(sc) db.session.commit() if not len(Page.query.all()): page = Page() page.content = "<p>Please proceed to the admin interface at <a href='/admin'>admin</a>!</p>" page.name = "home" page.urlsegment = "home" db.session.add(page) db.session.commit() page.mark_as_published() db.session.commit()
def setUp(self): """ Initialize app and setup admin user ('admin', 'admin'), a SiteConfig and a Page. """ self.create_app() from silverflask.models import User from silverflask.models.User import Role if not len(Role.query.all()): admin_role = Role("admin", "Admin has all privileges") db.session.add(admin_role) db.session.commit() if not len(User.query.all()): # create standard user u = User("admin", "admin") u.email = "admin" db.session.add(u) admin_role = Role.query.filter(Role.name == "admin").first() u.roles.append(admin_role) db.session.commit() from silverflask.models import SiteConfig if not len(SiteConfig.query.all()): sc = SiteConfig() db.session.add(sc) db.session.commit() if not len(Page.query.all()): page = Page() page.content = "<p>Please proceed to the admin interface at <a href='/admin'>admin</a>!</p>" page.name = "home" page.urlsegment = "home" db.session.add(page) db.session.commit() page.mark_as_published() db.session.commit()