Skip to content

Commit

Permalink
추가: search 앱 팩토리 작업
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahayana committed Nov 8, 2023
1 parent 468b559 commit 2a0d629
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/search/factories.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2a0d629

Please sign in to comment.