Once you've written code that uses the civis.APIClient, you've got to test it. We should have a page of Sphinx documentation (as a subheader on the "User Guide" page, or its own page if large enough) about how to test code that uses the APIClient. Include examples which both use the APIClient object and higher-level helpers such as the ones in civis.io.
A couple of best practices to mention:
Write functions which use the APIClient so that they take a client object as an optional parameter. For testing, you can pass in a unittest.mock.Mock object.
Use civis.tests.mocks.create_client_mock to create an autospecced Mock for testing. (Gotcha: By default, this relies on the API spec bundled with civis-python, so specs could be a bit out of date.)
Once you've written code that uses the
civis.APIClient
, you've got to test it. We should have a page of Sphinx documentation (as a subheader on the "User Guide" page, or its own page if large enough) about how to test code that uses theAPIClient
. Include examples which both use theAPIClient
object and higher-level helpers such as the ones incivis.io
.A couple of best practices to mention:
APIClient
so that they take aclient
object as an optional parameter. For testing, you can pass in aunittest.mock.Mock
object.civis.tests.mocks.create_client_mock
to create an autospeccedMock
for testing. (Gotcha: By default, this relies on the API spec bundled with civis-python, so specs could be a bit out of date.)