Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 Like Button #111

Merged
merged 4 commits into from
May 12, 2022
Merged

🚀 Like Button #111

merged 4 commits into from
May 12, 2022

Conversation

paOmer
Copy link
Collaborator

@paOmer paOmer commented Apr 16, 2022

Setting up the like button.

  • Added the like button functionality in the feed/views.py file.
  • Set a like URL which include the post to like ID
  • Links the existing dummy like button to the url
  • Added tests

Only an authenticated user can like a post.

Future Improvements:

Close #110

Copy link
Collaborator

@ShirleyFichman ShirleyFichman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@DeanBiton DeanBiton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good
👍

feed/views.py Outdated Show resolved Hide resolved
feed/tests/test_feed_views.py Outdated Show resolved Hide resolved
@paOmer paOmer force-pushed the like branch 2 times, most recently from 98d73e3 to 2217eb1 Compare April 20, 2022 16:59
@paOmer paOmer requested a review from Yarboa April 20, 2022 17:02
Copy link
Contributor

@Yarboa Yarboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@paOmer paOmer force-pushed the like branch 2 times, most recently from f2be968 to ec66e12 Compare April 23, 2022 09:40
@paOmer
Copy link
Collaborator Author

paOmer commented Apr 23, 2022

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.

Copy link
Contributor

@Yarboa Yarboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feed/tests/test_feed_views.py Outdated Show resolved Hide resolved
feed/tests/test_feed_views.py Outdated Show resolved Hide resolved
@paOmer paOmer requested a review from Yarboa April 28, 2022 11:18
feed/tests/test_feed_views.py Outdated Show resolved Hide resolved
feed/tests/test_feed_views.py Outdated Show resolved Hide resolved
feed/tests/test_feed_views.py Show resolved Hide resolved
@paOmer
Copy link
Collaborator Author

paOmer commented May 1, 2022

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.

@paOmer paOmer requested a review from Yarboa May 1, 2022 15:00
@Yarboa
Copy link
Contributor

Yarboa commented May 1, 2022

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
Copy link
Collaborator Author

paOmer commented May 2, 2022

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
Copy link
Contributor

Yarboa commented May 4, 2022

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)

Copy link
Collaborator

@amittcohen amittcohen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@paOmer
Copy link
Collaborator Author

paOmer commented May 8, 2022

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.

@Yarboa Yarboa merged commit abe6286 into redhat-beyond:main May 12, 2022
@paOmer paOmer deleted the like branch May 15, 2022 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 Like Button
5 participants