Refactor Extension and Version: explicit constructors from File #191

Merged
Oleg-Komarov merged 6 commits from refactor-models into main 2024-06-20 14:40:41 +02:00
3 changed files with 2 additions and 66 deletions
Showing only changes of commit c6ba74c76d - Show all commits

View File

@ -7,7 +7,7 @@ import factory
import factory.fuzzy import factory.fuzzy
from common.tests.factories.files import FileFactory 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 from ratings.models import Rating
fake_markdown = Faker() fake_markdown = Faker()
@ -57,69 +57,6 @@ class RatingFactory(DjangoModelFactory):
extension = factory.LazyAttribute(lambda o: o.version.extension) 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': def create_version(**kwargs) -> 'Version':
extension = kwargs.pop('extension', None) extension = kwargs.pop('extension', None)
file = kwargs.pop('file', None) file = kwargs.pop('file', None)

View File

@ -58,6 +58,7 @@ def construct_fake_notifications() -> list['NotificationFactory']:
), ),
Verb.DISMISSED_ABUSE_REPORT: None, Verb.DISMISSED_ABUSE_REPORT: None,
Verb.RATED_EXTENSION: RatingFactory.build( Verb.RATED_EXTENSION: RatingFactory.build(
extension=fake_extension,
text=fake.paragraph(nb_sentences=2), text=fake.paragraph(nb_sentences=2),
), ),
Verb.REPORTED_EXTENSION: None, # TODO: fake action_object Verb.REPORTED_EXTENSION: None, # TODO: fake action_object

View File

@ -6,8 +6,6 @@ from django.test import TestCase
from common.tests.factories.extensions import create_approved_version from common.tests.factories.extensions import create_approved_version
from stats.models import ExtensionView, ExtensionDownload, ExtensionCountedStat from stats.models import ExtensionView, ExtensionDownload, ExtensionCountedStat
# TODO: tests for VersionFactory Version download_count
class WriteStatsCommandTest(TestCase): class WriteStatsCommandTest(TestCase):
fixtures = ['dev', 'licenses'] fixtures = ['dev', 'licenses']