def test_topic():
    """ TOPIC command """
    assert like("TOPIC #test :New topic",
                pack_command("TOPIC", channel="#test", message="New topic"))
    assert like("TOPIC #test :",
                pack_command("TOPIC", channel="#test", message=""))
    assert like("TOPIC #test", pack_command("TOPIC", channel="#test"))
Example #2
0
def test_topic():
    ''' TOPIC command '''
    assert like("TOPIC #test :New topic", pack_command(
        "TOPIC", channel="#test", message="New topic"))
    assert like("TOPIC #test :", pack_command("TOPIC", channel="#test",
                                              message=""))
    assert like("TOPIC #test", pack_command("TOPIC", channel="#test"))
Example #3
0
def test_summon():
    ''' SUMMON command '''
    assert like("SUMMON Wiz remote.*.edu #Finnish", pack_command(
        "SUMMON", nick="Wiz", target="remote.*.edu", channel="#Finnish"))
    assert like("SUMMON Wiz remote.*.edu", pack_command(
        "SUMMON", nick="Wiz", target="remote.*.edu"))
    assert like("SUMMON Wiz", pack_command(
        "SUMMON", nick="Wiz"))
def test_part():
    """ PART command """
    assert like("PART #chan", pack_command("PART", channel="#chan"))
    assert like("PART #chan :msg",
                pack_command("PART", channel="#chan", message="msg"))
    assert like("PART ch1,ch2", pack_command("PART", channel=["ch1", "ch2"]))
    assert like("PART ch1,ch2 :msg",
                pack_command("PART", channel=["ch1", "ch2"], message="msg"))
Example #5
0
def test_summon():
    """ SUMMON command """
    assert like("SUMMON Wiz remote.*.edu #Finnish", pack_command(
        "SUMMON", nick="Wiz", target="remote.*.edu", channel="#Finnish"))
    assert like("SUMMON Wiz remote.*.edu", pack_command(
        "SUMMON", nick="Wiz", target="remote.*.edu"))
    assert like("SUMMON Wiz", pack_command(
        "SUMMON", nick="Wiz"))
def test_no_command():
    """ raise when command is None or empty """

    with pytest.raises(ValueError):
        pack_command(None)

    with pytest.raises(ValueError):
        pack_command("")
Example #7
0
def test_no_command():

    ''' raise when command is None or empty '''

    with pytest.raises(ValueError):
        pack_command(None)

    with pytest.raises(ValueError):
        pack_command("")
Example #8
0
def test_channelmode():
    ''' CHANNELMODE command '''
    assert like("MODE #Finnish +imI *!*@*.fi", pack_command(
        "CHANNELMODE", channel="#Finnish", modes="+imI", params="*!*@*.fi"))
    assert like("MODE #en-ops +v WiZ", pack_command(
        "CHANNELMODE", channel="#en-ops", modes="+v", params="WiZ"))
    # CHANNELMODE #Fins -s
    assert like("MODE #Fins -s", pack_command(
        "CHANNELMODE", channel="#Fins", modes="-s"))
Example #9
0
def test_part():
    ''' PART command '''
    assert like("PART #chan", pack_command("PART", channel="#chan"))
    assert like("PART #chan :msg", pack_command("PART", channel="#chan",
                                                message="msg"))
    assert like("PART ch1,ch2", pack_command("PART", channel=["ch1", "ch2"]))
    assert like("PART ch1,ch2 :msg", pack_command("PART",
                                                  channel=["ch1", "ch2"],
                                                  message="msg"))
Example #10
0
def test_links():
    ''' LINKS command '''
    assert like("LINKS *.edu *.bu.edu", pack_command("LINKS", remote="*.edu",
                                                     mask="*.bu.edu"))
    assert like("LINKS *.au", pack_command("LINKS", mask="*.au"))
    assert like("LINKS", pack_command("LINKS"))

    with pytest.raises(KeyError):
        pack_command("LINKS", remote="*.edu")
