Пример #1
0
def test_del_by_time():
    """test delete by time stamp"""
    interface = DataTransfer(Database(PATH))
    data_num = len(interface.get_all_msgs())
    test_save_msg(time=datetime.now() - timedelta(days=3))
    interface.del_msg_by_timedelta(timedelta(days=3))
    assert len(interface.get_all_msgs()) == data_num
Пример #2
0
def test_expiry():
    """test expiry of messages"""
    interface = DataTransfer(Database(PATH))
    controller = TagController(interface)
    data_num = len(interface.get_all_msgs())
    expiry = datetime.now() + timedelta(seconds=1)
    msg = f'test expiry, {KEY_EXPIRY}{KEY_SPLIT}{str(expiry)}'
    controller.handle_msg(quoted='second', msg=msg, talker='me', to_bot=True)
    sleep(1)
    assert data_num == len(interface.get_all_msgs())
Пример #3
0
def test_update():
    """test insert duplicated message with different tag"""
    interface = DataTransfer(Database(PATH))
    test_save_msg(msg='update message', tag='test update')
    data_num = len(interface.get_all_msgs())
    test_save_msg(msg='update message', tag='test update 2', force_create=False)
    all_msg = interface.get_all_msgs()
    assert len(all_msg) == data_num
    assert all_msg[-1][1].msg == 'update message'
    assert all_msg[-1][1].tags == 'test update 2'
Пример #4
0
def test_delete():
    """test delete message"""
    interface = DataTransfer(Database(PATH))
    controller = TagController(interface)
    data_num = len(interface.get_all_msgs())
    ifreply = controller.handle_msg(quoted=None,
                                    msg=f'{KEY_DELETE} {KEY_SPLIT}1',
                                    talker='me',
                                    to_bot=True)
    assert ifreply
    assert controller.reply == reply.del_msg_success(1)
    assert len(interface.get_all_msgs()) == data_num - 1
Пример #5
0
def test_get_all_msgs():
    """test get all messages"""
    test_save_msg('second', 'test 2', 'admin2', datetime(2020, 3, 26))
    test_save_msg('third', 'test 3')
    interface = DataTransfer(Database(PATH))
    all_msg = interface.get_all_msgs()
    _, msg = all_msg[0]
    assert len(all_msg) == 2
    assert msg.expiry == datetime(2020, 3, 26)
Пример #6
0
def test_save_msg():
    """test save messaga"""
    interface = DataTransfer(Database(PATH))
    controller = TagController(interface)
    ifreply = controller.handle_msg(quoted='first',
                                    msg='test save msg',
                                    talker='me',
                                    to_bot=True)
    assert ifreply
    assert controller.reply == reply.save_msg_success()
    assert len(interface.get_all_msgs()) == 1