• 
      

    Move `BaseWebAPITestCase._login_user` to `TestCase.login_user`.

    Review Request #15192 — Created July 23, 2026 and updated

    Information

    Review Board
    release-9.x

    Reviewers

    Our base class for API tests has a helper that can log in the test
    client, giving a couple knobs for whether the user should be an admin or
    part of a local host. We really ought to be using this more broadly (as
    opposed to just manually hardcoding usernames from our user fixtures),
    so I've relocated it to the base test case, renamed it to be
    not-private, and included a fallback for any third-party code that might
    use the old name. All of our references have been updated.

    Ran unit tests.

    Summary ID
    Move `BaseWebAPITestCase._login_user` to `TestCase.login_user`.
    Our base class for API tests has a helper that can log in the test client, giving a couple knobs for whether the user should be an admin or part of a local host. We really ought to be using this more broadly (as opposed to just manually hardcoding usernames from our user fixtures), so I've relocated it to the base test case, renamed it to be not-private, and included a fallback for any third-party code that might use the old name. All of our references have been updated. Testing Done: Ran unit tests.
    yrpmzylrpywkvonxskztmvmwwnlnwpwt
    Description From Last Updated

    I like the idea of a centralized login function that makes some common patterns easy, but I think if we're …

    chipx86 chipx86

    This is newly-added here, not changed.

    chipx86 chipx86
    Checks run (2 succeeded)
    flake8 passed.
    JSHint passed.
    chipx86
    1. 
        
    2. Show all issues

      I like the idea of a centralized login function that makes some common patterns easy, but I think if we're centralizing this, we should go just a step further by:

      1. Optionally allowing login of explicit users (handling LocalSite associations as needed).
      2. Allowing an explicit LocalSite instance, to constrain tests less and to not always require the fixtures for those tests that are managing custom LocalSite instances.

      Maybe this signature?

      def login_user(
          self,
          *,
          admin: bool = False,
          local_site: (bool | LocalSite) = False,
          username: (str | None) = None,
      ) -> User:
          ...
      

      Then we can continue to use it as-is, but can also specify an explicit username or LocalSite instance. That'll keep it more generally-useful without losing what made this convenient in API tests.

      The implementation would have to do the "create a proper user" steps outlined in the docstring if a username or custom local_site is provided, of course. But it could keep existing logic so existing tests don't break.

    3. reviewboard/testing/testcase.py (Diff revision 1)
       
       
       
      Show all issues

      This is newly-added here, not changed.

    4.