def test_update_writesChangesToMemory(self): srv1 = Server() srv1.Path = '/road/to/riches' srv2 = Server() srv2.Path = '/another/one' srv_updated = Server() srv_updated.Path = '/road/to/owning a home' self.plant_server([srv1, srv2]) manager.update_server('/road/to/riches', srv_updated) self.assertIn(srv_updated, manager._servers)
def test_process_set_type_invokesUpdateServer(self, mock_from, mock_getby, mock_update): self.fs.create_file(get_config_location()) args = ['set', 'bestest server ever', 'type', 'spigot'] planted_server = Server() planted_server.Alias = 'bestest server ever' mock_getby.return_value = planted_server manager.process_server(args) mock_update.assert_called_once() called_args = mock_update.call_args[0] self.assertEqual( 'bestest server ever', called_args[0], 'Update should have been invoked with original identifier') self.assertEqual('spigot', called_args[1].Type, 'Update was invoked with a non-updated object')
def test_getByIdentifier_returnsNoneIfNoMatch(self): srv1 = Server() srv1.Path = '/path/to/gold' srv2 = Server() srv2.Path = '/not/the/answer' self.plant_server([srv1, srv2]) result = manager.get_server_by_identifier('bruh') self.assertIsNone(result)
def test_getByIdentifier_returnsMatch(self): srv1 = Server() srv1.Path = '/path/to/gold' srv2 = Server() srv2.Path = '/not/the/answer' manager._servers = [srv1, srv2] result = manager.get_server_by_identifier(srv1.Path) self.assertEqual(srv1, result)
def test_scan_removesDeletedServers(self, mock_register, mock_print, mock_is_forge): # Create two servers, but only keep 1 of them on disk srv_stays = Server() srv_stays.Path = '/srvs/creative1' srv_stays.Type = FORGE srv_delete = Server() srv_delete.Path = '/srvs/creative2' srv_delete.Type = FORGE self.fs.create_dir(srv_stays.Path) manager._servers = [srv_stays, srv_delete] result = manager.scan_directory_for_servers(scan_path='/srvs/', verbosity=1) mock_register.assert_called_once_with(srv_stays.Path, FORGE) mock_print.assert_called_with('Found 1 servers') self.assertEqual(1, result)
class ServerControllerTests(TestCase): srv: Server = Server() control: ServerController VIR_PATH = 'D:\\Minecraft\\Servers' def setUp(self): self.setUpPyfakefs() self.srv.Path = self.VIR_PATH self.srv.Type = FORGE self.control = ForgeController(self.srv) def test_parser_passthru(self): args = ['my-identifier', 'pass', 'op TargetPlayer'] parsed = self.control.get_parser().parse_args(args) assert parsed.identifier == 'my-identifier' assert parsed.action == 'pass' assert parsed.command == 'op TargetPlayer' def test_parser_start(self): args = ['de ayedee', 'start'] parsed = self.control.get_parser().parse_args(args) assert parsed.identifier == 'de ayedee' assert parsed.action == 'start' def test_parser_stop(self): args = ['wheres waldo', 'stop'] parsed = self.control.get_parser().parse_args(args) assert parsed.identifier == 'wheres waldo' assert parsed.action == 'stop' def test_parser_restart(self): args = ['look at my head', 'restart'] parsed = self.control.get_parser().parse_args(args) assert parsed.identifier == 'look at my head' assert parsed.action == 'restart'
def test_update_throwsIfUnknownServer(self, mock_getby): updated = Server() with self.assertRaises(KeyError) as kex: manager.update_server('no such thing', updated) self.assertEqual('No server "no such thing"', kex.exception.args[0])