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

#360 Test for wrong redirects behaviour #381

Merged
merged 9 commits into from
Jul 7, 2018
Merged

Conversation

duker33
Copy link
Contributor

@duker33 duker33 commented Jun 22, 2018

Closes #360

@duker33 duker33 self-assigned this Jun 22, 2018
@duker33 duker33 requested a review from ArtemijRodionov June 22, 2018 09:58
@duker33 duker33 force-pushed the 360_fix_redirects branch 2 times, most recently from ca151d5 to a3c499b Compare June 22, 2018 13:25
@duker33 duker33 added the blocker this issue blocks another issue label Jun 22, 2018
# 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)
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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

# 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."""
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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)

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

discussed directly

@duker33 duker33 added the discuss issue needs to finish discussion before start working label Jul 1, 2018
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/'
Copy link
Contributor

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

Copy link
Contributor Author

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

# 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."""
Copy link
Contributor

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)

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

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?

@duker33 duker33 removed the discuss issue needs to finish discussion before start working label Jul 3, 2018
@duker33
Copy link
Contributor Author

duker33 commented Jul 3, 2018

discussed directly

@duker33 duker33 requested a review from ArtemijRodionov July 3, 2018 13:18
@duker33 duker33 force-pushed the 360_fix_redirects branch from 4636a94 to 7b80834 Compare July 3, 2018 13:19
@duker33 duker33 added the review waits for review label Jul 3, 2018
Copy link
Contributor

@ArtemijRodionov ArtemijRodionov left a 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
Copy link
Contributor

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

Copy link
Contributor Author

@duker33 duker33 Jul 3, 2018

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


# will be resurrected at rf#140
@unittest.expectedFailure
def test_redirect_on_existing_page(self):
Copy link
Contributor

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

Copy link
Contributor Author

@duker33 duker33 Jul 3, 2018

Choose a reason for hiding this comment

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

TO-DO

# 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."""
Copy link
Contributor

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

Copy link
Contributor Author

@duker33 duker33 Jul 3, 2018

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

@duker33 duker33 added refine issue already have resolving code, but code needs some fixes and removed review waits for review labels Jul 3, 2018
@duker33 duker33 requested a review from ArtemijRodionov July 3, 2018 17:43
@duker33 duker33 mentioned this pull request Jul 3, 2018
@duker33 duker33 force-pushed the 360_fix_redirects branch from 951054e to df2b032 Compare July 5, 2018 14:56
Copy link
Contributor

@ArtemijRodionov ArtemijRodionov left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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

@duker33 duker33 merged commit daee6d9 into master Jul 7, 2018
@duker33 duker33 deleted the 360_fix_redirects branch July 7, 2018 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker this issue blocks another issue refine issue already have resolving code, but code needs some fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants