Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a more realistic configuration in tests #516

Merged
merged 3 commits into from
Apr 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Avoid printing errors in tests.
clokep committed Apr 6, 2022
commit b587f1f2915f3ef52c18e552ca36d6fb2d78c8bd
12 changes: 1 addition & 11 deletions tests/test_casefold_migration.py
Original file line number Diff line number Diff line change
@@ -27,17 +27,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 = []
9 changes: 1 addition & 8 deletions tests/test_email.py
Original file line number Diff line number Diff line change
@@ -22,14 +22,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.
9 changes: 1 addition & 8 deletions tests/test_jinja_templates.py
Original file line number Diff line number Diff line change
@@ -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 = {
7 changes: 1 addition & 6 deletions tests/test_replication.py
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 0 additions & 5 deletions tests/test_store_invite.py
Original file line number Diff line number Diff line change
@@ -27,11 +27,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 <noreply@hostname>",
},
28 changes: 21 additions & 7 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -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()