• 
      

    Improve the foundation for testing hosting services.

    Review Request #9781 — Created March 15, 2018 and submitted

    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).

    Description From Last Updated

    Missing a period.

    daviddavid

    E501 line too long (80 > 79 characters)

    reviewbotreviewbot

    Instead of using form twice, can we have form_class and form?

    daviddavid

    This could just be: account.data = data or self.default_account_data

    daviddavid
    Checks run (1 failed, 1 succeeded)
    flake8 failed.
    JSHint passed.

    flake8

    david
    1. 
        
    2. Show all issues

      Missing a period.

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

      Instead of using form twice, can we have form_class and form?

      1. Yep. Old copy/pasted code. Thanks for catching that.

    4. reviewboard/hostingsvcs/testing/testcases.py (Diff revision 1)
       
       
       
       
       
      Show all issues

      This could just be:

      account.data = data or self.default_account_data
      
      1. This needs to allow {} to be specified without falling back on default_account_data. That's important for the authorize tests, where you don't want to start with any data.

    5. 
        
    chipx86
    david
    1. Ship It!
    2. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-3.0.x (140b712)