• 
      

    Make it easier for callers to modify the root resource in unit tests.

    Review Request #14580 — Created Sept. 8, 2025 and submitted

    Information

    RBTools
    release-5.x

    Reviewers

    We use as URLMapTransport the test transport in our unit tests, which
    lets callers easily define response payloads for our API URLs in unit
    tests.

    While writing some unit tests, I found that I couldn't reliably update
    the root resource's payload. I could update the payload returned by the
    root URL endpoint itself, but the server info resource and capabilities
    attribute on the class would still use information from the default root
    resource that gets set during URLMapTransport.initialize(). This
    change allows callers to more easily change the root resource, and
    dynamically reflect those changes in associated resources and attributes.

    This change also fixes two bugs:

    1. We weren't setting the right object representation for the server info
      resource. We were setting it to the outer payload when it should just
      be the inner payload (e.g. the object representation, without the
      'item_key' and 'stat' info).

    2. We weren't handling object representations that were callables. We
      do handle payloads that are callables, but it's possible to have
      object representations inside the payload that are callables too
      (as is the case for the server info resource). We now process these
      like we do for callable payloads.

    • Used this change in an upcoming one that has unit tests that
      previously crashed without these fixes.
    • Ran unit tests.
    Summary ID
    Make it easier for callers to modify the root resource in unit tests.
    We use as `URLMapTransport` the test transport in our unit tests, which lets callers easily define response payloads for our API URLs in unit tests. While writing some unit tests, I found that I couldn't reliably update the root resource's payload. I could update the payload returned by the root URL endpoint itself, but the server info resource and capabilities attribute on the class would still use information from the default root resource that gets set during `URLMapTransport.initialize()`. This change allows callers to more easily change the root resource, and dynamically reflect those changes in associated resources and attributes. This change also fixes two bugs: 1. We weren't setting the right object representation for the server info resource. We were setting it to the outer payload when it should just be the inner payload (e.g. the object representation, without the 'item_key' and 'stat' info). 2. We weren't handling object representations that were callables. We do handle payloads that are callables, but it's possible to have object representations inside the payload that are callables too (as is the case for the server info resource). We now process these like we do for callable payloads.
    2185a96e9eac2f8eac684d9ec2d22e53f5b89428
    Description From Last Updated

    There's a bunch of ** in here. Maybe break this out into one more variable? root_object_data = self.payload_factor.make_root_object_data(**kwargs) root_info = …

    daviddavid
    david
    1. 
        
    2. rbtools/testing/api/transport.py (Diff revision 1)
       
       
       
      Show all issues

      There's a bunch of ** in here. Maybe break this out into one more variable?

      root_object_data = self.payload_factor.make_root_object_data(**kwargs)
      root_info = self.add_item_url(**root_object_data)
      
      ...
      
    3. 
        
    maubin
    david
    1. Ship It!
    2. 
        
    chipx86
    1. Ship It!
    2. 
        
    maubin
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-5.x (0240702)