コード例 #1
0
    def test_filetracker_to_django_field(self):
        data = 'eloziom'
        path = 'my/path'
        abspath = '/' + path

        storage = default_storage
        try:
            self.assertEqual(storage.save(path, ContentFile(data)), path)

            model = TestFileModel()
            # File field is ignoring preferred name, as we can't copy file
            # in filetracker to another location
            with self.assertRaises(NotImplementedError):
                model.file_field.save('xx',
                        filetracker_to_django_file(abspath, storage))

            model.file_field = filetracker_to_django_file(abspath, storage)
            model.save()
            self.assertEqual(model.file_field.name, path)
            pk = model.pk

            # Here the model is removed from Django's cache, so the query
            # below actually hits the database.
            del model

            model = TestFileModel.objects.get(pk=pk)
            self.assertEqual(model.file_field.name, path)
            self.assertEqual(django_to_filetracker_path(model.file_field),
                                abspath)
            self.assertEqual(model.file_field.read(), data)
        finally:
            default_storage.delete(path)
コード例 #2
0
ファイル: tests.py プロジェクト: marmistrz/oioioi
    def test_filetracker_to_django_field(self):
        data = 'eloziom'
        path = 'my/path'
        abspath = '/' + path

        storage = default_storage
        try:
            self.assertEqual(storage.save(path, ContentFile(data)), path)

            model = TestFileModel()
            # File field is ignoring preferred name, as we can't copy file
            # in filetracker to another location
            with self.assertRaises(NotImplementedError):
                model.file_field.save(
                    'xx', filetracker_to_django_file(abspath, storage))

            model.file_field = filetracker_to_django_file(abspath, storage)
            model.save()
            self.assertEqual(model.file_field.name, path)
            pk = model.pk

            # Here the model is removed from Django's cache, so the query
            # below actually hits the database.
            del model

            model = TestFileModel.objects.get(pk=pk)
            self.assertEqual(model.file_field.name, path)
            self.assertEqual(django_to_filetracker_path(model.file_field),
                             abspath)
            self.assertEqual(model.file_field.read(), data)
        finally:
            default_storage.delete(path)
コード例 #3
0
    def test_file_field(self):
        f = ContentFile('eloziom', name='foo')

        model = TestFileModel()
        model.file_field = f
        model.save()
        pk = model.pk

        # Here the model is removed from Django's cache, so the query
        # below actually hits the database.
        del model

        model = TestFileModel.objects.get(pk=pk)
        self.assertEqual(model.file_field.read(), 'eloziom')

        model.file_field.delete()
コード例 #4
0
ファイル: tests.py プロジェクト: marmistrz/oioioi
    def test_file_field(self):
        f = ContentFile('eloziom', name='foo')

        model = TestFileModel()
        model.file_field = f
        model.save()
        pk = model.pk

        # Here the model is removed from Django's cache, so the query
        # below actually hits the database.
        del model

        model = TestFileModel.objects.get(pk=pk)
        self.assertEqual(model.file_field.read(), 'eloziom')

        model.file_field.delete()