From 2a0d6298e5bc5c5dca3e0162416f4137aff6a414 Mon Sep 17 00:00:00 2001 From: sahayana Date: Wed, 8 Nov 2023 21:35:55 +0400 Subject: [PATCH] =?UTF-8?q?=EC=B6=94=EA=B0=80:=20search=20=EC=95=B1=20?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A6=AC=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/search/factories.py | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tests/search/factories.py b/tests/search/factories.py index e69de29..218b0d6 100644 --- a/tests/search/factories.py +++ b/tests/search/factories.py @@ -0,0 +1,70 @@ +import factory +from factory.faker import faker + +from apps.account.utils import random_string_generator +from apps.search.models import Book, News, Shopping, Youtube +from tests.account.factories import UserFactory + +fake = faker.Faker() + + +class YoutubeFactory(factory.django.DjangoModelFactory): + class Meta: + model = Youtube + + user = factory.SubFactory(UserFactory) + url = factory.LazyAttribute( + lambda o: f"https://youtube.com/{random_string_generator(10)}" + ) + title = factory.Faker(provider="sentence", locale="en_US", nb_words=5) + views = "100" + + +class NewsFactory(factory.django.DjangoModelFactory): + class Meta: + model = News + + user = factory.SubFactory(UserFactory) + title = factory.Faker(provider="sentence", nb_words=10, locale="en_US") + date = "2023-11-08" + company = factory.Faker(provider="company", locale="ko_KR") + thumbnail = fake.image_url() + link = factory.LazyAttribute( + lambda o: faker.Faker().url() + f"{random_string_generator(10)}" + ) + + @factory.lazy_attribute + def content(self): + c = "" + for _ in range(0, 5): + c += "\n" + fake.paragraph(nb_sentences=10) + "\n" + return c + + +class BookFactory(factory.django.DjangoModelFactory): + class Meta: + model = Book + + user = factory.SubFactory(UserFactory) + title = factory.Faker(provider="sentence", locale="en_US", nb_words=2) + price = "15000" + author = factory.Faker(provider="name", locale="ko_KR") + company = factory.Faker(provider="company", locale="ko_KR") + thumbnail = fake.image_url() + link = factory.LazyAttribute( + lambda o: faker.Faker().url() + f"{random_string_generator(10)}" + ) + series = "fantasy" + + +class ShoppingFactory(factory.django.DjangoModelFactory): + class Meta: + model = Shopping + + user = factory.SubFactory(UserFactory) + price = "15000" + thumbnail = fake.image_url() + link = factory.LazyAttribute( + lambda o: faker.Faker().url() + f"{random_string_generator(10)}" + ) + title = factory.Faker(provider="sentence", locale="en_US", nb_words=2)