Skip to content

Commit

Permalink
Add ability to pass include parameters to list_nodes()
Browse files Browse the repository at this point in the history
Fix broken server tests
  • Loading branch information
iamkubi committed Jan 10, 2022
1 parent ea899d7 commit b45ce82
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
13 changes: 10 additions & 3 deletions pydactyl/api/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@
class Nodes(PterodactylAPI):
"""Class for interacting with the Pterdactyl Nodes API."""

def list_nodes(self):
"""List all nodes."""
def list_nodes(self, include=None):
"""List all nodes.
Args:
include(str): Comma separated list of includes
"""
endpoint = 'application/nodes'
response = self._api_request(endpoint=endpoint)
params = {}
if include is not None:
params['include'] = include
response = self._api_request(endpoint=endpoint, params=params)
return PaginatedResponse(self, endpoint, response)

def get_node_info(self, node_id):
Expand Down
10 changes: 10 additions & 0 deletions tests/application/nodes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ def setUp(self):
def test_list_nodes(self, mock_api):
expected = {
'endpoint': 'application/nodes',
'params': {},
}
self.client.nodes.list_nodes()
mock_api.assert_called_with(**expected)

@mock.patch('pydactyl.api.base.PterodactylAPI._api_request')
def test_list_nodes_with_includes(self, mock_api):
expected = {
'endpoint': 'application/nodes',
'params': {'include': 'location,other'},
}
self.client.nodes.list_nodes(include='location,other')
mock_api.assert_called_with(**expected)

@mock.patch('pydactyl.api.base.PterodactylAPI._api_request')
def test_get_node_info(self, mock_api):
expected = {
Expand Down
4 changes: 2 additions & 2 deletions tests/application/servers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ def test_create_server_without_allocation_or_location_raises(self):
def test_create_server_with_location(self, mock_api):
self.client.servers.create_server('test server', 1, 2, 3, 4, 5, 6,
location_ids=[7])
mock_api.assert_called_with(mock.ANY)
mock_api.assert_called()

@mock.patch('pydactyl.api.base.PterodactylAPI._api_request')
def test_create_server_with_allocation(self, mock_api):
self.client.servers.create_server('test server', 1, 2, 3, 4, 5, 6,
default_allocation=1234)
mock_api.assert_called_with(mock.ANY)
mock_api.assert_called()


if __name__ == '__main__':
Expand Down

0 comments on commit b45ce82

Please sign in to comment.