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

Commit

Permalink
Add type annotations to tests.storage.test_appservice. (#11488)
Browse files Browse the repository at this point in the history
  • Loading branch information
reivilibre committed Dec 2, 2021
1 parent f61462e commit 435f044
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 53 deletions.
1 change: 1 addition & 0 deletions changelog.d/11488.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add type annotations to `tests.storage.test_appservice`.
1 change: 0 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ exclude = (?x)
|tests/server_notices/test_resource_limits_server_notices.py
|tests/state/test_v2.py
|tests/storage/test_account_data.py
|tests/storage/test_appservice.py
|tests/storage/test_background_update.py
|tests/storage/test_base.py
|tests/storage/test_client_ips.py
Expand Down
3 changes: 2 additions & 1 deletion synapse/appservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
import logging
import re
from enum import Enum
from typing import TYPE_CHECKING, Iterable, List, Match, Optional

from synapse.api.constants import EventTypes
Expand All @@ -27,7 +28,7 @@
logger = logging.getLogger(__name__)


class ApplicationServiceState:
class ApplicationServiceState(Enum):
DOWN = "down"
UP = "up"

Expand Down
6 changes: 3 additions & 3 deletions synapse/storage/databases/main/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def get_appservices_by_state(
A list of ApplicationServices, which may be empty.
"""
results = await self.db_pool.simple_select_list(
"application_services_state", {"state": state}, ["as_id"]
"application_services_state", {"state": state.value}, ["as_id"]
)
# NB: This assumes this class is linked with ApplicationServiceStore
as_list = self.get_app_services()
Expand Down Expand Up @@ -173,7 +173,7 @@ async def get_appservice_state(
desc="get_appservice_state",
)
if result:
return result.get("state")
return ApplicationServiceState(result.get("state"))
return None

async def set_appservice_state(
Expand All @@ -186,7 +186,7 @@ async def set_appservice_state(
state: The connectivity state to apply.
"""
await self.db_pool.simple_upsert(
"application_services_state", {"as_id": service.id}, {"state": state}
"application_services_state", {"as_id": service.id}, {"state": state.value}
)

async def create_appservice_txn(
Expand Down
Loading

0 comments on commit 435f044

Please sign in to comment.