Skip to content

Commit

Permalink
fix: add cron test client and case
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Sep 14, 2023
1 parent a063609 commit e3dbc88
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions codeforlife/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .cron import CronTestCase, CronTestClient
28 changes: 28 additions & 0 deletions codeforlife/tests/cron.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e3dbc88

Please sign in to comment.