def test_delete_error_not_mine(self): """ 오류 - 해당 사용자의 코디가 아닐 시. """ # Create new user. created_user = UserFactory.create( username='******', password=make_password('test-password'), nickname='test-nickname-2', gender='남자', birthday='1996-01-14') # Create one clothes for new user. created_clothes = ClothesFactory.create( upper_category='상의', lower_category='반팔티셔츠', image_url='https://www.naver.com', alias='test-alias', created_at=timezone.now(), owner_id=created_user.id) # Create one clothes set for new user. new_clothes_set = ClothesSetFactory.create( name='test-name', style='화려', image_url='https://www.naver.com', created_at=timezone.now(), clothes=[created_clothes], owner=created_user) url = '/clothes-sets/' + str(new_clothes_set.id) + '/' response = self.client.delete(url) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
def setUp(self): # Create a user and log in. created_user = UserFactory.create( username='******', password=make_password('test-password'), nickname='test-nickname', gender='남자', birthday='1996-01-14') token_data = {'username': '******', 'password': '******'} response = self.client.post('/api/token/', token_data, format='json') access_token = response.data['access'] self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + access_token) # Create 10 Clothes for current user populate_clothes(10) # Create 3 ClothesSets for current user created_clothes_set = populate_clothes_set(3) # Create 1 ClothesSetReviews for current user self.created_review = populate_clothes_set_review(1)[0] self.clothes_set = created_clothes_set[0].id self.start_datetime = str(datetime(1996, 1, 14, 12, 0)) self.start_datetime = 'T'.join(self.start_datetime.split(' ')) self.end_datetime = str(datetime(1996, 1, 14, 21, 0)) self.end_datetime = 'T'.join(self.end_datetime.split(' ')) self.location = 1 self.review = 3 self.comment = 'test-comment'
def setUp(self): # Create a user and log in. created_user = UserFactory.create( username='******', password=make_password('test-password'), nickname='test-nickname', gender='남자', birthday='1996-01-14') token_data = {'username': '******', 'password': '******'} response = self.client.post('/api/token/', token_data, format='json') access_token = response.data['access'] self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + access_token) # Create 10 Clothes for current user created_clothes = populate_clothes(10) # Create 3 ClothesSets for current user self.created_clothes_set = populate_clothes_set(3) self.clothes = [] for clothe in created_clothes: self.clothes.append(clothe.id) if len(self.clothes) == 5: break self.name = 'test-name' self.style = '화려' self.image_url = 'https://www.naver.com'
def test_update_error_not_mine(self): """ 오류 - 해당 사용자의 코디가 아닐 시. """ # Create new user. created_user = UserFactory.create( username='******', password=make_password('test-password'), nickname='test-nickname-2', gender='남자', birthday='1996-01-14') # Create one clothes for new user. created_clothes = ClothesFactory.create( upper_category='상의', lower_category='반팔티셔츠', image_url='https://www.test_img.com', alias='test-alias', created_at=timezone.now(), owner_id=created_user.id) # Create one clothes set for new user. new_clothes_set = ClothesSetFactory.create(name=self.name, style=self.style, image_url=self.image_url, created_at=timezone.now(), clothes=[created_clothes], owner=created_user) data = {'name': 'new_name'} url = '/clothes-sets/' + str(new_clothes_set.id) + '/' response = self.client.patch(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) self.assertEqual(response.data['error'], 'you are not allowed to access this object')
def setUp(self): # Create a user and log in. created_user = UserFactory.create( username='******', password=make_password('test-password'), nickname='test-nickname', gender='남자', birthday='1996-01-14') token_data = {'username': '******', 'password': '******'} response = self.client.post('/api/token/', token_data, format='json') access_token = response.data['access'] self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + access_token) # Create 10 Clothes for current user created_clothes = populate_clothes(10) self.clothes = [] for clothe in created_clothes: self.clothes.append(clothe.id) if len(self.clothes) == 5: break self.name = 'test-name' self.style = '화려' with open("temp/sample_image.png", 'rb') as image: self.image = base64.b64encode(image.read())
def populate_users(number=10): fake = Faker('ko_KR') created_users = [] for i in range(number): while True: username = fake.user_name() if len(User.objects.all().filter(username=username)) == 0: break while True: nickname = fake.name() if len(User.objects.all().filter(nickname=nickname)) == 0: break password = make_password(''.join(fake.random_letters(length=8))) gender = fake.random_element(elements=('남자','여자')) birthday = fake.date_between(start_date='-30y', end_date='-20y') created = UserFactory.create( username=username, password=password, nickname=nickname, gender=gender, birthday=birthday ) created_users.append(created) return created_users
def test_retrieve_me(self): """ 내 리뷰 정보 반환 테스트. """ # Create new user. created_user = UserFactory.create( username='******', password=make_password('test-password'), nickname='test-nickname-2', gender='남자', birthday='1996-01-14') # Create one clothes for new user. created_clothes = ClothesFactory.create( upper_category='상의', lower_category='반팔티셔츠', image_url='https://www.test_img.com', alias='test-alias', created_at=timezone.now(), owner_id=created_user.id) # Create one clothes set for new user. new_clothes_set = ClothesSetFactory.create( name='test-name', style='화려', image_url='https://www.naver.com', created_at=timezone.now(), clothes=[created_clothes], owner=created_user) # Creates one clothes set review for new user. ClothesSetReviewFactory.create(start_datetime=self.start_datetime, end_datetime=self.end_datetime, location=self.location, review=self.review, max_temp=14.3, min_temp=2.4, max_sensible_temp=13.4, min_sensible_temp=0.6, humidity=40, wind_speed=5.2, precipitation=4, comment=self.comment, created_at=timezone.now(), clothes_set_id=new_clothes_set.id, owner=created_user) # Total Reviews : 4. response = self.client.get('/clothes-set-reviews/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['count'], 4) # Current User's Review sets : 3. response = self.client.get('/clothes-set-reviews/?me=True') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['count'], 3)
def test_update_error_not_mine(self): """ 오류 - 해당 사용자의 리뷰가 아닐 시. """ # Create new user. created_user = UserFactory.create( username='******', password=make_password('test-password'), nickname='test-nickname-2', gender='남자', birthday='1996-01-14') # Create one clothes for new user. created_clothes = ClothesFactory.create( upper_category='상의', lower_category='반팔티셔츠', image_url='https://www.test_img.com', alias='test-alias', created_at=timezone.now(), owner_id=created_user.id) # Create one clothes set for new user. new_clothes_set = ClothesSetFactory.create( name='test-name', style='화려', image_url='https://www.naver.com', created_at=timezone.now(), clothes=[created_clothes], owner=created_user) # Create one clothes set review for new user. new_review = ClothesSetReviewFactory.create( start_datetime=self.start_datetime, end_datetime=self.end_datetime, location=self.location, review=self.review, max_temp=14.3, min_temp=2.4, max_sensible_temp=13.4, min_sensible_temp=0.6, humidity=40, wind_speed=5.2, precipitation=4, comment=self.comment, created_at=timezone.now(), clothes_set_id=new_clothes_set.id, owner=created_user) data = {'comment': 'new comment'} url = '/clothes-set-reviews/' + str(new_review.id) + '/' response = self.client.patch(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) self.assertEqual(response.data['error'], 'you are not allowed to access this object')
def setUp(self): # Create a user and log in. created_user = UserFactory.create( username='******', password=make_password('test-password'), nickname='test-nickname', gender='남자', birthday='1996-01-14') token_data = {'username': '******', 'password': '******'} response = self.client.post('/api/token/', token_data, format='json') access_token = response.data['access'] self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + access_token) # Create 10 Clothes for current user. populate_clothes(10) # Create 3 Clothes Set for current user. created_clothes_set = populate_clothes_set(3) self.clothes_set = created_clothes_set[0].id self.start_datetime = str(datetime(1996, 1, 14, 12, 0)) self.start_datetime = 'T'.join(self.start_datetime.split(' ')) self.end_datetime = str(datetime(1996, 1, 14, 21, 0)) self.end_datetime = 'T'.join(self.end_datetime.split(' ')) self.location = 1 self.review = 3 self.comment = 'test-comment' # location_code, date, time, temp, sensible_temp, humidity, wind_speed, precipitation, x, y WeatherFactory.create(location_code=self.location, date='1996-01-14', time=14, temp=20, sensible_temp=20, humidity=30, wind_speed=1, precipitation=0, x=0, y=0) WeatherFactory.create(location_code=self.location, date='1996-01-14', time=17, temp=10, sensible_temp=10, humidity=50, wind_speed=3, precipitation=5, x=0, y=0)
def setUp(self): # Create a user and log in. created_user = UserFactory.create( username='******', password=make_password('test-password'), nickname='test-nickname', gender='남자', birthday='1996-01-14') token_data = {'username': '******', 'password': '******'} response = self.client.post('/api/token/', token_data, format='json') access_token = response.data['access'] self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + access_token) # Create 10 Clothes for current user populate_clothes(10) # Create 1 ClothesSets for current user self.created_clothes_set = populate_clothes_set(1)[0]
def test_retrieve_me(self): """ 내 코디 정보 반환 테스트. """ # Create new user. new_user = UserFactory.create(username='******', password=make_password('test-password'), nickname='test-nickname-2', gender='남자', birthday='1996-01-14') # Create one clothes for new user. new_clothes = ClothesFactory.create( upper_category='상의', lower_category='반팔티셔츠', image_url='https://www.test_img.com', alias='test-alias', created_at=timezone.now(), owner_id=new_user.id) # Create one clothes set for new user. ClothesSetFactory.create(name=self.name, style=self.style, image_url=self.image_url, created_at=timezone.now(), clothes=[new_clothes], owner=new_user) # Total Clothe sets : 4. response = self.client.get('/clothes-sets/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['count'], 4) # Current User's Clothes sets : 3. response = self.client.get('/clothes-sets/?me=True') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['count'], 3)