def add(c, e, channel, server, command, argv): """ Add a server to this channel only available as a private message due to the rcon password. """ args = ("name", "host", "port", "rcon", "servertype") if len(argv) < 5: return "usage: !add name host port rcon [normal|tv]" if len(argv) < 6: args = args[:5] else: if argv[5] != "tv": argv[5] = "normal" argv = map(unicode, argv) info = dict(zip(args, argv[1:])) try: ss = model.Server.query.filter_by(channel=channel, name=argv[1]).all() if len(ss) > 0: return "server '{0}' exists!".format(argv[1]) except sqlalchemy.orm.exc.NoResultFound: s = None s = model.Server(channel=channel, **info) channel.servers.append(s) model.session.commit() return "server '{0}' created!".format(s.name)
def test_file_arg_value_load(self): configure_main(config_arg='test.ini') server = model.Server() self.assertEqual(server.addr, '127.0.0.1') self.assertEqual(server.port, 80) self.assertEqual(server.udp, True) self.assertEqual(server.val_f, 0.5) self.assertEqual(server.val_d, {'a': 10, 'b': 20, 'c': 30}) self.assertEqual(server.val_l, [1, 2, 3, 4, 5, 6]) self.assertEqual(server.home, Path('../../..')) with self.assertRaises(AttributeError): self.conf.addr = '1.2.3.4' # not editable
def test_default_value_load(self): configure_main() server = model.Server() self.assertEqual(server.addr, '0.0.0.0') self.assertEqual(server.port, 8080) self.assertEqual(server.udp, False) self.assertEqual(server.val_f, 0.8) self.assertEqual(server.val_d, {'a': 1, 'b': 2, 'c': 3}) self.assertEqual(server.val_l, [1, 2, 3]) self.assertEqual(server.home, Path('..')) with self.assertRaises(AttributeError): self.conf.addr = '1.2.3.4' # not editable
def test_file_path_value_load_with_two_files(self): configure_main(config_path=['test.ini', 'test2.ini'], config_arg=None) server = model.Server() self.assertEqual(server.addr, '127.0.0.1') self.assertEqual(server.port, 80) self.assertEqual(server.udp, True) self.assertEqual(server.val_f, 0.5) self.assertEqual(server.val_d, {'a': 10, 'b': 20, 'c': 30}) self.assertEqual(server.val_l, [1, 2, 3, 4, 5, 6]) self.assertEqual(server.home, Path('../../..')) with self.assertRaises(AttributeError): self.conf.addr = '1.2.3.4' # not editable server = model.Database(immutable=True) self.assertEqual(server.addr, '192.168.0.1') self.assertEqual(server.port, 3333)
def test_ifconf_config_path(self): configure_main(config_path='test_all.ini', config_arg=None) server = model.Server() self.assertEqual(server.addr, '127.0.0.1') self.assertEqual(server.port, 80) self.assertEqual(server.udp, True) self.assertEqual(server.val_f, 0.5) self.assertEqual(server.val_d, {'a': 10, 'b': 20, 'c': 30}) self.assertEqual(server.val_l, [9, 9, 9]) self.assertEqual(server.home, Path('../../..')) with self.assertRaises(AttributeError): self.conf.addr = '1.2.3.4' # not editable server = model.Database(immutable=True) self.assertEqual(server.addr, '192.168.0.1') self.assertEqual(server.port, 3333)
import bottle import baza import model import re # vsako zdravilo za raka je rak # BAZA server = model.Server() # VLC PREDVAJALNIk domaci_server = False # spremeni to za vlc predvajalnik vlc = model.Predvajalnik() SKRIVNOST = "42x69eq420" # zastonj priložnost za jazjaz def id(): ''' Vrne id uporabnikove seje, ali pa ustvari novo sejo in vrnje njen id. Parameters ---------- None Returns ------- ans : int Id seje trenuntnega uporabnika. ''' try: ans = int(bottle.request.get_cookie('id_seje', secret=SKRIVNOST))
def test_override_value(self): configure_main() server = model.Server(override={'server_addr': '192.168.0.1'}) self.assertEqual(server.addr, '192.168.0.1')
def test_override_fail(self): configure_main() with self.assertRaises(ValueError): server = model.Server(override={'server_addr', '192.168.0.1'})