• 
      

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

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

    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

    Can you mention how this can be a LocalSite too.

    maubin maubin

    I think we'll also need to add doc as a user to the local site that gets passed in, because …

    maubin maubin

    Missing a trailing comma.

    chipx86 chipx86
    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. 
        
    david
    maubin
    1. 
        
    2. reviewboard/testing/testcase.py (Diff revision 2)
       
       
       
      Show all issues

      Can you mention how this can be a LocalSite too.

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

      I think we'll also need to add doc as a user to the local site that gets passed in, because if someone's passing in a local site then it's likely a site that doesn't already include doc as a user of it.

    4. 
        
    david
    chipx86
    1. 
        
    2. reviewboard/testing/testcase.py (Diff revision 3)
       
       
      Show all issues

      Missing a trailing comma.

    3. 
        
    maubin
    1. Ship It!
    2. 
        
    david
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-9.x (81115bb)