Example #11
0
def test_channelmode():
    """ CHANNELMODE command """
    assert like("MODE #Finnish +imI *!*@*.fi", pack_command(
        "CHANNELMODE", channel="#Finnish", modes="+imI", params="*!*@*.fi"))
    assert like("MODE #en-ops +v WiZ", pack_command(
        "CHANNELMODE", channel="#en-ops", modes="+v", params="WiZ"))
    # CHANNELMODE #Fins -s
    assert like("MODE #Fins -s", pack_command(
        "CHANNELMODE", channel="#Fins", modes="-s"))
def test_join():
    """ JOIN command """
    assert like("JOIN 0", pack_command("JOIN", channel=0))
    assert like("JOIN #chan", pack_command("JOIN", channel="#chan"))
    assert like("JOIN #chan key",
                pack_command("JOIN", channel="#chan", key="key"))
    assert like("JOIN ch1,ch2", pack_command("JOIN", channel=["ch1", "ch2"]))
    assert like("JOIN ch1,ch2 k1,k2",
                pack_command("JOIN", channel=["ch1", "ch2"], key=["k1", "k2"]))
def test_links():
    """ LINKS command """
    assert like("LINKS *.edu *.bu.edu",
                pack_command("LINKS", remote="*.edu", mask="*.bu.edu"))
    assert like("LINKS *.au", pack_command("LINKS", mask="*.au"))
    assert like("LINKS", pack_command("LINKS"))

    with pytest.raises(KeyError):
        pack_command("LINKS", remote="*.edu")
Example #14
0
def test_command():
    """ KICK command """
    assert like("KICK #Finnish WiZ", pack_command(
        "KICK", channel="#Finnish", nick="WiZ"))
    assert like("KICK #Finnish WiZ :Speaking English", pack_command(
        "KICK", channel="#Finnish", nick="WiZ", message="Speaking English"))
    assert like("KICK #Finnish WiZ,Wiz-Bot :msg", pack_command(
        "KICK", channel="#Finnish", nick=["WiZ", "Wiz-Bot"], message="msg"))
    assert like("KICK #ch1,#ch2 n1,n2 :msg", pack_command(
        "KICK", channel=["#ch1", "#ch2"], nick=["n1", "n2"], message="msg"))
Example #15
0
def test_join():
    ''' JOIN command '''
    assert like("JOIN 0", pack_command("JOIN", channel=0))
    assert like("JOIN #chan", pack_command("JOIN", channel="#chan"))
    assert like("JOIN #chan key", pack_command("JOIN", channel="#chan",
                                               key="key"))
    assert like("JOIN ch1,ch2", pack_command("JOIN", channel=["ch1", "ch2"]))
    assert like("JOIN ch1,ch2 k1,k2", pack_command("JOIN",
                                                   channel=["ch1", "ch2"],
                                                   key=["k1", "k2"]))
Example #16
0
def test_command():
    ''' KICK command '''
    assert like("KICK #Finnish WiZ", pack_command(
        "KICK", channel="#Finnish", nick="WiZ"))
    assert like("KICK #Finnish WiZ :Speaking English", pack_command(
        "KICK", channel="#Finnish", nick="WiZ", message="Speaking English"))
    assert like("KICK #Finnish WiZ,Wiz-Bot :msg", pack_command(
        "KICK", channel="#Finnish", nick=["WiZ", "Wiz-Bot"], message="msg"))
    assert like("KICK #ch1,#ch2 n1,n2 :msg", pack_command(
        "KICK", channel=["#ch1", "#ch2"], nick=["n1", "n2"], message="msg"))
def test_connect():
    """ CONNECT command """
    assert like(
        "CONNECT tolsun.oulu.fi 6667 *.edu",
        pack_command("CONNECT",
                     target="tolsun.oulu.fi",
                     port=6667,
                     remote="*.edu"))
    assert like("CONNECT tolsun.oulu.fi 6667",
                pack_command("CONNECT", target="tolsun.oulu.fi", port=6667))
