def test_update(self):
        self.login()
        response = self.client.put(self.UPDATE_URL, UPDATE_DATA, format='json')
        self.assert_200_OK(response)
        self.client.force_authenticate()

        expected = UPDATE_DATA['user'].copy()
        assert self.user_1.email == expected['email']
        assert self.user_1.check_password(expected['password'])

        login_data = {
            'user': {
                'email': expected['email'],
                'password': expected['password']
            }
        }

        user = JwtUser.objects.get_by_natural_key(expected['email'])
        assert self.user_1.email == user.email
        assert user.check_password(expected['password'])

        assert authenticate(username=expected['email'],
                            password=expected['password']) is not None

        del expected['password']
        self.check_item_body(parse_body(response), {'user': expected})

        login_response = self.login_response_with(login_data)
        self.assert_200_OK(login_response)
        assert 'token' in parse_body(login_response)['user']
    def test_article_feed(self):
        self.login()
        response = self.client.get('/api/articles/feed/')
        self.assert_200_OK(response)
        assert len(parse_body(response)['articles']) == 0

        follow_response = self.client.post(
            f"/api/profiles/{self.user_2.username}/follow")
        self.assert_201_created(follow_response)

        after_response = self.client.get('/api/articles/feed/')
        self.assert_200_OK(after_response)
        articles_after = parse_body(after_response)['articles']
        assert len(articles_after) == 1
        assert articles_after[0]['title'] == self.article_2.title
    def test_list_article_by_author_stelo(self):
        response = self.client.get(ARTICLE_URL, {'author': 'stelo'})
        self.assert_200_OK(response)

        articles_body = parse_body(response)['articles']
        assert len(articles_body) == 1
        assert articles_body[0]['title'] == ARTICLE_1['title']
 def test_retrieve(self):
     self.login()
     response = self.client.get(self.UPDATE_URL)
     self.assert_200_OK(response)
     expected = REGISTER_DATA['user'].copy()
     del expected['password']
     self.check_item(parse_body(response)['user'], expected)
 def test_update_article(self):
     self.login()
     response = self.client.put(self.SLUG_ARTICLE_URL,
                                UPDATE_DATA,
                                format='json')
     self.assert_200_OK(response)
     self.check_item_body(parse_body(response), UPDATE_DATA.copy())
 def test_list_article_by_tag(self):
     response = self.client.get(ARTICLE_URL, {'tag': 'react'})
     self.assert_200_OK(response)
     articles_body = parse_body(response)['articles']
     self.check_sorted_list_body(
         articles_body,
         [ARTICLE_1],  # 제목 역순
         key='title')
 def test_article_favorite(self):
     self.login()
     response = self.client.post(self.FAVORITE_URL)
     self.assert_201_created(response)
     expected = RETRIEVE_EXPECTED['article'].copy()
     expected['favorited'] = True
     expected['favoritesCount'] = 1
     self.check_item(parse_body(response)['article'], expected)
    def test_article_unfavorite(self):
        self.login()
        response = self.client.post(self.FAVORITE_URL)
        self.assert_201_created(response)

        response = self.client.delete(self.FAVORITE_URL)
        self.assert_200_OK(response)
        expected = RETRIEVE_EXPECTED['article'].copy()
        self.check_item(parse_body(response)['article'], expected)
Ejemplo n.º 9
0
 def test_retrieve_profile(self):
     response = self.client.get(self.PROFILE_URL)
     self.assert_200_OK(response)
     expected = {
         'username': "******",
         'bio': '',
         'image':
         'https://static.productionready.io/images/smiley-cyrus.jpg',
         'following': False,
     }
     assert parse_body(response)["profile"] == expected
    def test_list_article_by_favorited_by(self):
        self.login()
        response = self.client.post(self.FAVORITE_URL)
        self.assert_201_created(response)

        response = self.client.get(ARTICLE_URL, {'favorited': 'stelo'})
        self.assert_200_OK(response)
        articles_body = parse_body(response)['articles']
        self.check_sorted_list_body(
            articles_body,
            [ARTICLE_1],  # 제목 역순
            key='title')
 def register(self):
     response = self.client.post(REGISTER_URL, REGISTER_DATA, format='json')
     assert response.status_code == status.HTTP_201_CREATED
     return parse_body(response)
 def test_register(self):
     response = self.client.post(REGISTER_URL,
                                 REGISTER_DATA_2,
                                 format='json')
     self.assert_201_created(response)
     assert 'token' in parse_body(response)['user']
 def test_retrieve_article(self):
     response = self.client.get(self.SLUG_ARTICLE_URL)
     self.assert_200_OK(response)
     self.check_item_body(parse_body(response), RETRIEVE_EXPECTED)
 def test_login_without_email(self):
     data = self.get_login_data_without('email')
     response = self.login_response_with(data)
     self.assert_400_BAD_REQUEST(response)
     assert 'email' in parse_body(response)['errors']
 def test_tag_list(self):
     response = self.client.get(TAG_URL)
     self.assert_200_OK(response)
     assert set(
         parse_body(response)['tags']) == {'react', '태그', 'django', '태그4'}
Ejemplo n.º 16
0
 def test_list_comments(self):
     response = self.client.get(self.COMMENT_URL)
     self.assert_200_OK(response)
     self.check_sorted_list_body(parse_body(response)['comments'],
                                 self.LIST_EXPECTED,
                                 key='body')
Ejemplo n.º 17
0
 def get_following(follow_response):
     return parse_body(follow_response)["profile"]['following']
Ejemplo n.º 18
0
 def test_create_comment(self):
     self.login()
     response = self.request_create_comment(self.COMMENT_URL)
     self.assert_201_created(response)
     self.check_item_body(parse_body(response), CREATE_DATA)
 def test_login(self):
     response = self.login_response_with(REGISTER_DATA)
     self.assert_200_OK(response)
     assert 'token' in parse_body(response)['user']
Ejemplo n.º 20
0
 def test_list_comments_wrong_article(self):
     wrong_url = ARTICLE_URL + '/wrong/comments/'
     response = self.client.get(wrong_url)
     self.assert_200_OK(response)
     assert parse_body(response) == {'comments': [], 'commentsCount': 0}
 def test_create_article(self):
     self.login()
     response = self.client.post(ARTICLE_URL, CREATE_DATA, format='json')
     self.assert_201_created(response)
     self.check_item_body(parse_body(response), CREATE_DATA.copy())