This commit is contained in:
Felipe M 2021-02-02 13:07:13 +01:00
parent a512896ff5
commit a810d5bdc3
Signed by: fmartingr
GPG Key ID: 716BC147715E716F
3 changed files with 13 additions and 9 deletions

View File

@ -3,8 +3,8 @@ from typing import Union
import dataset
from butterrobot.config import DATABASE_PATH, SECRET_KEY
from butterrobot.objects import Channel, ChannelPlugin, User
from butterrobot.config import SECRET_KEY, DATABASE_PATH
from butterrobot.objects import User, Channel, ChannelPlugin
db = dataset.connect(DATABASE_PATH)
@ -25,7 +25,7 @@ class Query:
yield cls.obj(**row)
@classmethod
def get(cls, **kwargs) -> "class":
def get(cls, **kwargs):
"""
Returns the object representation of an specific row in a table.
Allows retrieving object by multiple columns.
@ -153,7 +153,9 @@ class ChannelPluginQuery(Query):
@classmethod
def get_from_channel_id(cls, channel_id):
yield from [cls.obj(**row) for row in db[cls.tablename].find(channel_id=channel_id)]
yield from [
cls.obj(**row) for row in db[cls.tablename].find(channel_id=channel_id)
]
@classmethod
def delete_by_channel(cls, channel_id):

View File

@ -36,7 +36,7 @@ class Platform:
@classmethod
@abstractmethod
def parse_incoming_message(cls, request) -> 'Message':
def parse_incoming_message(cls, request):
"""
Parses the incoming request and returns a :class:`butterrobot.objects.Message` instance.
"""
@ -52,7 +52,7 @@ class Platform:
@classmethod
@abstractmethod
def parse_channel_from_message(cls, channel_raw) -> 'Channel':
def parse_channel_from_message(cls, channel_raw):
"""
Extracts the Channel raw data from the message received in the incoming webhook.
"""
@ -62,6 +62,6 @@ class Platform:
class PlatformMethods:
@classmethod
@abstractmethod
def send_message(cls, message: 'Message'):
def send_message(cls, message):
"""Method used to send a message via the platform"""
pass

View File

@ -7,9 +7,11 @@ def test_channel_has_enabled_plugin_ok():
platform_channel_id="debug",
channel_raw={},
plugins={
"enabled": ChannelPlugin(id=1, channel_id="test", plugin_id="enabled", enabled=True),
"enabled": ChannelPlugin(
id=1, channel_id="test", plugin_id="enabled", enabled=True
),
"existant": ChannelPlugin(id=2, channel_id="test", plugin_id="existant"),
}
},
)
assert not channel.has_enabled_plugin("non.existant")
assert not channel.has_enabled_plugin("existant")