diff --git a/changelog.d/516.misc b/changelog.d/516.misc new file mode 100644 index 00000000..6d2aaf21 --- /dev/null +++ b/changelog.d/516.misc @@ -0,0 +1 @@ +Avoid spurious warnings in tests. diff --git a/tests/test_casefold_migration.py b/tests/test_casefold_migration.py index 59e28cd7..e24b0b20 100644 --- a/tests/test_casefold_migration.py +++ b/tests/test_casefold_migration.py @@ -1,5 +1,17 @@ +# Copyright 2021 Matrix.org Foundation C.I.C. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import json -import os.path from unittest.mock import patch from twisted.trial import unittest @@ -27,17 +39,7 @@ def create_signedassoc(self, medium, address, mxid, ts, not_before, not_after): def setUp(self): # Create a new sydent - config = { - "general": { - "templates.path": os.path.join( - os.path.dirname(os.path.dirname(__file__)), "res" - ), - }, - "crypto": { - "ed25519.signingkey": "ed25519 0 FJi1Rnpj3/otydngacrwddFvwz/dTDsBv62uZDN2fZM" - }, - } - self.sydent = make_sydent(test_config=config) + self.sydent = make_sydent() # create some local associations associations = [] diff --git a/tests/test_email.py b/tests/test_email.py index b7f48c1f..f8d1c908 100644 --- a/tests/test_email.py +++ b/tests/test_email.py @@ -11,7 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os.path from unittest.mock import patch from twisted.trial import unittest @@ -22,14 +21,7 @@ class TestRequestCode(unittest.TestCase): def setUp(self): # Create a new sydent - config = { - "general": { - "templates.path": os.path.join( - os.path.dirname(os.path.dirname(__file__)), "res" - ), - }, - } - self.sydent = make_sydent(test_config=config) + self.sydent = make_sydent() def _render_request(self, request): # Patch out the email sending so we can investigate the resulting email. diff --git a/tests/test_jinja_templates.py b/tests/test_jinja_templates.py index 030e6e90..6e0b37cb 100644 --- a/tests/test_jinja_templates.py +++ b/tests/test_jinja_templates.py @@ -25,14 +25,7 @@ class TestTemplate(unittest.TestCase): def setUp(self): # Create a new sydent - config = { - "general": { - "templates.path": os.path.join( - os.path.dirname(os.path.dirname(__file__)), "res" - ), - }, - } - self.sydent = make_sydent(test_config=config) + self.sydent = make_sydent() def test_jinja_vector_invite(self): substitutions = { diff --git a/tests/test_replication.py b/tests/test_replication.py index 46db25d0..e119d224 100644 --- a/tests/test_replication.py +++ b/tests/test_replication.py @@ -15,12 +15,7 @@ class ReplicationTestCase(unittest.TestCase): def setUp(self): # Create a new sydent - config = { - "crypto": { - "ed25519.signingkey": "ed25519 0 FJi1Rnpj3/otydngacrwddFvwz/dTDsBv62uZDN2fZM" - } - } - self.sydent = make_sydent(test_config=config) + self.sydent = make_sydent() # Create a fake peer to replicate to. peer_public_key_base64 = "+vB8mTaooD/MA8YYZM8t9+vnGhP1937q2icrqPV9JTs" diff --git a/tests/test_store_invite.py b/tests/test_store_invite.py index 5f19fdb0..9f5cb6ff 100644 --- a/tests/test_store_invite.py +++ b/tests/test_store_invite.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import os.path from unittest.mock import patch from parameterized import parameterized @@ -27,11 +26,6 @@ class StoreInviteTestCase(unittest.TestCase): def setUp(self) -> None: # Create a new sydent config = { - "general": { - "templates.path": os.path.join( - os.path.dirname(os.path.dirname(__file__)), "res" - ), - }, "email": { "email.from": "Sydent Validation ", }, diff --git a/tests/utils.py b/tests/utils.py index 902b3bef..80be5c16 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -2,7 +2,7 @@ import logging import os from io import BytesIO -from typing import Dict +from typing import Dict, Optional from unittest.mock import MagicMock import attr @@ -53,20 +53,34 @@ """ -def make_sydent(test_config={}): +def make_sydent(test_config: Optional[dict] = None) -> Sydent: """Create a new sydent Args: - test_config (dict): any configuration variables for overriding the default sydent + test_config: Configuration variables for overriding the default sydent config """ + if test_config is None: + test_config = {} + # Use an in-memory SQLite database. Note that the database isn't cleaned up between # tests, so by default the same database will be used for each test if changed to be # a file on disk. - if "db" not in test_config: - test_config["db"] = {"db.file": ":memory:"} - else: - test_config["db"].setdefault("db.file", ":memory:") + test_config.setdefault("db", {}).setdefault("db.file", ":memory:") + + # Specify a server name to avoid warnings. + general_config = test_config.setdefault("general", {}) + general_config.setdefault("server.name", ":test:") + # Specify the default templates. + general_config.setdefault( + "templates.path", + os.path.join(os.path.dirname(os.path.dirname(__file__)), "res"), + ) + + # Specify a signing key. + test_config.setdefault("crypto", {}).setdefault( + "ed25519.signingkey", "ed25519 0 FJi1Rnpj3/otydngacrwddFvwz/dTDsBv62uZDN2fZM" + ) reactor = ResolvingMemoryReactorClock()