Add test helpers for creating review request drafts and HTTP requests.

Review Request #1902 — Created April 9, 2020 and updated

guest6905
Review Board
www.google.com
361d769...
guest6905
Many of the unit tests in our codebase involve creating an `HttpRequest`
and setting state on it (like users, a `LocalSite`, or a
`ResolverMatch`), which is done through a `RequestFactory`. This
requires a lot of annoying, repeated code.

We also often need to create a `ReviewRequestDraft`, which is easier,
but still requires more setup than is generally required for our other
models.

This change introduces new helpers for both. `create_http_request()`
takes care of constructing the `HttpRequest` from the factory and
setting various properties on it. Down the road, this could be updated
to provide more capabilities like running middleware.

`create_review_request_draft()` is a simple wrapper around
`ReviewRequestDraft.create()`, which lets unit tests avoid the extra
import.

A few unit tests have been updated to use `create_http_request()`, to
ensure that everything works as expected.

Testing Done:
Unit tests pass.

Made use of these new helpers in upcoming unit tests.

This is a backport of aeb5d6438ade5853e29da044a1dddcd0c4cb7df3 from
release-4.0.x.

Reviewed at https://reviews.reviewboard.org/r/10710/


Loading...