• 
      

    Improve the foundation for testing hosting services.

    Review Request #9781 — Created March 16, 2018 and submitted — Latest diff uploaded

    Information

    Review Board
    release-3.0.x
    7c8e7de...

    Reviewers

    Hosting service test code is a bit of a mess, due to the need for
    overriding HTTP request handling for most tests and setting up
    account/service state. Over time, as code was copy/pasted between test
    suites to form new tests, this just became more complicated and harder
    to manage.

    This change introduces a new infrastructure for writing hosting service
    tests. Modern test cases now subclass
    reviewboard.hostingsvcs.testing.HostingServiceTestCase, which, unlike
    the old ServiceTests, is meant to be publicly-used. It provides
    several public functions for common types of checks needed, some of
    which were previously private functions in ServiceTests, and some of
    which are new and will help slim down most tests.

    There's a set of new attributes for specifying defaults for hosting
    account data, repository extra_data, authentication credentials, and
    more, which reduce the need to hard-code the same bits of data
    everywhere.

    It also introduces the new setup_http_test context manager, which does
    all the work of setting up state and spies for any tests that need to
    fake results from HTTP requests. This provides a couple of ways of
    working. It allows for an explicit payload to be provided, or a status
    code for an error response, or a function to invoke when the HTTP
    request is made. The context manager yields a HttpTestContext object,
    which has some pre-calculated state and helpers for creating
    repositories for the test and asserting the results of the HTTP calls.

    It also makes the useful HostingService.get_field public, which can
    now be used in tests without being re-implemented.

    No tests have been updated to make use of this yet. That will come in
    future changes.

    Existing unit tests pass.

    Tested with some upcoming changes that will make use of the new test
    case class.

    Built the docs and made sure things rendered mostly fine (along with
    some changes in beanbag-docutils that will go in later).