Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
babolivier committed Apr 28, 2022
1 parent d721bf6 commit c5b91b4
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 36 deletions.
2 changes: 1 addition & 1 deletion synapse/federation/transport/server/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def __init__(
super(FederationUserInfoServlet, self).__init__(
hs, authenticator, ratelimiter, server_name
)
self._store = hs.get_datastore()
self._store = hs.get_datastores().main

async def on_POST(
self,
Expand Down
5 changes: 0 additions & 5 deletions synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,6 @@ async def register_user(
shadow_banned=shadow_banned,
)

requester = create_requester(user)
await self.profile_handler.set_displayname(
user, requester, default_display_name, by_admin=True
)

# Successfully registered
break
except SynapseError:
Expand Down
2 changes: 1 addition & 1 deletion synapse/http/proxyagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

logger = logging.getLogger(__name__)

_VALID_URI = re.compile(br"\A[\x21-\x7e]+\Z")
_VALID_URI = re.compile(rb"\A[\x21-\x7e]+\Z")


@implementer(IAgent)
Expand Down
4 changes: 2 additions & 2 deletions synapse/rest/client/user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(self, hs: "HomeServer") -> None:
super(SingleUserInfoServlet, self).__init__()
self.hs = hs
self.auth = hs.get_auth()
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.transport_layer = hs.get_federation_transport_client()
registry = hs.get_federation_registry()

Expand Down Expand Up @@ -168,7 +168,7 @@ def __init__(self, hs: "HomeServer") -> None:
super(UserInfoServlet, self).__init__()
self.hs = hs
self.auth = hs.get_auth()
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.transport_layer = hs.get_federation_transport_client()

async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
Expand Down
4 changes: 2 additions & 2 deletions synapse/rest/media/v1/preview_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
logger = logging.getLogger(__name__)

_charset_match = re.compile(
br'<\s*meta[^>]*charset\s*=\s*"?([a-z0-9_-]+)"?', flags=re.I
rb'<\s*meta[^>]*charset\s*=\s*"?([a-z0-9_-]+)"?', flags=re.I
)
_xml_encoding_match = re.compile(
br'\s*<\s*\?\s*xml[^>]*encoding="([a-z0-9_-]+)"', flags=re.I
rb'\s*<\s*\?\s*xml[^>]*encoding="([a-z0-9_-]+)"', flags=re.I
)
_content_type_match = re.compile(r'.*; *charset="?(.*?)"?(;|$)', flags=re.I)

Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ def default_config(self) -> JsonDict:

def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
super(UserInfoTestCase, self).prepare(reactor, clock, hs)
self.store = hs.get_datastore()
self.store = hs.get_datastores().main
self.handler = hs.get_user_directory_handler()

def test_user_info(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/replication/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def assert_request_is_get_repl_stream_updates(
path: bytes = request.path # type: ignore
self.assertRegex(
path,
br"^/_synapse/replication/get_repl_stream_updates/%s/[^/]+$"
rb"^/_synapse/replication/get_repl_stream_updates/%s/[^/]+$"
% (stream_name.encode("ascii"),),
)

Expand Down
26 changes: 13 additions & 13 deletions tests/rest/client/test_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json
from http import HTTPStatus

from twisted.test.proto_helpers import MemoryReactor
from unittest.mock import Mock

from twisted.internet import defer
from twisted.test.proto_helpers import MemoryReactor

import synapse.rest.admin
from synapse.rest.client import login, room
from synapse.rest.client import account, login, room
from synapse.server import HomeServer
from synapse.util import Clock

Expand All @@ -47,11 +45,11 @@ def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:

return self.hs

def prepare(self, reactor, clock, hs):
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
self.user_id = self.register_user("kermit", "monkey")
self.tok = self.login("kermit", "monkey")

def test_3pid_invite_disabled(self):
def test_3pid_invite_disabled(self) -> None:
channel = self.make_request(b"POST", "/createRoom", {}, access_token=self.tok)
self.assertEquals(channel.result["code"], b"200", channel.result)
room_id = channel.json_body["room_id"]
Expand All @@ -75,7 +73,7 @@ def test_3pid_lookup_disabled(self) -> None:
channel = self.make_request("GET", url, access_token=self.tok)
self.assertEqual(channel.result["code"], b"403", channel.result)

def test_3pid_bulk_lookup_disabled(self):
def test_3pid_bulk_lookup_disabled(self) -> None:
url = "/_matrix/client/unstable/account/3pid/bulk_lookup"
data = {
"id_server": "testis",
Expand All @@ -95,7 +93,7 @@ class IdentityEnabledTestCase(unittest.HomeserverTestCase):
login.register_servlets,
]

def make_homeserver(self, reactor, clock):
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:

config = self.default_config()
config["enable_3pid_lookup"] = True
Expand All @@ -116,12 +114,14 @@ def make_homeserver(self, reactor, clock):

return self.hs

def prepare(self, reactor, clock, hs):
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
self.user_id = self.register_user("kermit", "monkey")
self.tok = self.login("kermit", "monkey")

def test_3pid_invite_enabled(self):
channel = self.make_request(b"POST", "/createRoom", b"{}", access_token=tok)
def test_3pid_invite_enabled(self) -> None:
channel = self.make_request(
b"POST", "/createRoom", b"{}", access_token=self.tok
)
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
room_id = channel.json_body["room_id"]

Expand All @@ -140,7 +140,7 @@ def test_3pid_invite_enabled(self):
)
self.assertEquals(channel.result["code"], b"200", channel.result)

def test_3pid_lookup_enabled(self):
def test_3pid_lookup_enabled(self) -> None:
url = (
"/_matrix/client/unstable/account/3pid/lookup"
"?id_server=testis&medium=email&[email protected]"
Expand All @@ -153,7 +153,7 @@ def test_3pid_lookup_enabled(self):
{"address": "[email protected]", "medium": "email"},
)

def test_3pid_bulk_lookup_enabled(self):
def test_3pid_bulk_lookup_enabled(self) -> None:
url = "/_matrix/client/unstable/account/3pid/bulk_lookup"
data = {
"id_server": "testis",
Expand Down
18 changes: 8 additions & 10 deletions tests/rest/client/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@
import datetime
import json
import os
from typing import Any, Dict, List, Tuple
import os.path
import tempfile
from typing import Any, Dict, List, Tuple
from unittest.mock import Mock

import pkg_resources

from twisted.internet import defer

from twisted.test.proto_helpers import MemoryReactor

import synapse.rest.admin
from synapse.api.constants import APP_SERVICE_REGISTRATION_TYPE, LoginType
from synapse.api.errors import Codes
from synapse.appservice import ApplicationService
from synapse.rest.client import account, account_validity, login, logout, register, sync
from synapse.server import HomeServer
from synapse.rest.client import (
account,
account_validity,
Expand All @@ -44,6 +41,7 @@
sync,
user_directory,
)
from synapse.server import HomeServer
from synapse.storage._base import db_to_json
from synapse.types import JsonDict
from synapse.util import Clock
Expand Down Expand Up @@ -794,7 +792,7 @@ class RegisterHideProfileTestCase(unittest.HomeserverTestCase):

servlets = [synapse.rest.admin.register_servlets_for_client_rest_resource]

def make_homeserver(self, reactor, clock):
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:

self.url = b"/_matrix/client/r0/register"

Expand All @@ -812,7 +810,7 @@ def make_homeserver(self, reactor, clock):

return self.hs

def test_profile_hidden(self):
def test_profile_hidden(self) -> None:
user_id = self.register_user("kermit", "monkey")

post_json = self.hs.get_simple_http_client().post_json_get_json
Expand All @@ -832,7 +830,7 @@ def test_profile_hidden(self):


class AccountValidityTemplateDirectoryTestCase(unittest.HomeserverTestCase):
def make_homeserver(self, reactor, clock):
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
config = self.default_config()

# Create a custom template directory and a template inside to read
Expand Down Expand Up @@ -865,7 +863,7 @@ def make_homeserver(self, reactor, clock):

return self.hs

def test_template_contents(self):
def test_template_contents(self) -> None:
"""Tests that the contents of the custom templates as specified in the config are
correct.
"""
Expand Down Expand Up @@ -1012,7 +1010,7 @@ class AccountValidityUserDirectoryTestCase(unittest.HomeserverTestCase):
account_validity.register_servlets,
]

def make_homeserver(self, reactor, clock):
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
config = self.default_config()

# Set accounts to expire after a week
Expand All @@ -1033,7 +1031,7 @@ def make_homeserver(self, reactor, clock):

return self.hs

def test_expired_user_in_directory(self):
def test_expired_user_in_directory(self) -> None:
"""Test that an expired user is hidden in the user directory"""
# Create an admin user to search the user directory
admin_id = self.register_user("admin", "adminpassword", admin=True)
Expand Down

0 comments on commit c5b91b4

Please sign in to comment.