-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* clean up models dir * use dedicated test resources * create dedicated test resources * add close Action coverage * add exits Action tests * add say Action tests * add open Action tests * add quit Action tests * add logout Action tests, update existing tests * update command and output tests * add missing client test coverage * add missing door test coverage * add register Action tests, improve database factory * add login Action tests * add inventory Action tests * update github workflow * speed up database fixture, and remove test sleep * only hash db fixture password once * add drop Action tests * add get Action tests * add finalize Action tests * add move Action tests * add look Action tests, improve existing tests * add schedule event tests
- Loading branch information
1 parent
642e041
commit a0ced2e
Showing
50 changed files
with
1,299 additions
and
295 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
DATABASE_PATH=test_database.db | ||
DATABASE_PATH=:memory: | ||
SERVER_PORT=51234 | ||
|
||
MOTD_PATH=/cibo/resources/motd.txt | ||
ROOMS_PATH=/cibo/resources/rooms.json | ||
DOORS_PATH=/cibo/resources/doors.json | ||
ITEMS_PATH=/cibo/resources/items.json | ||
MOTD_PATH=/tests/resources/motd.txt | ||
ROOMS_PATH=/tests/resources/rooms.json | ||
DOORS_PATH=/tests/resources/doors.json | ||
ITEMS_PATH=/tests/resources/items.json |
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
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
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
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
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
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 |
---|---|---|
@@ -1,12 +1,63 @@ | ||
from tests.conftest import ClientFactory, CloseActionFactory | ||
from cibo.client import ClientLoginState | ||
from cibo.output import Announcement | ||
from tests.conftest import CloseActionFactory | ||
|
||
|
||
class TestCloseAction(ClientFactory, CloseActionFactory): | ||
class TestCloseAction(CloseActionFactory): | ||
def test_action_close_aliases(self): | ||
assert self.close.aliases() == ["close"] | ||
|
||
def test_action_close_required_args(self): | ||
assert not self.close.required_args() | ||
|
||
def test_action_close_process(self): | ||
self.close.process(self.mock_client, "close", ["north"]) | ||
def test_action_close_process_not_logged_in(self): | ||
self.client.login_state = ClientLoginState.PRE_LOGIN | ||
|
||
self.close.process(self.client, "close", ["n"]) | ||
|
||
self.output.send_prompt.assert_called_once_with(self.client) | ||
|
||
def test_action_close_process_missing_args(self): | ||
self.close.process(self.client, "close", []) | ||
|
||
self.output.send_private_message.assert_called_with( | ||
self.client, "You close your eyes and daydream about money and success." | ||
) | ||
|
||
def test_action_close_process_door_is_closed(self): | ||
self.close.process(self.client, "close", ["n"]) | ||
|
||
self.output.send_private_message.assert_called_with( | ||
self.client, "A wooden door is already closed." | ||
) | ||
|
||
def test_action_close_process_door_is_locked(self): | ||
self.close.process(self.client, "close", ["s"]) | ||
|
||
self.output.send_private_message.assert_called_with( | ||
self.client, "A steel security door is already closed." | ||
) | ||
|
||
def test_action_close_process_door_not_found(self): | ||
self.close.process(self.client, "close", ["w"]) | ||
|
||
self.output.send_private_message.assert_called_with( | ||
self.client, "There's nothing to close." | ||
) | ||
|
||
def test_action_close_process_close_door(self): | ||
self.close.process(self.client, "close", ["e"]) | ||
|
||
door = self.close.doors.get_by_room_ids(1, 3) | ||
assert door.is_closed | ||
|
||
self.output.send_local_announcement.assert_called_once_with( | ||
Announcement( | ||
self_message="You close a propped-open door.", | ||
room_message="[cyan]frank[/] closes a propped-open door.", | ||
adjoining_room_message="A propped-open door closes.", | ||
), | ||
self.client, | ||
1, | ||
3, | ||
) |
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,58 @@ | ||
from cibo.client import ClientLoginState | ||
from cibo.models.data.item import Item | ||
from cibo.models.data.player import Player | ||
from cibo.output import Announcement | ||
from tests.conftest import DropActionFactory | ||
|
||
|
||
class TestDropAction(DropActionFactory): | ||
def test_action_drop_aliases(self): | ||
assert self.drop.aliases() == ["drop"] | ||
|
||
def test_action_drop_required_args(self): | ||
assert not self.drop.required_args() | ||
|
||
def test_action_drop_process_not_logged_in(self): | ||
self.client.login_state = ClientLoginState.PRE_LOGIN | ||
|
||
self.drop.process(self.client, "drop", []) | ||
|
||
self.output.send_prompt.assert_called_once_with(self.client) | ||
|
||
def test_action_drop_process_missing_args(self): | ||
self.drop.process(self.client, "drop", []) | ||
|
||
self.output.send_private_message.assert_called_with( | ||
self.client, "Drop what? Your pants? No way!" | ||
) | ||
|
||
def test_action_drop_process_inventory_item_not_found(self, _fixture_database): | ||
self.client.player = Player.get_by_name("frank") | ||
self.give_item_to_player(2, self.client.player) | ||
|
||
self.drop.process(self.client, "drop", ["spoon"]) | ||
|
||
self.output.send_private_message.assert_called_with( | ||
self.client, "You scour your inventory, but can't find that." | ||
) | ||
|
||
def test_action_drop_process_dropped_tem(self, _fixture_database): | ||
self.client.player = Player.get_by_name("frank") | ||
self.give_item_to_player(2, self.client.player) | ||
|
||
self.drop.process(self.client, "drop", ["fork"]) | ||
|
||
item = Item.get_by_id(2) | ||
|
||
assert not item.player | ||
assert item.room_id == 1 | ||
|
||
self.output.send_local_announcement.assert_called_once_with( | ||
Announcement( | ||
self_message="You drop a metal fork.", | ||
room_message="[cyan]frank[/] drops a metal fork.", | ||
adjoining_room_message=None, | ||
), | ||
self.client, | ||
1, | ||
) |
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,24 @@ | ||
from cibo.client import ClientLoginState | ||
from tests.conftest import ExitsActionFactory | ||
|
||
|
||
class TestExitsAction(ExitsActionFactory): | ||
def test_action_exits_aliases(self): | ||
assert self.exits.aliases() == ["exits"] | ||
|
||
def test_action_exits_required_args(self): | ||
assert not self.exits.required_args() | ||
|
||
def test_action_exits_process_not_logged_in(self): | ||
self.client.login_state = ClientLoginState.PRE_LOGIN | ||
|
||
self.exits.process(self.client, "exits", []) | ||
|
||
self.output.send_prompt.assert_called_once_with(self.client) | ||
|
||
def test_action_exits_process(self): | ||
self.exits.process(self.client, "exits", []) | ||
|
||
self.output.send_private_message.assert_called_with( | ||
self.client, "[green]Exits:[/] east, north, south, west" | ||
) |
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,57 @@ | ||
from cibo.client import ClientLoginState | ||
from cibo.models.data.player import Player | ||
from tests.conftest import FinalizeActionFactory | ||
|
||
|
||
class TestFinalizeAction(FinalizeActionFactory): | ||
def test_action_finalize_aliases(self): | ||
assert self.finalize.aliases() == ["finalize"] | ||
|
||
def test_action_finalize_required_args(self): | ||
assert not self.finalize.required_args() | ||
|
||
def test_action_finalize_process_logged_in(self): | ||
self.client.login_state = ClientLoginState.LOGGED_IN | ||
|
||
self.finalize.process(self.client, "finalize", []) | ||
|
||
self.output.send_private_message.assert_called_with( | ||
self.client, | ||
"You finalize your written will, leaving your whole estate to your cat.", | ||
) | ||
|
||
def test_action_finalize_process_not_registered(self): | ||
self.finalize.process(self.client, "finalize", []) | ||
|
||
self.output.send_private_message.assert_called_with( | ||
self.client, | ||
"You'll need to [green]register[/] before you can [green]finalize[/].", | ||
) | ||
|
||
def test_action_finalize_process_player_already_exists(self, _fixture_database): | ||
self.client.registration = Player( | ||
name="frank", password="abcd1234", current_room_id=1 | ||
) | ||
|
||
self.finalize.process(self.client, "finalize", []) | ||
|
||
self.output.send_private_message.assert_called_with( | ||
self.client, | ||
"Sorry, turns out the name [cyan]frank[/] is already taken. Please [green]register[/] again with a different name.", | ||
) | ||
|
||
def test_action_finalize_process_create_player(self, _fixture_database): | ||
self.client.registration = Player( | ||
name="jennifer", password="abcd1234", current_room_id=1 | ||
) | ||
|
||
self.finalize.process(self.client, "finalize", []) | ||
|
||
assert not self.client.is_registered | ||
player = Player.get_by_name("jennifer") | ||
assert len(player.inventory) == 1 | ||
|
||
self.output.send_private_message.assert_called_with( | ||
self.client, | ||
"[cyan]jennifer[/] has been created. You can now [green]login[/] with this player.", | ||
) |
Oops, something went wrong.