1
|
|
|
# Copyright 2017 Starbot Discord Project |
2
|
|
|
# |
3
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
4
|
|
|
# you may not use this file except in compliance with the License. |
5
|
|
|
# You may obtain a copy of the License at |
6
|
|
|
# |
7
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
8
|
|
|
# |
9
|
|
|
# Unless required by applicable law or agreed to in writing, software |
10
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
11
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12
|
|
|
# See the License for the specific language governing permissions and |
13
|
|
View Code Duplication |
# limitations under the License. |
|
|
|
|
14
|
|
|
|
15
|
|
|
import unittest |
16
|
|
|
from api import message, plugin, bot |
17
|
|
|
from plugins import botutils |
18
|
|
|
from tests.fake_server import Server |
19
|
|
|
|
20
|
|
|
class TestBotutilsSuite(unittest.TestCase): |
21
|
|
|
|
22
|
|
|
def test_srcutils_import(self): |
23
|
|
|
result = botutils.onInit(__import__('api.plugin')) |
24
|
|
|
self.assertEqual(type(result), plugin.Plugin) |
25
|
|
View Code Duplication |
|
|
|
|
|
26
|
|
|
|
27
|
|
|
def test_botutils_plugin(self): |
28
|
|
|
result = botutils.onInit(__import__('api.plugin')) |
29
|
|
|
bot.Bot.plugins.append(result) |
30
|
|
|
for command in result.commands: |
31
|
|
|
bot.Bot.commands.append(command) |
32
|
|
|
|
33
|
|
|
msg = message.Message(body="") |
34
|
|
|
msg.command = "plugins" |
35
|
|
|
result = yield from botutils.onCommand(msg) |
36
|
|
View Code Duplication |
self.assertEqual(type(result), type(msg)) |
|
|
|
|
37
|
|
|
|
38
|
|
|
|
39
|
|
|
def test_botutils_commands(self): |
40
|
|
|
result = botutils.onInit(__import__('api.plugin')) |
41
|
|
|
bot.Bot.plugins.append(result) |
42
|
|
|
for command in result.commands: |
43
|
|
|
bot.Bot.commands.append(command) |
44
|
|
|
|
45
|
|
|
msg = message.Message(body="") |
46
|
|
|
msg.command = "commands" |
47
|
|
|
result = yield from botutils.onCommand(msg) |
48
|
|
|
self.assertEqual(type(result), type(msg)) |
49
|
|
|
|
50
|
|
|
def test_botutils_help(self): |
51
|
|
|
result = botutils.onInit(__import__('api.plugin')) |
52
|
|
|
bot.Bot.plugins.append(result) |
53
|
|
|
for command in result.commands: |
54
|
|
|
bot.Bot.commands.append(command) |
55
|
|
|
|
56
|
|
|
msg = message.Message(body="") |
57
|
|
|
msg.command = "help" |
58
|
|
|
result = yield from botutils.onCommand(msg) |
59
|
|
|
self.assertEqual(type(result), type(msg)) |
60
|
|
|
|
61
|
|
|
def test_botutils_info(self): |
62
|
|
|
msg = message.Message(body="") |
63
|
|
|
msg.command = "info" |
64
|
|
|
result = yield from botutils.onCommand(msg) |
65
|
|
|
self.assertEqual(type(result), type(msg)) |
66
|
|
|
|
67
|
|
|
def test_botutils_plugintree(self): |
68
|
|
|
msg = message.Message(body="") |
69
|
|
|
msg.command = "plugintree" |
70
|
|
|
result = yield from botutils.onCommand(msg) |
71
|
|
|
self.assertEqual(type(result), type(msg)) |
72
|
|
|
|
73
|
|
|
def test_botutils_uptime(self): |
74
|
|
|
msg = message.Message(body="") |
75
|
|
|
msg.command = "uptime" |
76
|
|
|
result = yield from botutils.onCommand(msg) |
77
|
|
|
self.assertEqual(type(result), type(msg)) |
78
|
|
|
|
79
|
|
|
def test_botutils_hostinfo(self): |
80
|
|
|
server = Server |
81
|
|
|
server.me = 'StarBot' |
82
|
|
|
|
83
|
|
|
msg = message.Message(body="") |
84
|
|
|
msg.command = "hostinfo" |
85
|
|
|
msg.server = server |
86
|
|
|
|
87
|
|
|
result = yield from botutils.onCommand(msg) |
88
|
|
|
self.assertEqual(type(result), type(msg)) |
89
|
|
|
|
90
|
|
|
def test_botutils_cpuinfo(self): |
91
|
|
|
msg = message.Message(body="") |
92
|
|
|
msg.command = "cpuinfo" |
93
|
|
|
result = yield from botutils.onCommand(msg) |
94
|
|
|
self.assertEqual(type(result), type(msg)) |
95
|
|
|
|