Update webhook support for Python 3.x and Django 1.11.

Review Request #10483 — Created March 31, 2019 and submitted — Latest diff uploaded

Information

Review Board
release-4.0.x

Reviewers

This brings Python 3.x and Django 1.11 support to our webhook code.
There were a few key areas that required some rethinking in order for
modern support:

  1. Python 2 has a long type, but Python 3 does not, so we just
    needed to alias long to int for testing purposes.

  2. Python 3.x's JSON support doesn't handle sorting of non-string keys.
    They recommend avoiding non-string keys entirely, but it only breaks
    when sorting. However, our XML and custom payloads support them. We
    now normalize keys to strings if we know we're going to run the
    data through a JSON encoder.

  3. We were outputting byte strings for JSON and form-data payloads,
    but Unicode strings for XML. We're now consistent in the format
    returned across all types.

  4. Django 1.6 and 1.11 have different setup requirements for manually
    parsing templates and getting results. This has to be solved with a
    version check, and using different logic for each version of Django.

  5. Django 1.11 tries to be helpful when encountering an invalid block
    tag, making recommendations about loading libraries. We don't want
    this at all, since users don't have this option with our webhook
    templates, so we now override this error message to be less helpful.

Unit tests pass for Python 2.7 with Django 1.6 and 3.5-3.7 with
Django 1.11 (with other in-progress changes).

Commits

Files