TIL(22.12.19) - Django testcode 더미데이터 생성하기

이지영·2022년 12월 19일
0

TIL/WIL

목록 보기
94/110
post-custom-banner
# 더미데이터 생성
from faker import Faker

class ReviewRankReadTest(APITestCase):
    @classmethod
    def setUpTestData(cls):
        cls.faker = Faker()
        cls.reviews=[]
        cls.place = Place.objects.create(place_name="장소명", rating="5", category="카테고리", place_address="주소", place_time="시간", place_img="이미지")
        for i in range(2):
            cls.user_data = {'username':cls.faker.name(), 'password':cls.faker.word()}
            cls.user = User.objects.create_user(cls.faker.name(), cls.faker.email(), cls.faker.name(), cls.faker.word())
            Profile.objects.create(user=cls.user)
            cls.reviews.append(Review.objects.create(content=cls.faker.text(), rating_cnt=cls.faker.pyint(min_value=0, max_value=5), author=cls.user, place=cls.place))
    
    def test_get_review_rank(self):
        for review in self.reviews:
            response = self.client.get(
                path=reverse("reveiw_rank_view"))
            print(review) 
# print(review)

[작성자][아이디]Juan Gomez, [내용]Hot buy plan beat way perhaps instead.
Instead have send wind. Since until approach his hotel enjoy happy.
[작성자][아이디]Dalton Miller, [내용]Least wind stop recently. Require score community thank.
Why national participant ahead study moment. Hundred article movement move role record economic

랜덤으로 review를 작성해준다!
id -> faker.name()
password -> faker.word()

profile
🐶🦶📏
post-custom-banner

0개의 댓글