redhat-beyond / JobSeeker

https://github.com/redhat-beyond/JobSeeker
MIT License
2 stars 5 forks source link

🚀 Like Button #111

Closed paOmer closed 2 years ago

paOmer commented 2 years ago

Setting up the like button.

Only an authenticated user can like a post.

Future Improvements:

Close #110

paOmer commented 2 years ago

the way authenticate is used here should be revised https://docs.djangoproject.com/en/4.0/topics/auth/default/#authenticating-users It is a low level authentication, Dont you think the logic should be done ins the App side?

Updated, you could find the updates in the test file added to this PR in lines 139 and 157. Hope that I understood correctly.

paOmer commented 2 years ago

Hi @Yarboa, Changed the tests to assert content of the response context. Also added another test test_after_like_redirect_to_detail_view to check redirection after success like when HTML REFFER is disabled, but couldn't figure out how or if to check redirection when HTML REFFER is allowed.

Yarboa commented 2 years ago

Hi @Yarboa, Changed the tests to assert content of the response context. Also added another test test_after_like_redirect_to_detail_view to check redirection after success like when HTML REFFER is disabled, but couldn't figure out how or if to check redirection when HTML REFFER is allowed.

You should run another request with client to the redirect URL you should reach the redirected page, with 200OK and context

paOmer commented 2 years ago

Hi @Yarboa, Changed the tests to assert content of the response context. Also added another test test_after_like_redirect_to_detail_view to check redirection after success like when HTML REFFER is disabled, but couldn't figure out how or if to check redirection when HTML REFFER is allowed.

You should run another request with client to the redirect URL you should reach the redirected page, with 200OK and context

I've added the 200 status code in the test_like_url_unlikes test. And I also have this test:

def test_after_like_redirect_to_detail_view(self, post, logged_in_client):
        # Testing that after successful like, if the user got to the like URL
        # by typing it, he would get redirected to the post detail view page.
        # Also, if a user turned off the HTTP_REFERER option in his browser he would
        # get returned to the post detail view
        response = logged_in_client.get(post_like_url(post.id))
        assert response.status_code == REDIRECT_URL_STATUS
        assert response.url == POST_DETAIL_URL + f'{post.id}/'

But I think there is another test missing and I cant figure out how to set it, I tried:

def test(self, post, logged_in_client):
        logged_in_client.get(FEED_URL)
        response = logged_in_client.get(post_like_url(post.id))
        assert response.url == FEED_URL

but I dont get the feed to be the response.url, I get the post detail view as the test before. What im trying to test here are lines 57-59 in the feed/views.py:

 origin_url = request.META.get('HTTP_REFERER')
 if origin_url is not None:
        return HttpResponseRedirect(origin_url)
Yarboa commented 2 years ago

Hi @Yarboa, Changed the tests to assert content of the response context. Also added another test test_after_like_redirect_to_detail_view to check redirection after success like when HTML REFFER is disabled, but couldn't figure out how or if to check redirection when HTML REFFER is allowed.

You should run another request with client to the redirect URL you should reach the redirected page, with 200OK and context

I've added the 200 status code in the test_like_url_unlikes test. And I also have this test:

def test_after_like_redirect_to_detail_view(self, post, logged_in_client):
        # Testing that after successful like, if the user got to the like URL
        # by typing it, he would get redirected to the post detail view page.
        # Also, if a user turned off the HTTP_REFERER option in his browser he would
        # get returned to the post detail view
        response = logged_in_client.get(post_like_url(post.id))
        assert response.status_code == REDIRECT_URL_STATUS
        assert response.url == POST_DETAIL_URL + f'{post.id}/'

But I think there is another test missing and I cant figure out how to set it, I tried:

def test(self, post, logged_in_client):
        logged_in_client.get(FEED_URL)
        response = logged_in_client.get(post_like_url(post.id))
        assert response.url == FEED_URL

but I dont get the feed to be the response.url, I get the post detail view as the test before. What im trying to test here are lines 57-59 in the feed/views.py:

 origin_url = request.META.get('HTTP_REFERER')
 if origin_url is not None:
        return HttpResponseRedirect(origin_url)

Just review the UI talk, you have those sample tests. Once you received redirect url, you should call from the client again

response = client.get('/posts') assert response.status_code == 301 response = client.get(response.url) assert response.status_code == 200 assert isinstance(response.context['blog_list'], list)

paOmer commented 2 years ago

Hi @Yarboa, Changed the tests to assert content of the response context. Also added another test test_after_like_redirect_to_detail_view to check redirection after success like when HTML REFFER is disabled, but couldn't figure out how or if to check redirection when HTML REFFER is allowed.

You should run another request with client to the redirect URL you should reach the redirected page, with 200OK and context

I've added the 200 status code in the test_like_url_unlikes test. And I also have this test:

def test_after_like_redirect_to_detail_view(self, post, logged_in_client):
        # Testing that after successful like, if the user got to the like URL
        # by typing it, he would get redirected to the post detail view page.
        # Also, if a user turned off the HTTP_REFERER option in his browser he would
        # get returned to the post detail view
        response = logged_in_client.get(post_like_url(post.id))
        assert response.status_code == REDIRECT_URL_STATUS
        assert response.url == POST_DETAIL_URL + f'{post.id}/'

But I think there is another test missing and I cant figure out how to set it, I tried:

def test(self, post, logged_in_client):
        logged_in_client.get(FEED_URL)
        response = logged_in_client.get(post_like_url(post.id))
        assert response.url == FEED_URL

but I dont get the feed to be the response.url, I get the post detail view as the test before. What im trying to test here are lines 57-59 in the feed/views.py:

 origin_url = request.META.get('HTTP_REFERER')
 if origin_url is not None:
        return HttpResponseRedirect(origin_url)

Just review the UI talk, you have those sample tests. Once you received redirect url, you should call from the client again

response = client.get('/posts') assert response.status_code == 301 response = client.get(response.url) assert response.status_code == 200 assert isinstance(response.context['blog_list'], list)

Thanks Done, also moved the like count to a fixture.