def test_dump_load_data_content(self): """ Testing the dump / load with full dump of file content data """ with SettingsOverride(filer_settings, FILER_DUMP_PAYLOAD=True): # Initialize the test data create_folder_structure(1, 1) fileobj = self.create_filer_file(Folder.objects.all()[0]) jdata = StringIO() # Dump the current data fobj = tempfile.NamedTemporaryFile(suffix=".json", delete=False) call_command("dumpdata", "filer", stdout=jdata, indent=3) # Delete database and filesystem data and complete = os.path.join(fileobj.file.storage.location, fileobj.path) os.unlink(complete) fileobj.delete() # Dump data to json file fobj.write(jdata.getvalue().encode('utf-8')) fobj.seek(0) # Load data back call_command("loaddata", fobj.name, stdout=jdata) # Database data is restored self.assertEqual(Folder.objects.all().count(), 1) self.assertEqual(File.objects.all().count(), 1) self.assertEqual(File.objects.all()[0].original_filename, self.image_name) fileobj = File.objects.all()[0] complete = os.path.join(fileobj.file.storage.location, fileobj.path) # Filesystem data too! self.assertTrue(os.path.exists(complete))
def test_dump_load_data(self): """ Testing the dump / load with no dump of file content data """ # Initialize the test data create_folder_structure(1, 1) fileobj = self.create_filer_file(Folder.objects.all()[0]) self.assertEqual(Image.objects.count(), 0) image = self.create_filer_image() image.save() image_size = image._width, image._height self.assertEqual(Image.objects.count(), 1) jdata = StringIO() # Dump the current data fobj = tempfile.NamedTemporaryFile(suffix=".json", delete=False) call_command("dumpdata", "filer", stdout=jdata, indent=3) # Delete database and filesystem data complete = os.path.join(fileobj.file.storage.location, fileobj.path) os.unlink(complete) fileobj.delete() # Dump data to json file fobj.write(jdata.getvalue().encode('utf-8')) fobj.seek(0) # Load data back call_command("loaddata", fobj.name, stdout=jdata) # Database data is restored self.assertEqual(Folder.objects.all().count(), 1) self.assertEqual(File.objects.all().count(), 2) self.assertEqual(File.objects.all()[0].original_filename, self.image_name) self.assertEqual(Image.objects.count(), 1) fileobj = File.objects.all()[0] image = Image.objects.all()[0] self.assertEqual(image._width, image_size[0]) self.assertEqual(image._height, image_size[1]) complete = os.path.join(fileobj.file.storage.location, fileobj.path) # Filesystem data is not self.assertFalse(os.path.exists(complete))
def test_create_folder_structure(self): create_folder_structure(depth=3, sibling=2, parent=None) self.assertEqual(Folder.objects.count(), 26)