def test_service():
    """ SERVICE command """
    assert like(
        "SERVICE nick * distribution type 0 :info",
        pack_command("SERVICE",
                     nick="nick",
                     distribution="distribution",
                     type="type",
                     info="info"))
Example #19
0
    def send(self, command: str, **kwargs: Any) -> None:
        """
        Send a message to the server.

        .. code-block:: python

            client.send("nick", nick="weatherbot")
            client.send("privmsg", target="#python", message="Hello, World!")

        """
        packed_command = pack_command(command, **kwargs).strip()
        self.send_raw(packed_command)
Example #20
0
    def send(self, command, **kwargs):
        """
        Send a message to the server.

        Examples
        --------
        client.send("nick", nick="weatherbot")
        client.send("privmsg", target="#python", message="Hello, World!")
        """
        packed_command = pack_command(command, **kwargs).strip()
        if not self.protocol:
            raise RuntimeError("Not connected")
        self.protocol.write(packed_command)
Example #21
0
    def send(self, command, **kwargs):
        """
        Send a message to the server.

        Examples
        --------
        client.send("nick", nick="weatherbot")
        client.send("privmsg", target="#python", message="Hello, World!")
        """
        packed_command = pack_command(command, **kwargs).strip()
        if not self.protocol:
            raise RuntimeError("Not connected")
        self.protocol.write(packed_command)
def test_ison():
    """ ISON command """
    assert like("ISON Wiz Michael syrk",
                pack_command("ISON", nick=["Wiz", "Michael", "syrk"]))
    assert like("ISON syrk", pack_command("ISON", nick="syrk"))
def test_pass():
    """ PASS command """
    assert like("PASS foo", pack_command("PASS", password="******"))
def test_die():
    """ DIE command """
    assert like("DIE", pack_command("DIE"))
Example #25
0
def test_ison():
    ''' ISON command '''
    assert like("ISON Wiz Michael syrk", pack_command(
        "ISON", nick=["Wiz", "Michael", "syrk"]))
    assert like("ISON syrk", pack_command(
        "ISON", nick="syrk"))
def test_kill():
    """ KILL command """
    assert like("KILL WiZ :Spamming joins",
                pack_command("KILL", nick="WiZ", message="Spamming joins"))
def test_away():
    """ AWAY command """
    assert like("AWAY :msg", pack_command("AWAY", message="msg"))
    assert like("AWAY", pack_command("AWAY"))
Example #28
0
def test_oper():
    ''' OPER command '''
    assert like("OPER user pass", pack_command("OPER", user="******",
                                               password="******"))
def test_quit():
    """ QUIT command """
    assert like("QUIT", pack_command("QUIT"))
    assert like("QUIT :message", pack_command("QUIT", message="message"))
Example #30
0
def test_nick():
    ''' NICK command '''
    assert like("NICK foo", pack_command("NICK", nick="foo"))
Example #31
0
def test_user():
    ''' USER command '''
    assert like("USER user 1 * :real", pack_command("USER", user="******",
                                                    realname="real", mode=1))
    assert like("USER user 0 * :real", pack_command("USER", user="******",
                                                    realname="real"))
Example #32
0
def test_pass():
    ''' PASS command '''
    assert like("PASS foo", pack_command("PASS", password="******"))
Example #33
0
def test_ignore_case():

    ''' input case doesn't matter '''

    assert "PASS foo" == pack_command("pASs", password="******")
Example #34
0
def test_unknown_command():

    ''' raise when command isn't known '''

    with pytest.raises(ValueError):
        pack_command("unknown_command", param="foo")
def test_user():
    """ USER command """
    assert like("USER user 1 * :real",
                pack_command("USER", user="******", realname="real", mode=1))
    assert like("USER user 0 * :real",
                pack_command("USER", user="******", realname="real"))
