# Path: grazyna/plugins/db.py
# @register(cmd='add', on_private=False)
# def add_cmd(bot, key, message):
#     if not bot.protocol.db:
#         return
#     with bot.protocol.get_session() as session:
#         session.add(Message(
#             key=key,
#             channel=bot.chan,
#             message=message,
#         ))
#     bot.reply('Done!')
# 
# @register(cmd='del', on_private=False, admin_required=True)
# def delete_cmd(bot, key):
#     if not bot.protocol.db:
#         return
#     with bot.protocol.get_session() as session:
#         count = session.query(Message).filter_by(key=key, channel=bot.chan).delete()
#     if count > 0:
#         bot.reply('Done!')
#     else:
#         bot.reply('Key doesn\'t exist')
# 
# Path: grazyna/test_mocks/sender.py
# class SayMessage(Message):
# 
#     def __init__(self, to, msg):
#         super().__init__('PRIVMSG', to, ':' + msg)
# 
# Path: grazyna/models.py
# class Message(Base):
#     __tablename__ = 'messages'
#     id = Column(Integer, primary_key=True, autoincrement=True)
#     created = Column(DateTime, default=func.now())
#     channel = Column(String(30), nullable=False, index=True)
#     key = Column(String(20), nullable=False, index=True)
#     message = Column(String(200), nullable=False)


from grazyna.plugins.db import add_cmd, delete_cmd
from grazyna.test_mocks.sender import SayMessage
from grazyna.models import Message
import pytest



@pytest.mark.asyncio
def test_db_add(public_bot_with_db):
    yield from add_cmd(public_bot_with_db, 'firemark', 'firesmart')

# Path: grazyna/plugins/db.py
# @register(cmd='add', on_private=False)
# def add_cmd(bot, key, message):
#     if not bot.protocol.db:
#         return
#     with bot.protocol.get_session() as session:
#         session.add(Message(
#             key=key,
#             channel=bot.chan,
#             message=message,
#         ))
#     bot.reply('Done!')
# 
# @register(cmd='del', on_private=False, admin_required=True)
# def delete_cmd(bot, key):
#     if not bot.protocol.db:
#         return
#     with bot.protocol.get_session() as session:
#         count = session.query(Message).filter_by(key=key, channel=bot.chan).delete()
#     if count > 0:
#         bot.reply('Done!')
#     else:
#         bot.reply('Key doesn\'t exist')
# 
# Path: grazyna/test_mocks/sender.py
# class SayMessage(Message):
# 
#     def __init__(self, to, msg):
#         super().__init__('PRIVMSG', to, ':' + msg)
# 
# Path: grazyna/models.py
# class Message(Base):
#     __tablename__ = 'messages'
#     id = Column(Integer, primary_key=True, autoincrement=True)
#     created = Column(DateTime, default=func.now())
#     channel = Column(String(30), nullable=False, index=True)
#     key = Column(String(20), nullable=False, index=True)
#     message = Column(String(200), nullable=False)


# Path: grazyna/tests/plugins/test_db.py
from grazyna.plugins.db import add_cmd, delete_cmd
from grazyna.test_mocks.sender import SayMessage
from grazyna.models import Message
import pytest




@pytest.mark.asyncio
def test_db_add(public_bot_with_db):
    yield from add_cmd(public_bot_with_db, 'firemark', 'firesmart')

    yield from add_cmd(public_bot_with_db, 'firemark', 'firesmark')