Ejemplo n.º 1
0
class TestParseLine(unittest.TestCase):
    def setUp(self):
        self.server = TransactionServer(('', 0))

    def test_returns_command_and_args(self):
        res = self.server.parse_line('COMMAND,arg1,arg2')
        self.assertEqual(len(res), 2)
        self.assertEqual(len(res[1]), 2)

    def test_comma_input(self):
        command, args = self.server.parse_line('COMMAND,arg1,arg2')
        self.assertEqual(command, 'COMMAND')
        self.assertEqual(args[0], 'arg1')
        self.assertEqual(args[1], 'arg2')

    def test_space_input(self):
        command, args = self.server.parse_line('COMMAND arg1 arg2')
        self.assertEqual(command, 'COMMAND')
        self.assertEqual(args[0], 'arg1')
        self.assertEqual(args[1], 'arg2')
Ejemplo n.º 2
0
def main():
    from optparse import OptionParser

    parser = OptionParser()
    parser.add_option("-d", "--debug", dest="debug", action="store_true",
                      default=False,
                      help="Run server in debug mode (autoreload)")
    parser.add_option("-f", "--config-file", dest="config", 
                      default=config.CONFIG_FILE_PATH,
                      help="Path to configuration file", metavar="FILE")

    import logging
    logging.basicConfig(level=logging.DEBUG)
    log = logging.getLogger('tserver')

    (opt, args) = parser.parse_args()
    log.debug(opt)
    log.debug(args)

    if exists(opt.config):
        log.info('Using config file "%s"', normpath(opt.config))
        read_config_file(opt.config)

    if(opt.debug):
        log.info('Debug mode enabled')
        from sps.utils.autoreload_eventlet import autoreload
        try:
            autoreload()
        except:
            exit(0)

    try:
        log.info('Starting transaction server on port %d' % config.TRANSACTION_SERVER_PORT)
        transaction_server = TransactionServer(('0.0.0.0', config.TRANSACTION_SERVER_PORT))
        transaction_server.start()
    except KeyboardInterrupt:
        print >> sys.stderr, '\nInterrupted'
        exit(0)
    except Exception as e:
        log.error(e)
        exit(1)
Ejemplo n.º 3
0
 def setUp(self):
     self.server = TransactionServer(('', 0))
Ejemplo n.º 4
0
 def test_exception_error_newline(self):
     """ When a command throws any other Exception, there should be no
     newlines in the response. """
     self.exception = Exception('stuff')
     response = TransactionServer.handle_line('a,b')
     self.assertEqual(response.count('\n'), 0)