Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    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])
        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(), 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 is not
        self.assertFalse(os.path.exists(complete))
Exemplo n.º 3
0
 def test_create_folder_structure(self):
     create_folder_structure(depth=3, sibling=2, parent=None)
     self.assertEqual(Folder.objects.count(), 26)
Exemplo n.º 4
0
 def test_create_folder_structure(self):
     create_folder_structure(depth=3, sibling=2, parent=None)
     self.assertEqual(Folder.objects.count(), 26)
Exemplo n.º 5
0
 def test_filer_directory_listing_root_get(self):
     create_folder_structure(depth=3, sibling=2, parent=None)
     response = self.client.post(reverse('admin:filer-directory_listing-root'))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.context['folder'].children.count(), 6)