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

tests fail with german locale #608

Open
crosspolar opened this issue Jan 5, 2025 · 5 comments
Open

tests fail with german locale #608

crosspolar opened this issue Jan 5, 2025 · 5 comments

Comments

@crosspolar
Copy link
Contributor

I guess because I have a German Locale, some tests comparing messages fail, for example:

 tapir/coop/tests/membership_resignation/test_form.py14% █▍        

―――――――――――――――――――――――――――――――――――――――――――――――――――――――― TestMembershipResignationForm.test_validateTransferChoice_resignationTypeTransferButNoRecipient_errorIsAddedToForm ――――――――――――――――――――――――――――――――――――――――――――――――――――――――

self = <tapir.coop.tests.membership_resignation.test_form.TestMembershipResignationForm testMethod=test_validateTransferChoice_resignationTypeTransferButNoRecipient_errorIsAddedToForm>

    def test_validateTransferChoice_resignationTypeTransferButNoRecipient_errorIsAddedToForm(
        self,
    ):
        share_owner = ShareOwnerFactory.create()
        form = MembershipResignationForm(
            data={
                "share_owner": share_owner,
                "resignation_type": MembershipResignation.ResignationType.TRANSFER,
            }
        )
        self.assertIn("transferring_shares_to", form.errors.keys())
>       self.assertIn(
            "Please select the member that the shares should be transferred to.",
            form.errors["transferring_shares_to"],
        )
E       AssertionError: 'Please select the member that the shares should be transferred to.' not found in ['Bitte wähle ein Mitglied an welches die Anteile überwiesen werden sollen']

tapir/coop/tests/membership_resignation/test_form.py:65: AssertionError

In total these three:

     569 passed
       3 failed
         - tapir/coop/tests/membership_resignation/test_form.py:92 TestMembershipResignationForm.test_validateGiftingMemberAndReceivingMemberAreNotTheSame_giftingAndReceivingMembersAreTheSame_errorIsAddedToForm
         - tapir/coop/tests/membership_resignation/test_form.py:70 TestMembershipResignationForm.test_validateTransferChoice_resignationTypeNotTransferButRecipientSent_errorIsAddedToForm
         - tapir/coop/tests/membership_resignation/test_form.py:54 TestMembershipResignationForm.test_validateTransferChoice_resignationTypeTransferButNoRecipient_errorIsAddedToForm
@Theophile-Madet
Copy link
Contributor

I get the same errors, both on master and on #559, so it must be a general thing rather that linked to the locale on your machine.
We didn't get those errors before, neither locally or on the github actions, so there must be something deterministic about it, but I don't know what.

Could you add translation.activate("en") to the corresponding tests, or to the setUp of that test class?

@crosspolar
Copy link
Contributor Author

It's because I translated the respective sentence recently in d2d5b66#diff-47e0a4d998e7e37cf9f5390e3f39c7e5adf8e11eb7e45224092a56fd0e79b0deR647

@crosspolar
Copy link
Contributor Author

this works. Do we have tests depending on translations or should we go for a more general solution?

@crosspolar
Copy link
Contributor Author

and do we have to reset the language as stated here? https://docs.djangoproject.com/en/5.1/topics/testing/tools/#setting-the-language

@Theophile-Madet
Copy link
Contributor

It's because I translated the respective sentence recently in d2d5b66#diff-47e0a4d998e7e37cf9f5390e3f39c7e5adf8e11eb7e45224092a56fd0e79b0deR647

But then the tests in the github actions should have failed since then? I'm not sure how they can be green 🤔

For requests where a used is logged in, we set the language in tapir.accounts.models.language_middleware.
I we want to check something in the response, I think the user that is logged in should have the expected language. I'm not sure which is better:

  • set the field value to a hardcoded "en" in the factory class
  • set the preferred_language explicitely when calling the ShareOwnerFactory, only in the tests that check for text

For the tests that you noticed were failing, there is no logged in user, though the question is kind of the same, we can either:

  • add translation.activate("en") to the setUp of TapirFactoryTestBase
  • add it only to the relevant classes instead

I'm a bit more in favor of adding it only where it's relevant, so the second option in both cases. Do you have an opinion?

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

No branches or pull requests

2 participants