Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sjohnson31 committed Feb 8, 2020
1 parent b3353c9 commit 7f701ce
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
3 changes: 0 additions & 3 deletions api/src/game_state_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ def __init__(self, room_store: RoomStore):
self._rooms = {}
self.room_store = room_store

def valid_previous_rooms(self) -> list:
return self.room_store.get_all_room_ids()

def new_connection_request(self, client: Hashable, room_id: str) -> Reply:
if self._rooms.get(room_id, False):
self._rooms[room_id].clients.add(client)
Expand Down
1 change: 0 additions & 1 deletion api/src/wsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def __init__(self, port, gss):
asyncio.set_event_loop(self._loop)
self.port = port
self.gss = gss
self._valid_room_ids = set(self.gss.valid_previous_rooms())

@staticmethod
async def process_request(path, request_headers):
Expand Down
57 changes: 57 additions & 0 deletions api/tests/test_game_state_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,60 @@ def test_delete_after_load(gss_with_client):
{'action': 'delete', 'data': valid_data['id']}, TEST_ROOM_ID,
)
assert len(reply.data) == 0


def test_move_existing_token(gss_with_client):
gss_with_client.process_update(valid_update, TEST_ROOM_ID)
updated_token = {
'id': valid_data['id'],
'icon_id': valid_data['icon_id'],
'start_x': 7,
'start_y': 8,
'start_z': 9,
'end_x': 8,
'end_y': 9,
'end_z': 10,
}
reply = gss_with_client.process_update(
{'action': 'update', 'data': updated_token}, TEST_ROOM_ID
)
assert len(reply.data) == 1
assert reply.data[0] == updated_token


def test_ping(gss_with_client):
valid_ping = {'key': 'some_id', 'x': 4, 'y': 4}
reply = gss_with_client.process_update(
{'action': 'ping', 'data': valid_ping}, TEST_ROOM_ID
)
assert reply.type == 'ping'
assert reply.data == valid_ping


def test_invalid_action(gss_with_client):
with pytest.raises(MessageError):
gss_with_client.process_update(
{'action': 'destroy all humans', 'data': valid_data}, TEST_ROOM_ID
)


def test_invalid_data(gss_with_client):
with pytest.raises(MessageError):
gss_with_client.process_update(
{'action': 'create', 'data': 'destroy all humans'}, TEST_ROOM_ID
)


def test_incomplete_message(gss_with_client):
with pytest.raises(MessageError):
gss_with_client.process_update({'action': 'create'}, TEST_ROOM_ID)
with pytest.raises(MessageError):
gss_with_client.process_update({'data': valid_data}, TEST_ROOM_ID)


def test_delete_with_full_token(gss_with_client):
gss_with_client.process_update(valid_update, TEST_ROOM_ID)
with pytest.raises(MessageError):
gss_with_client.process_update(
{'action': 'delete', 'data': valid_data}, TEST_ROOM_ID
)

0 comments on commit 7f701ce

Please sign in to comment.