Example #36
0
def test_usermode():
    ''' USERMODE command '''
    assert like("MODE nick +w", pack_command("USERMODE",
                                             nick="nick", modes="+w"))
def test_usermode():
    """ USERMODE command """
    assert like("MODE nick +w",
                pack_command("USERMODE", nick="nick", modes="+w"))
Example #38
0
def test_restart():
    ''' RESTART command '''
    assert like("RESTART", pack_command("RESTART"))
Example #39
0
def test_wallops():
    ''' WALLOPS command '''
    assert like("WALLOPS :msg", pack_command("WALLOPS", message="msg"))
Example #40
0
def test_quit():
    ''' QUIT command '''
    assert like("QUIT", pack_command("QUIT"))
    assert like("QUIT :message", pack_command("QUIT", message="message"))
def test_pong():
    """ PONG command """
    assert like("PONG :msg", pack_command("PONG", message="msg"))
    assert like("PONG", pack_command("PONG"))
def test_users():
    """ USERS command """
    assert like("USERS", pack_command("USERS"))
def test_rehash():
    """ REHASH command """
    assert like("REHASH", pack_command("REHASH"))
def test_userhost():
    """ USERHOST command """
    assert like("USERHOST Wiz Michael syrk",
                pack_command("USERHOST", nick=["Wiz", "Michael", "syrk"]))
    assert like("USERHOST syrk", pack_command("USERHOST", nick="syrk"))
def test_restart():
    """ RESTART command """
    assert like("RESTART", pack_command("RESTART"))
Example #46
0
def test_userhost():
    ''' USERHOST command '''
    assert like("USERHOST Wiz Michael syrk", pack_command(
        "USERHOST", nick=["Wiz", "Michael", "syrk"]))
    assert like("USERHOST syrk", pack_command(
        "USERHOST", nick="syrk"))
def test_wallops():
    """ WALLOPS command """
    assert like("WALLOPS :msg", pack_command("WALLOPS", message="msg"))
Example #48
0
def test_die():
    ''' DIE command '''
    assert like("DIE", pack_command("DIE"))
def test_unknown_command():
    """ raise when command isn't known """

    with pytest.raises(ValueError):
        pack_command("unknown_command", param="foo")
Example #50
0
def test_rehash():
    ''' REHASH command '''
    assert like("REHASH", pack_command("REHASH"))
def test_ignore_case():
    """ input case doesn't matter """

    assert "PASS foo" == pack_command("pASs", password="******")
Example #52
0
def test_bad_command():

    ''' raise when command doesn't have upper '''

    with pytest.raises(ValueError):
        pack_command(object())
def test_nick():
    """ NICK command """
    assert like("NICK foo", pack_command("NICK", nick="foo"))
Example #54
0
def test_away():
    ''' AWAY command '''
    assert like("AWAY :msg", pack_command("AWAY", message="msg"))
    assert like("AWAY", pack_command("AWAY"))
def test_oper():
    """ OPER command """
    assert like("OPER user pass",
                pack_command("OPER", user="******", password="******"))
Example #56
0
def test_pong():
    ''' PONG command '''
    assert like("PONG :msg", pack_command("PONG", message="msg"))
    assert like("PONG", pack_command("PONG"))
Example #57
0
def test_whowas():
    ''' WHOWAS command '''
    assert like("WHOWAS WiZ 9", pack_command("WHOWAS", nick="WiZ", count=9))
    assert like("WHOWAS WiZ", pack_command("WHOWAS", nick="WiZ"))
Example #58
0
def test_kill():
    ''' KILL command '''
    assert like("KILL WiZ :Spamming joins", pack_command(
        "KILL", nick="WiZ", message="Spamming joins"))
Example #59
0
def test_service():
    ''' SERVICE command '''
    assert like("SERVICE nick * distribution type 0 :info", pack_command(
        "SERVICE", nick="nick", distribution="distribution",
        type="type", info="info"))
Example #60
0
def test_users():
    ''' USERS command '''
    assert like("USERS", pack_command("USERS"))