def test_conversion_equality(self): session = DBSession() PROJECT_ID = 2 schema = convert_schema(SQLAlchemyMapping(Project, unknown='raise',)) form = Form(schema, action='test', project_id=PROJECT_ID, buttons=('Save', 'Delete', 'Submit', 'Reopen', 'Approve', 'Disable'), use_ajax=False) model = session.query(Project).filter_by(id=2).first() data = model.dictify(schema) new_model = Project(appstruct=data) public_props = (name for name in dir(object) if not name.startswith('_')) for name in public_props: print name assert model.getattr(name) == new_model.getattr(name), "Converted models don't equal: %s, %s" % model.getattr(name) % new_model.getattr(name) print "Successfully read model, converted to data, converted back to model and the models are the same."
def initialise_project_templates(session): """ Initialise the default project templates, this could be updated to be organisation specific. :param session: Database connection to add the created templates to. :return: None """ blank_project = Project() blank_project.template_only = True session.add(blank_project) # Add an empty project as a blank template session.flush() blank_template = ProjectTemplate() blank_template.template_id = blank_project.id blank_template.category = "Blank (No auto-fill)" blank_template.name = "Blank Template" blank_template.description = ( "An empty template that allows you to start from scratch (only for advanced " "users or if no other template is relevent)." ) session.add(blank_template) # Add an empty project as a blank template # add blank templates for testing, delete when production ready placeholder_template_names = [ "DRO", "Australian Wet Tropics", "TERN Supersite", "The Wallace Initiative", "Tropical Futures", ] count = 0 for name in placeholder_template_names: for i in range(random.randint(2, 5)): template = ProjectTemplate() template.template_id = blank_project.id template.category = name template.name = name + " Placeholder Template " + str(count) + " (Testing Only)" count += 1 template.description = ( "An empty template that allows you to start from scratch (only for advanced " "users or if no other template is relevent)." ) session.add(template) # Add an empty project as a blank template