def setup_database(): init_model(engine) teardownDatabase() metadata.create_all(engine) # Creating permissions see_site = Permission() see_site.permission_name = u'see-site' DBSession.add(see_site) edit_site = Permission() edit_site.permission_name = u'edit-site' DBSession.add(edit_site) commit = Permission() commit.permission_name = u'commit' DBSession.add(commit) # Creating groups admins = Group(u'admins') admins.permissions.append(edit_site) DBSession.add(admins) developers = Group(u'developers') developers.permissions = [commit, edit_site] DBSession.add(developers) trolls = Group(u'trolls') trolls.permissions.append(see_site) DBSession.add(trolls) # Plus a couple of groups with no permissions php = Group(u'php') DBSession.add(php) python = Group(u'python') DBSession.add(python) # Creating users user = User() user.user_name = u'rms' user.password = u'freedom' user.groups.append(admins) user.groups.append(developers) DBSession.add(user) user = User() user.user_name = u'linus' user.password = u'linux' user.groups.append(developers) DBSession.add(user) user = User() user.user_name = u'sballmer' user.password = u'developers' user.groups.append(trolls) DBSession.add(user) # Plus a couple of users without groups user = User() user.user_name = u'guido' user.password = u'phytonic' DBSession.add(user) user = User() user.user_name = u'rasmus' user.password = u'php' DBSession.add(user) DBSession.commit()
def setup_database(): init_model(engine) teardownDatabase() metadata.create_all(engine) # Creating permissions see_site = Permission() see_site.permission_name = u"see-site" DBSession.add(see_site) edit_site = Permission() edit_site.permission_name = u"edit-site" DBSession.add(edit_site) commit = Permission() commit.permission_name = u"commit" DBSession.add(commit) nopermission = Permission() nopermission.permission_name = u"nopermission" DBSession.add(nopermission) # Creating groups admins = Group(u"admins") admins.permissions.append(edit_site) DBSession.add(admins) developers = Group(u"developers") developers.permissions = [commit, edit_site] DBSession.add(developers) trolls = Group(u"trolls") trolls.permissions.append(see_site) DBSession.add(trolls) # Plus a couple of groups with no permissions php = Group(u"php") DBSession.add(php) python = Group(u"python") DBSession.add(python) nogroup = Group(u"nogroup") DBSession.add(nogroup) # Creating users user = User() user.user_name = u"rms" user.password = u"freedom" user.groups.append(admins) user.groups.append(developers) DBSession.add(user) user = User() user.user_name = u"linus" user.password = u"linux" user.groups.append(developers) DBSession.add(user) user = User() user.user_name = u"sballmer" user.password = u"developers" user.groups.append(trolls) DBSession.add(user) # Plus a couple of users without groups user = User() user.user_name = u"guido" user.password = u"phytonic" DBSession.add(user) user = User() user.user_name = u"rasmus" user.password = u"php" DBSession.add(user) DBSession.commit()