forked from DanielOaks/irctest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_roleplay.py
68 lines (58 loc) · 2.94 KB
/
test_roleplay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from irctest import cases
from irctest.numerics import ERR_CANNOTSENDRP
from irctest.irc_utils.random import random_name
class RoleplayTestCase(cases.BaseServerTestCase):
def customizedConfig(self):
config = self.controller.baseConfig()
config['roleplay'] = {
'enabled': True,
}
return self.controller.addMysqlToConfig(config)
@cases.SpecificationSelector.requiredBySpecification('Oragono')
def testRoleplay(self):
bar = random_name('bar')
qux = random_name('qux')
chan = random_name('#chan')
self.connectClient(bar, name=bar, capabilities=['batch', 'labeled-response', 'message-tags', 'server-time'])
self.connectClient(qux, name=qux, capabilities=['batch', 'labeled-response', 'message-tags', 'server-time'])
self.joinChannel(bar, chan)
self.joinChannel(qux, chan)
self.getMessages(bar)
# roleplay should be forbidden because we aren't +E yet
self.sendLine(bar, 'NPC %s bilbo too much bread' % (chan,))
reply = self.getMessages(bar)[0]
self.assertEqual(reply.command, ERR_CANNOTSENDRP)
self.sendLine(bar, 'MODE %s +E' % (chan,))
reply = self.getMessages(bar)[0]
self.assertEqual(reply.command, 'MODE')
self.assertMessageEqual(reply, command='MODE', params=[chan, '+E'])
self.getMessages(qux)
self.sendLine(bar, 'NPC %s bilbo too much bread' % (chan,))
reply = self.getMessages(bar)[0]
self.assertEqual(reply.command, 'PRIVMSG')
self.assertEqual(reply.params[0], chan)
self.assertTrue(reply.prefix.startswith('*bilbo*!'))
self.assertIn('too much bread', reply.params[1])
reply = self.getMessages(qux)[0]
self.assertEqual(reply.command, 'PRIVMSG')
self.assertEqual(reply.params[0], chan)
self.assertTrue(reply.prefix.startswith('*bilbo*!'))
self.assertIn('too much bread', reply.params[1])
self.sendLine(bar, 'SCENE %s dark and stormy night' % (chan,))
reply = self.getMessages(bar)[0]
self.assertEqual(reply.command, 'PRIVMSG')
self.assertEqual(reply.params[0], chan)
self.assertTrue(reply.prefix.startswith('=Scene=!'))
self.assertIn('dark and stormy night', reply.params[1])
reply = self.getMessages(qux)[0]
self.assertEqual(reply.command, 'PRIVMSG')
self.assertEqual(reply.params[0], chan)
self.assertTrue(reply.prefix.startswith('=Scene=!'))
self.assertIn('dark and stormy night', reply.params[1])
# test history storage
self.sendLine(qux, 'CHATHISTORY LATEST %s * 10' % (chan,))
reply = [msg for msg in self.getMessages(qux) if msg.command == 'PRIVMSG' and 'bilbo' in msg.prefix][0]
self.assertEqual(reply.command, 'PRIVMSG')
self.assertEqual(reply.params[0], chan)
self.assertTrue(reply.prefix.startswith('*bilbo*!'))
self.assertIn('too much bread', reply.params[1])