Browse Source

Misc test fixes

master
dave 1 year ago
parent
commit
ade7fed3a8
7 changed files with 38 additions and 14 deletions
  1. +1
    -1
      pyircbot/irccore.py
  2. +5
    -3
      pyircbot/modules/DCC.py
  3. +25
    -3
      pyircbot/modules/NickUser.py
  4. +1
    -1
      pyircbot/modules/PingResponder.py
  5. +2
    -1
      tests/modules/test_cryptowallet.py
  6. +1
    -1
      tests/modules/test_nickuser.py
  7. +3
    -4
      tests/test_jsonrpc.py

+ 1
- 1
pyircbot/irccore.py View File

@@ -78,7 +78,7 @@ class IRCCore(object):
family=self.connection_family,
local_addr=self.bind_addr)
self.fire_hook("_CONNECT")
except (socket.gaierror, ConnectionRefusedError):
except (socket.gaierror, ConnectionRefusedError, OSError):
traceback.print_exc()
logging.warning("Non-fatal connect error, trying next server...")
self.server = (self.server + 1) % len(self.servers)


+ 5
- 3
pyircbot/modules/DCC.py View File

@@ -96,9 +96,8 @@ class RecieveGenerator(object):
print("total", total, "expected", self.length)
if total != self.length:
raise TransferFailedException("Transfer failed: expected {} bytes but got {}".format(self.length, total))
raise StopIteration()
finally:
self.sock.shutdown(socket.SHUT_RDWR)
# self.sock.shutdown(socket.SHUT_RDWR)
self.sock.close()


@@ -140,8 +139,11 @@ class OfferThread(Thread):
clientsocket.shutdown(socket.SHUT_RDWR)
clientsocket.close()
finally:
self.listener.shutdown(socket.SHUT_RDWR)
# try:
# self.listener.shutdown(socket.SHUT_RDWR)
self.listener.close()
# except Exception:
# pass

def abort(self):
"""


+ 25
- 3
pyircbot/modules/NickUser.py View File

@@ -50,13 +50,15 @@ class NickUser(ModuleBase):
oldpass = attr.getKey(prefix.nick, "password")
if oldpass is None:
attr.setKey(prefix.nick, "password", cmd.args[0])
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Your password has been set to \"%s\"." % cmd.args[0])
self.bot.act_PRIVMSG(prefix.nick, ".setpass: You've been logged in and "
"your password has been set to \"%s\"." % cmd.args[0])
else:
if len(cmd.args) == 2:
if cmd.args[0] == oldpass:
attr.setKey(prefix.nick, "password", cmd.args[1])
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Your password has been set to \"%s\"." %
cmd.args[1])
self.bot.act_PRIVMSG(prefix.nick,
".setpass: Your password has been set to \"%s\"." % cmd.args[1])
attr.setKey(prefix.nick, "loggedinfrom", prefix.hostname)
else:
self.bot.act_PRIVMSG(prefix.nick, ".setpass: Old password incorrect.")
else:
@@ -89,3 +91,23 @@ class NickUser(ModuleBase):
else:
attr.setKey(prefix.nick, "loggedinfrom", None)
self.bot.act_PRIVMSG(prefix.nick, ".logout: You have been logged out.")


# Decorator for methods that require login
# Assumes your args matches the same format that @command(...) expects
#TODO better docs
class protected(object):
def __init__(self, message=None):
self.message = message or "{}: you need to .login to do that"

def __call__(self, func):
def wrapper(*args, **kwargs):
module, message, command = args
login = module.bot.getBestModuleForService("login")

if not login.check(message.prefix.nick, message.prefix.hostname):
module.bot.act_PRIVMSG(message.args[0], self.message.format(message.prefix.nick))
return

func(*args, **kwargs)
return wrapper

+ 1
- 1
pyircbot/modules/PingResponder.py View File

@@ -22,7 +22,7 @@ class PingResponder(ModuleBase):
"""Respond to the PING command"""
# got a ping? send it right back
self.bot.act_PONG(msg.trailing)
self.log.info("%s Responded to a ping: %s" % (self.bot.get_nick(), msg.trailing))
self.log.debug("%s Responded to a ping: %s" % (self.bot.get_nick(), msg.trailing))

@hook("_RECV", "_SEND")
def resettimer(self, msg, cmd):


+ 2
- 1
tests/modules/test_cryptowallet.py View File

@@ -70,8 +70,9 @@ def test_getbal_authed(cryptobot):

def test_setup(cryptobot, mynick="chatter"):
pm(cryptobot, ".setpass foobar", nick=mynick)
cryptobot.act_PRIVMSG.assert_called_once_with(mynick, '.setpass: Your password has been set to "foobar".')
cryptobot.act_PRIVMSG.assert_called_once_with(mynick, '.setpass: You\'ve been logged in and your password has been set to "foobar".')
cryptobot.act_PRIVMSG.reset_mock()
# TODO shouldn't need .login here, the setpass does it
pm(cryptobot, ".login foobar", nick=mynick)
cryptobot.act_PRIVMSG.assert_called_once_with(mynick, '.login: You have been logged in from: cia.gov')
cryptobot.act_PRIVMSG.reset_mock()


+ 1
- 1
tests/modules/test_nickuser.py View File

@@ -36,7 +36,7 @@ def test_register(nickbot):
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.setpass: usage: ".setpass newpass" or ".setpass oldpass newpass"')
nickbot.act_PRIVMSG.reset_mock()
pm(nickbot, ".setpass foobar")
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.setpass: Your password has been set to "foobar".')
nickbot.act_PRIVMSG.assert_called_once_with('chatter', '.setpass: You\'ve been logged in and your password has been set to "foobar".')
nickbot.act_PRIVMSG.reset_mock()




+ 3
- 4
tests/test_jsonrpc.py View File

@@ -3,7 +3,6 @@ import pytest
from pyircbot import jsonrpc
from threading import Thread
from random import randint
from socket import SHUT_RDWR
from time import sleep


@@ -37,7 +36,7 @@ def j1testserver():
Thread(target=server.serve, daemon=True).start()
sleep(0.1) # Give the serve() time to set up the serversocket
yield (server, port)
server._Server__transport.s.shutdown(SHUT_RDWR)
server._Server__transport.close()


@pytest.fixture
@@ -48,9 +47,9 @@ def j2testserver():
server.register_function(sample)
server.register_instance(_sample(), name="obj")
Thread(target=server.serve, daemon=True).start()
sleep(0.1) # Give the serve() time to set up the serversocket
sleep(0.2) # Give the serve() time to set up the serversocket
yield (server, port)
server._Server__transport.s.shutdown(SHUT_RDWR)
server._Server__transport.close()


# Basic functionality


Loading…
Cancel
Save