Refactor Extension and Version: explicit constructors from File #191
@ -7,7 +7,7 @@ import factory
|
||||
import factory.fuzzy
|
||||
|
||||
from common.tests.factories.files import FileFactory
|
||||
from extensions.models import Extension, Version, Tag, Preview, Platform
|
||||
from extensions.models import Extension, Version, Preview
|
||||
from ratings.models import Rating
|
||||
|
||||
fake_markdown = Faker()
|
||||
@ -57,69 +57,6 @@ class RatingFactory(DjangoModelFactory):
|
||||
extension = factory.LazyAttribute(lambda o: o.version.extension)
|
||||
|
||||
|
||||
class VersionFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = Version
|
||||
|
||||
extension = factory.SubFactory(ExtensionFactory)
|
||||
version = factory.LazyAttribute(
|
||||
lambda _: f'{random.randint(0, 9)}.{random.randint(0, 9)}.{random.randint(0, 9)}'
|
||||
)
|
||||
blender_version_min = factory.fuzzy.FuzzyChoice(
|
||||
{'2.83.1', '2.93.0', '2.93.8', '3.0.0', '3.2.1'}
|
||||
)
|
||||
download_count = factory.Faker('random_int')
|
||||
tagline = factory.Faker('bs')
|
||||
|
||||
file = factory.SubFactory(
|
||||
'common.tests.factories.files.FileFactory',
|
||||
metadata=factory.Dict(
|
||||
{
|
||||
'name': factory.Faker('name'),
|
||||
'support': factory.Faker('url'),
|
||||
'website': factory.Faker('url'),
|
||||
}
|
||||
),
|
||||
)
|
||||
ratings = factory.RelatedFactoryList(
|
||||
RatingFactory, size=lambda: random.randint(0, 5), factory_related_name='version'
|
||||
)
|
||||
|
||||
@factory.post_generation
|
||||
def files(self, create, extracted, **kwargs):
|
||||
if not create:
|
||||
return
|
||||
|
||||
if not extracted:
|
||||
self.files.add(self.file)
|
||||
return
|
||||
|
||||
for file in extracted:
|
||||
self.files.add(file)
|
||||
|
||||
@factory.post_generation
|
||||
def platforms(self, create, extracted, **kwargs):
|
||||
if not create:
|
||||
return
|
||||
|
||||
if not extracted:
|
||||
return
|
||||
|
||||
platforms = Platform.objects.filter(slug__in=extracted)
|
||||
self.platforms.add(*platforms)
|
||||
|
||||
@factory.post_generation
|
||||
def tags(self, create, extracted, **kwargs):
|
||||
if not create:
|
||||
return
|
||||
|
||||
if not extracted:
|
||||
return
|
||||
|
||||
tags = Tag.objects.filter(name__in=extracted)
|
||||
self.tags.add(*tags)
|
||||
|
||||
|
||||
def create_version(**kwargs) -> 'Version':
|
||||
extension = kwargs.pop('extension', None)
|
||||
file = kwargs.pop('file', None)
|
||||
|
@ -58,6 +58,7 @@ def construct_fake_notifications() -> list['NotificationFactory']:
|
||||
),
|
||||
Verb.DISMISSED_ABUSE_REPORT: None,
|
||||
Verb.RATED_EXTENSION: RatingFactory.build(
|
||||
extension=fake_extension,
|
||||
text=fake.paragraph(nb_sentences=2),
|
||||
),
|
||||
Verb.REPORTED_EXTENSION: None, # TODO: fake action_object
|
||||
|
@ -6,8 +6,6 @@ from django.test import TestCase
|
||||
from common.tests.factories.extensions import create_approved_version
|
||||
from stats.models import ExtensionView, ExtensionDownload, ExtensionCountedStat
|
||||
|
||||
# TODO: tests for VersionFactory Version download_count
|
||||
|
||||
|
||||
class WriteStatsCommandTest(TestCase):
|
||||
fixtures = ['dev', 'licenses']
|
||||
|
Loading…
Reference in New Issue
Block a user