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

Fix 262 tests #277

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Fix 262 tests #277

wants to merge 4 commits into from

Conversation

allcaps
Copy link
Member

@allcaps allcaps commented Nov 18, 2022

No description provided.

…o that we have access to the url resolver. Then check if the requested path belongs to i18n_patterns.
@allcaps allcaps force-pushed the fix-262-tests branch 3 times, most recently from 2e602a5 to 373d83b Compare November 21, 2022 08:41
@allcaps
Copy link
Member Author

allcaps commented Nov 21, 2022

@saevarom Can you have a look at this one?

Comment on lines +15 to +28
if (
request.path == "/"
or request.resolver_match
and pattern.match(request.resolver_match.route)
):
try:
HomePage.objects.get(locale__language_code=get_language(), live=True)
response = self.get_response(request)
except HomePage.DoesNotExist:
# The requested language is not available, use the default
activate(settings.LANGUAGE_CODE)
response = self.get_response(request)
else:
response = self.get_response(request)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you call the resolver before get_response you will always have None, so this code defaults to the else statement every single time. I ran the tests with a print statement in the else section and it printed every time.

I also tried to set my language to a language that had a matching homepage and it did not properly set my preferred language until I put the response = self.get_response(request) at the top.

I see that you removed the 404 response when a language does not exist, was there a reason for that?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why the tests do not fail on the language preference, but at least it was not working in the browser for me

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the tests that correctly pass when a user asks for "/" and is redirected to the preferred language (browser or cookie) because of LocaleMiddleware

Copy link
Contributor

Choose a reason for hiding this comment

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

So, I guess we need to take a step back and actually think about what the requirements are

Copy link
Contributor

@saevarom saevarom left a comment

Choose a reason for hiding this comment

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

See comments in middleware

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.

2 participants