• 
      

    Add testing helpers for building consistent API payloads.

    Review Request #12239 — Created April 19, 2022 and submitted

    Information

    RBTools
    release-3.x

    Reviewers

    This is the first in a series of changes designed to solve unit testing
    problems in RBTools. Traditionally, unit testing for anything using
    rbtools.api (directly or indirectly) has been very difficult, as most
    operations require making numerous API calls to compute such state as
    API capabilities or repository lists. While we had a couple of helpers
    throughout the codebase, they still left most of the work to the
    particular unit test.

    This change introduces rbtools.testing.api, which is where API-related
    testing infrastructure will soon live, and a new
    ResourcePayloadFactory class. This is responsible for building:

    1. Object payloads/headers/URLs/etc. for items within a resource tree
      (such as a repository).

    2. Response payloads (for lists/items/errors) representing what would
      be sent to a client.

    Going forward, anything that needs to test against part of the API tree
    should use this (or suitable wrappers, coming in the next change) to
    build up the responses for the API resource classes to consume. This
    gives us consistency in what sort of payloads we're testing against.

    It's basically equivalent to the sort of testing methods we have
    available in Review Board for creating instances of models with
    defaults, such as review requests or repositories.

    This is currently limited in the types of object payloads/metadata that
    can be created. It should evolve over time as testing needs evolve.

    Upcoming changes will make use of this to provide a more simple,
    consistent mechanism for writing real-world unit tests that perform API
    requsts against these payloads.

    Tested along with some upcoming changes. Unit tests utilizing the
    payloads in this class all succeeded in looking up and getting the
    information they needed.

    Summary ID
    Add testing helpers for building consistent API payloads.
    This is the first in a series of changes designed to solve unit testing problems in RBTools. Traditionally, unit testing for anything using `rbtools.api` (directly or indirectly) has been very difficult, as most operations require making numerous API calls to compute such state as API capabilities or repository lists. While we had a couple of helpers throughout the codebase, they still left most of the work to the particular unit test. This change introduces `rbtools.testing.api`, which is where API-related testing infrastructure will soon live, and a new `ResourcePayloadFactory` class. This is responsible for building: 1. Object payloads/headers/URLs/etc. for items within a resource tree (such as a repository). 2. Response payloads (for lists/items/errors) representing what would be sent to a client. Going forward, anything that needs to test against part of the API tree should use this (or suitable wrappers, coming in the next change) to build up the responses for the API resource classes to consume. This gives us consistency in what sort of payloads we're testing against. It's basically equivalent to the sort of testing methods we have available in Review Board for creating instances of models with defaults, such as review requests or repositories. This is currently limited in the types of object payloads/metadata that can be created. It should evolve over time as testing needs evolve. Upcoming changes will make use of this to provide a more simple, consistent mechanism for writing real-world unit tests that perform API requsts against these payloads.
    d93f3b7bd8a7618674e12b710c986d8c764cd980
    david
    1. Ship It!
    2. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-3.x (70ad616)