summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe Pina <fopina@gmail.com>2016-09-19 17:22:00 +0100
committerJoel Rosdahl <joel@rosdahl.net>2016-09-20 22:45:26 +0200
commitf2ada2ad57cef7eec0da84a04cd78a126ff47bc3 (patch)
tree02cc1545395deccdfbf6db355e0b69baf03ff7fb
parent505cdd6ba74eb609d80d1ac00332bec9f5495f91 (diff)
downloadminiircd-f2ada2ad57cef7eec0da84a04cd78a126ff47bc3.tar.gz
miniircd-f2ada2ad57cef7eec0da84a04cd78a126ff47bc3.zip
PEP8 + test.py
-rwxr-xr-xminiircd12
-rw-r--r--test.py54
2 files changed, 62 insertions, 4 deletions
diff --git a/miniircd b/miniircd
index 7ae4d37..8db1412 100755
--- a/miniircd
+++ b/miniircd
@@ -270,17 +270,21 @@ class Client(object):
self.reply("331 %s %s :No topic is set"
% (self.nickname, channel.name))
names_prefix = "353 %s = %s :" % (self.nickname, channelname)
- names = names_prefix
- # max length: reply prefix ":server_name(space)" plus CRLF in the end
+ names = ''
+ # max length: reply prefix ":server_name(space)"
+ # plus CRLF in the end
names_max_len = 512 - (len(self.server.name) + 2 + 2)
for name in sorted(x.nickname for x in channel.members):
+ if not names:
+ names = names_prefix + name
# using >= to include the space between "names" and "name"
- if len(names) + len(name) >= names_max_len:
+ elif len(names) + len(name) >= names_max_len:
self.reply(names)
names = names_prefix + name
else:
names += ' ' + name
- self.reply(names)
+ if names:
+ self.reply(names)
self.reply("366 %s %s :End of NAMES list"
% (self.nickname, channelname))
diff --git a/test.py b/test.py
index 3e3cd86..5069eb1 100644
--- a/test.py
+++ b/test.py
@@ -243,6 +243,60 @@ class TestBasicStuff(ServerFixture):
self.expect("lemur", r":lemur!lemur@127.0.0.1 PART #fisk :boa")
self.expect("apa", r":lemur!lemur@127.0.0.1 PART #fisk :boa")
+ def test_join_and_name_many_users(self):
+ base_nick = 'A' * 49
+ # :FQDN 353 nick = #fisk :
+ base_len = len(socket.getfqdn()) + 66
+
+ one_line = (512 - base_len) / 50
+ nick_list_one = []
+ for i in range(one_line):
+ long_nick = '%s%d' % (base_nick, i)
+ nick_list_one.append(long_nick)
+ self.connect(long_nick)
+ self.send(long_nick, "JOIN #fisk")
+ self.expect(
+ long_nick,
+ r":%(nick)s!%(nick)s@127.0.0.1 JOIN #fisk" % {
+ 'nick': long_nick
+ }
+ )
+ self.expect(long_nick, r":local\S+ 331 %s #fisk :.*" % long_nick)
+ self.expect(
+ long_nick,
+ r":local\S+ 353 %s = #fisk :%s" % (
+ long_nick, ' '.join(nick_list_one)
+ )
+ )
+ self.expect(long_nick, r":local\S+ 366 %s #fisk :.*" % long_nick)
+
+ nick_list_two = []
+ for i in range(10 - one_line):
+ long_nick = '%s%d' % (base_nick, one_line + i)
+ nick_list_two.append(long_nick)
+ self.connect(long_nick)
+ self.send(long_nick, "JOIN #fisk")
+ self.expect(
+ long_nick,
+ r":%(nick)s!%(nick)s@127.0.0.1 JOIN #fisk" % {
+ 'nick': long_nick
+ }
+ )
+ self.expect(long_nick, r":local\S+ 331 %s #fisk :.*" % long_nick)
+ self.expect(
+ long_nick,
+ r":local\S+ 353 %s = #fisk :%s" % (
+ long_nick, ' '.join(nick_list_one)
+ )
+ )
+ self.expect(
+ long_nick,
+ r":local\S+ 353 %s = #fisk :%s" % (
+ long_nick, ' '.join(nick_list_two)
+ )
+ )
+ self.expect(long_nick, r":local\S+ 366 %s #fisk :.*" % long_nick)
+
def test_ison(self):
self.connect("apa")
self.send("apa", "ISON apa lemur")