def setUp(self): self.project = Project(**{'name': 'Customer A'}) self.project.save() self.folder = Folder(**{'name': 'Images', 'project': self.project}) self.folder.save() files = ['2210571.jpg', 'images.docx'] for file in files: path = 'tests/files/%s' % file f = open(path, 'rb') document = Document() document.folder = self.folder document.name = file document.file.save(name=document.name, content=File(f)) document.save() document.save_thumbnail() f.close()
def update_or_create_project(yaml_obj): """ Submit an object read from our YAML files and it will update it in the database, creating it if it doesn't already exist. Returns the database object, and a boolean that is true if a new object was created. """ obj = Project.get_by_key_name(yaml_obj.get('slug')) # Update the obj if it exists if obj: for key in yaml_obj.keys(): setattr(obj, key, yaml_obj.get(key)) obj.put() return obj, False # Create it if it doesn't else: obj = Project(key_name=yaml_obj.get('slug'), **yaml_obj) obj.put() return obj, True