diff --git a/codeforlife/tests/__init__.py b/codeforlife/tests/__init__.py new file mode 100644 index 00000000..e415ed2d --- /dev/null +++ b/codeforlife/tests/__init__.py @@ -0,0 +1 @@ +from .cron import CronTestCase, CronTestClient diff --git a/codeforlife/tests/cron.py b/codeforlife/tests/cron.py new file mode 100644 index 00000000..5a45b287 --- /dev/null +++ b/codeforlife/tests/cron.py @@ -0,0 +1,28 @@ +from rest_framework.test import APIClient, APITestCase + + +class CronTestClient(APIClient): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs, HTTP_X_APPENGINE_CRON="true") + + def generic( + self, + method, + path, + data="", + content_type="application/octet-stream", + secure=False, + **extra, + ): + wsgi_response = super().generic( + method, path, data, content_type, secure, **extra + ) + assert ( + 200 <= wsgi_response.status_code < 300 + ), f"Response has error status code: {wsgi_response.status_code}" + + return wsgi_response + + +class CronTestCase(APITestCase): + client_class = CronTestClient