Refactor Extension and Version: explicit constructors from File #191
@ -92,7 +92,6 @@ class Command(BaseCommand):
|
||||
size_bytes=FILE_SOURCES["blender-kitsu"]["size"],
|
||||
source=FILE_SOURCES["blender-kitsu"]["file"],
|
||||
status=File.STATUSES.APPROVED,
|
||||
type=File.TYPES.BPY,
|
||||
),
|
||||
)
|
||||
for preview in [
|
||||
@ -108,8 +107,8 @@ class Command(BaseCommand):
|
||||
for i in range(10):
|
||||
type = random.choice(Extension.TYPES)[0]
|
||||
version = create_approved_version(
|
||||
status=File.STATUSES.APPROVED,
|
||||
metadata__tags=random.sample(tags[type], k=1),
|
||||
status=File.STATUSES.APPROVED,
|
||||
type=type,
|
||||
)
|
||||
for preview in [
|
||||
@ -126,9 +125,9 @@ class Command(BaseCommand):
|
||||
for i in range(5):
|
||||
type = random.choice(Extension.TYPES)[0]
|
||||
version = create_version(
|
||||
metadata__tags=random.sample(tags[type], k=1),
|
||||
status=random.choice((File.STATUSES.DISABLED, File.STATUSES.DISABLED_BY_AUTHOR)),
|
||||
type=type,
|
||||
metadata__tags=random.sample(tags[type], k=1),
|
||||
)
|
||||
for i in range(random.randint(1, len(LICENSES))):
|
||||
version.licenses.add(LICENSES[i])
|
||||
|
@ -7,7 +7,7 @@ import factory.fuzzy
|
||||
from files.models import File
|
||||
|
||||
|
||||
class FileMetadataFactory(factory.DictFactory):
|
||||
class ManifestFactory(factory.DictFactory):
|
||||
name = factory.Faker('name')
|
||||
id = factory.Faker('slug')
|
||||
support = factory.Faker('url')
|
||||
@ -28,29 +28,27 @@ class FileFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = File
|
||||
|
||||
original_name = factory.LazyAttribute(lambda x: x.source)
|
||||
original_hash = factory.Faker('lexify', text='fakehash:??????????????????', letters='deadbeef')
|
||||
hash = factory.Faker('lexify', text='fakehash:??????????????????', letters='deadbeef')
|
||||
metadata = factory.SubFactory(ManifestFactory)
|
||||
original_hash = factory.Faker('lexify', text='fakehash:??????????????????', letters='deadbeef')
|
||||
original_name = factory.LazyAttribute(lambda x: x.source)
|
||||
size_bytes = factory.Faker('random_int', min=1234)
|
||||
source = factory.Faker('file_name', extension='zip')
|
||||
type = File.TYPES.BPY
|
||||
|
||||
user = factory.SubFactory('common.tests.factories.users.UserFactory')
|
||||
|
||||
metadata = factory.SubFactory(FileMetadataFactory)
|
||||
|
||||
|
||||
class ImageFactory(FileFactory):
|
||||
metadata = {}
|
||||
original_name = factory.Faker('file_name', extension='png')
|
||||
size_bytes = 1234
|
||||
source = 'images/de/deadbeef.png'
|
||||
type = File.TYPES.IMAGE
|
||||
size_bytes = 1234
|
||||
metadata = {}
|
||||
|
||||
|
||||
class VideoFactory(FileFactory):
|
||||
metadata = {}
|
||||
original_name = factory.Faker('file_name', extension='mp4')
|
||||
size_bytes = 12345678
|
||||
source = 'images/be/beefcafe.mp4'
|
||||
type = File.TYPES.VIDEO
|
||||
size_bytes = 12345678
|
||||
metadata = {}
|
||||
|
@ -244,6 +244,8 @@ class NewVersionFinalizeView(LoginRequiredMixin, OwnsFileMixin, CreateView):
|
||||
|
||||
def get_form_kwargs(self):
|
||||
form_kwargs = super().get_form_kwargs()
|
||||
# this lookup via VersionFiles ManyToManyManager returns the version that was created on
|
||||
# the previous step by create_version_from_file
|
||||
form_kwargs['instance'] = self.file.version.first()
|
||||
return form_kwargs
|
||||
|
||||
|
@ -18,11 +18,11 @@ class FileTest(TestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.file = FileFactory(
|
||||
status=File.STATUSES.AWAITING_REVIEW,
|
||||
original_name='test.zip',
|
||||
hash='foobar',
|
||||
size_bytes=7149,
|
||||
metadata={},
|
||||
original_name='test.zip',
|
||||
size_bytes=7149,
|
||||
status=File.STATUSES.AWAITING_REVIEW,
|
||||
)
|
||||
self.assertEqual(entries_for(self.file).count(), 0)
|
||||
self.assertIsNone(self.file.date_approved)
|
||||
|
Loading…
Reference in New Issue
Block a user