diff --git a/zerver/lib/openapi.py b/zerver/lib/openapi.py index fc23d6cb68..1a44d3fbca 100644 --- a/zerver/lib/openapi.py +++ b/zerver/lib/openapi.py @@ -23,7 +23,7 @@ EXCLUDE_PROPERTIES = { class OpenAPISpec(): def __init__(self, path: str) -> None: self.path = path - self.reload() + self.last_update = None # type: Optional[float] def reload(self) -> None: self.last_update = os.path.getmtime(self.path) diff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.py index a126caa569..1ecd51ec4a 100644 --- a/zerver/tests/test_openapi.py +++ b/zerver/tests/test_openapi.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import mock from typing import Dict, Any import zerver.lib.openapi as openapi @@ -132,3 +133,8 @@ class OpenAPIToolsTest(ZulipTestCase): # Check that the file has been reloaded by verifying that the last # update date isn't zero anymore self.assertNotEqual(openapi_spec.last_update, 0) + + # Now verify calling it again doesn't call reload + with mock.patch('zerver.lib.openapi.openapi_spec.reload') as mock_reload: + get_openapi_fixture(TEST_ENDPOINT, TEST_METHOD) + self.assertFalse(mock_reload.called)