-
Notifications
You must be signed in to change notification settings - Fork 5
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
#360 Test for wrong redirects behaviour #381
Conversation
ca151d5
to
a3c499b
Compare
shopelectro/tests/tests_views.py
Outdated
# take some existing `url_from` | ||
url_from = '/catalog/categories/category-0/tags/6-v/' | ||
response = self.client.get(url_from) | ||
self.assertEqual(response.status_code, 200) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is an unnecessary assertion, we should test only redirect logic here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@artemiy312 , it's specific of this test case.
django.contrib.redirects
provide different behaviour if url_from
returns 200 or 404
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@duker33 but we already test it in other tests, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@artemiy312 , it's new test, that fails.
Maybe we touch redirects in some way in different code. In products scope, for example.
But it's doesn't matter for this task.
Here we test mech for redirects concept itself
shopelectro/tests/tests_views.py
Outdated
# will be resurrected at rf#140 | ||
@unittest.expectedFailure | ||
def test_redirect_on_existing_page(self): | ||
"""DB based redirect from existing url should do, but should not avoid it.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a test is too big and complicated. Let's divide it into smaller pieces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@artemiy312 , it's single test case.
Do test this case, we should check two things:
url_from returns 200
and url_to returns 301
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@duker33 We can test it separate.
self.redirect = Redirect.objects.create( # also we may move it to fixtures
site=Site.objects.first(),
old_path=url_from,
new_path=url_to
)
def test_redirect_301(self):
self.assertEqual(self.client.get(self.redirect.old_path).status_code, 300)
def test_following_redirect_200(self):
self.assertEqual(self.client.get(self.redirect.old_path, follow=True).status_code, 200)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@artemiy312 , url_from
should not return 200 in all cases. Only for our single case.
So, this two methods have strong semantical binding. They both mean nothing in separate.
For a different test case, we should create a different test class.
Big test method's size doesn't look bad for me. It consists of simple and sequential steps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed directly
shopelectro/tests/tests_views.py
Outdated
def test_redirect_on_existing_page(self): | ||
"""DB based redirect from existing url should do, but should not avoid it.""" | ||
# take some existing `url_from` | ||
url_from = '/catalog/categories/category-0/tags/6-v/' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get a category's url from Model: Category.objects.first().url
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@artemiy312 , here i should take not the first category. But the one, that has at least one tag.
And it'll be too complex to take it. We have fixtures in cvs, so we can completely rely on them in code
shopelectro/tests/tests_views.py
Outdated
# will be resurrected at rf#140 | ||
@unittest.expectedFailure | ||
def test_redirect_on_existing_page(self): | ||
"""DB based redirect from existing url should do, but should not avoid it.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@duker33 We can test it separate.
self.redirect = Redirect.objects.create( # also we may move it to fixtures
site=Site.objects.first(),
old_path=url_from,
new_path=url_to
)
def test_redirect_301(self):
self.assertEqual(self.client.get(self.redirect.old_path).status_code, 300)
def test_following_redirect_200(self):
self.assertEqual(self.client.get(self.redirect.old_path, follow=True).status_code, 200)
shopelectro/tests/tests_views.py
Outdated
# take some existing `url_from` | ||
url_from = '/catalog/categories/category-0/tags/6-v/' | ||
response = self.client.get(url_from) | ||
self.assertEqual(response.status_code, 200) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@duker33 but we already test it in other tests, isn't it?
discussed directly |
4636a94
to
7b80834
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A wrong version number of refarm-site
requirements.txt
Outdated
sorl-thumbnail==12.4a1 | ||
https://github.com/selwin/django-user_agents/archive/master.zip | ||
https://github.com/fidals/refarm-site/archive/0.1.6.zip | ||
https://github.com/fidals/refarm-site/archive/0.1.3.zip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a wrong version number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.1.6
fails, as i remember. I'll check it TO-DO
shopelectro/tests/tests_views.py
Outdated
|
||
# will be resurrected at rf#140 | ||
@unittest.expectedFailure | ||
def test_redirect_on_existing_page(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe test_redirect_from_existing_page
will be more relevant. decide by yourself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TO-DO
shopelectro/tests/tests_views.py
Outdated
# will be resurrected at rf#140 | ||
@unittest.expectedFailure | ||
def test_redirect_on_existing_page(self): | ||
"""DB based redirect from existing url should do, but should not avoid it.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""DB based redirect from existing url should do, but should not avoid it."""
->
"""Redirect middleware of refarm-site redirects from existing url too"""
decide by yourself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refarm-site's custom redirects app should redirect from existing url too
TO-DO
951054e
to
df2b032
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refarm-site version
tblib==1.3.2 | ||
Unidecode==1.0.22 | ||
ua-parser==0.8.0 | ||
user-agents==1.1.0 | ||
sorl-thumbnail==12.4a1 | ||
https://github.com/selwin/django-user_agents/archive/master.zip | ||
https://github.com/fidals/refarm-site/archive/0.1.6.zip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to bump the refarm-site version to 0.1.7, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@artemiy312 , nope, 0.1.7 was created after this code
Closes #360