Skip to content

Commit

Permalink
✅ Add/fix tests for client timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Feb 13, 2024
1 parent ae135cf commit 45d1bd9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import patch

from django.test import TestCase

import requests_mock
Expand All @@ -11,11 +13,12 @@ class ClientTests(TestCase):
def setUp(self):
self.api_root = "https://example.com/api/v1/"
self.api_token = "token"
self.client = Client(self.api_root, self.api_token)
self.client_timeout = 2
self.client = Client(self.api_root, self.api_token, self.client_timeout)

def test_has_config(self, m):
self.assertTrue(self.client.has_config())
self.assertFalse(Client("", "").has_config())
self.assertFalse(Client("", "", "").has_config())

def test_is_healthy(self, m):
m.head(
Expand Down Expand Up @@ -76,3 +79,13 @@ def test_get_form_with_error(self, m):

with self.assertRaises(HTTPError):
self.client.get_form("myform")

def test_request_uses_configured_timeout(self, m):
with patch("openformsclient.client.requests.request") as mock_request:
self.client.get_form("myform")
mock_request.assert_called_with(
"get",
"https://example.com/api/v1/forms/myform",
headers={"Authorization": "Token token"},
timeout=2,
)
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setUp(self):
)

def test_get_form_choices_without_config(self, m):
client = Client("", "")
client = Client("", "", "")
result = get_form_choices(client)
self.assertEqual(result, [])

Expand Down

0 comments on commit 45d1bd9

Please sign in to comment.