-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from uktrade/LTD-2508-Upgrade-Django-to-lates…
…t-LTS LTD-2508: Upgrade Django to current LTS version 3.2
- Loading branch information
Showing
8 changed files
with
308 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from datetime import timedelta | ||
|
||
from background_task.models import Task | ||
from django.conf import settings | ||
from django.test import testcases | ||
from django.urls import reverse | ||
from django.utils import timezone | ||
from rest_framework import status | ||
|
||
from mail.enums import ReceptionStatusEnum, ReplyStatusEnum | ||
from mail.models import Mail | ||
from mail.tasks import LICENCE_DATA_TASK_QUEUE, MANAGE_INBOX_TASK_QUEUE | ||
|
||
|
||
class TestHealthcheck(testcases.TestCase): | ||
def setUp(self): | ||
self.url = reverse("healthcheck") | ||
|
||
def test_healthcheck_return_ok(self): | ||
response = self.client.get(self.url) | ||
self.assertEqual(response.context["message"], "OK") | ||
self.assertEqual(response.context["status"], status.HTTP_200_OK) | ||
|
||
def test_healthcheck_service_unavailable_pending_mail(self): | ||
sent_at = timezone.now() - timedelta(seconds=settings.EMAIL_AWAITING_REPLY_TIME) | ||
Mail.objects.create( | ||
edi_filename="filename", | ||
edi_data="1\\fileHeader\\CHIEF\\SPIRE\\", | ||
status=ReplyStatusEnum.PENDING, | ||
sent_at=sent_at, | ||
) | ||
response = self.client.get(self.url) | ||
self.assertEqual(response.context["message"], "not OK") | ||
self.assertEqual(response.context["status"], status.HTTP_503_SERVICE_UNAVAILABLE) | ||
|
||
def test_healthcheck_service_unavailable_rejected_mail(self): | ||
sent_at = timezone.now() - timedelta(seconds=settings.EMAIL_AWAITING_CORRECTIONS_TIME) | ||
Mail.objects.create( | ||
edi_filename="filename", | ||
edi_data="1\\fileHeader\\CHIEF\\SPIRE\\", | ||
response_data="1\\line1\\rejected\\", | ||
status=ReceptionStatusEnum.REPLY_SENT, | ||
sent_at=sent_at, | ||
) | ||
response = self.client.get(self.url) | ||
self.assertEqual(response.context["message"], "not OK") | ||
self.assertEqual(response.context["status"], status.HTTP_503_SERVICE_UNAVAILABLE) | ||
|
||
def test_healthcheck_service_unavailable_inbox_task_not_responsive(self): | ||
run_at = timezone.now() + timedelta(minutes=settings.INBOX_POLL_INTERVAL) | ||
task, _ = Task.objects.get_or_create(queue=MANAGE_INBOX_TASK_QUEUE) | ||
task.run_at = run_at | ||
task.save() | ||
response = self.client.get(self.url) | ||
self.assertEqual(response.context["message"], "not OK") | ||
self.assertEqual(response.context["status"], status.HTTP_503_SERVICE_UNAVAILABLE) | ||
|
||
def test_healthcheck_service_unavailable_licence_update_task_not_responsive(self): | ||
run_at = timezone.now() + timedelta(minutes=settings.LITE_LICENCE_DATA_POLL_INTERVAL) | ||
task, _ = Task.objects.get_or_create(queue=LICENCE_DATA_TASK_QUEUE) | ||
task.run_at = run_at | ||
task.save() | ||
response = self.client.get(self.url) | ||
self.assertEqual(response.context["message"], "not OK") | ||
self.assertEqual(response.context["status"], status.HTTP_503_SERVICE_UNAVAILABLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Generated by Django 3.2.14 on 2022-07-14 11:27 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("mail", "0017_auto_20220517_0830"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="licencepayload", | ||
name="data", | ||
field=models.JSONField(default=dict), | ||
), | ||
migrations.AlterField( | ||
model_name="usagedata", | ||
name="licence_ids", | ||
field=models.JSONField(default=list), | ||
), | ||
migrations.AlterField( | ||
model_name="usagedata", | ||
name="lite_accepted_licences", | ||
field=models.JSONField(default=list), | ||
), | ||
migrations.AlterField( | ||
model_name="usagedata", | ||
name="lite_licences", | ||
field=models.JSONField(default=dict), | ||
), | ||
migrations.AlterField( | ||
model_name="usagedata", | ||
name="lite_payload", | ||
field=models.JSONField(default=dict), | ||
), | ||
migrations.AlterField( | ||
model_name="usagedata", | ||
name="lite_rejected_licences", | ||
field=models.JSONField(default=list), | ||
), | ||
migrations.AlterField( | ||
model_name="usagedata", | ||
name="lite_response", | ||
field=models.JSONField(default=dict), | ||
), | ||
migrations.AlterField( | ||
model_name="usagedata", | ||
name="spire_accepted_licences", | ||
field=models.JSONField(default=dict), | ||
), | ||
migrations.AlterField( | ||
model_name="usagedata", | ||
name="spire_licences", | ||
field=models.JSONField(default=dict), | ||
), | ||
migrations.AlterField( | ||
model_name="usagedata", | ||
name="spire_rejected_licences", | ||
field=models.JSONField(default=dict), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters