-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from CactusDev/test/magic-commands
Magic command tests
- Loading branch information
Showing
9 changed files
with
608 additions
and
477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ def join(iterable, delimeter): | |
yield item | ||
|
||
|
||
@Command.command() | ||
class Temmie(Command): | ||
"awwAwa!!" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pytest | ||
|
||
from cactusbot.commands.magic import Cactus | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_default(): | ||
assert (await Cactus()).text == "Ohai! I'm CactusBot! :cactus:" | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_docs(): | ||
assert (await Cactus("docs")).text == ("Check out my documentation at " | ||
"cactusbot.rtfd.org.") | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_twitter(): | ||
assert (await Cactus("twitter")).text == ( | ||
"You can follow the team behind CactusBot at: " | ||
"twitter.com/CactusDevTeam") | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_github(): | ||
assert (await Cactus("github")).text == ( | ||
"Check out my GitHub repository at: github.com/CactusDev/CactusBot") | ||
assert (await Cactus("github", "cactusbot")).text == ( | ||
"Check out my GitHub repository at: github.com/CactusDev/CactusBot") | ||
assert (await Cactus("github", "CactusDev")).text == ( | ||
"Check out the CactusDev GitHub organization at: github.com/CactusDev") | ||
assert (await Cactus("github", "issue")).text == ( | ||
"Create a GitHub issue at: github.com/CactusDev/CactusBot/issues") | ||
assert (await Cactus("github", "CactusAPI")).text == ( | ||
"Check out the GitHub repository for CactusAPI at: " | ||
"github.com/CactusDev/CactusAPI") | ||
assert (await Cactus("github", "SEPAL")).text == ( | ||
"Check out the GitHub repository for Sepal at: " | ||
"github.com/CactusDev/Sepal") | ||
assert (await Cactus("github", "assets")).text == ( | ||
"Check out the CactusDev assets at: github.com/CactusDev/CactusAssets") | ||
assert (await Cactus("github", "nonexistant")).text == ( | ||
"Unknown project 'nonexistant'.") | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_help(): | ||
assert (await Cactus("help")) == ( | ||
"Try our docs (!cactus docs). " | ||
"If that doesn't help, tweet at us (!cactus twitter)!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import pytest | ||
|
||
from cactusbot.commands.magic import Cube, Temmie | ||
from cactusbot.packets import MessagePacket | ||
|
||
async def verify_cube(packet, expected): | ||
_, *args = packet[1:].text.split() | ||
response = (await Cube(*args, username=packet.user, packet=packet)) | ||
if isinstance(response, str): | ||
assert response == expected | ||
elif isinstance(response, MessagePacket): | ||
assert response.text == expected | ||
else: | ||
raise TypeError | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_cube(): | ||
|
||
await verify_cube( | ||
MessagePacket("!cube", user="Username"), | ||
"Username³" | ||
) | ||
|
||
await verify_cube( | ||
MessagePacket("!cube 2"), | ||
"8. Whoa, that's 2Cubed!" | ||
) | ||
|
||
await verify_cube( | ||
MessagePacket("!cube a b c d e f g h"), | ||
' · '.join([n + '³' for n in "a b c d e f g h".split()]) | ||
) | ||
|
||
await verify_cube( | ||
MessagePacket("!cube a b c d e f g h i"), | ||
"Whoa, that's 2 many cubes!" | ||
) | ||
|
||
await verify_cube( | ||
MessagePacket("!cube 3 eggs and 4 slices of toast"), | ||
"27 · eggs³ · and³ · 64 · slices³ · of³ · toast³" | ||
) | ||
|
||
await verify_cube( | ||
MessagePacket("!cube lots of taco salad ", ("emoji", "😃")), | ||
"lots³ · of³ · taco³ · salad³ · 😃³" | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_temmie(): | ||
|
||
await Temmie() | ||
|
||
assert (await Temmie("hoi")).text == "hOI!!!!!! i'm tEMMIE!!" | ||
|
||
assert not (await Temmie("hoi")).action | ||
assert (await Temmie("flakes")).action |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.