# Path: vespa/controller.py
# class Controller(object):
#     def __init__(self, model, view, testmode=False):
#         self.model = model
#         self.view = view
#         self.testmode = testmode
# 
#     def handler(self, signum, false):
#         if signum == 2:
#             debug_init("Controller received shutting down")
#             self._shutdown()
# 
#     def _shutdown(self):
#         self.model.destroy()
# 
#         if not self.testmode:
#             exit(0)
# 
#         self.server.stop()
# 
#     def start(self):
#         debug5("Started Controller")
# 
#         if not self.testmode:
#             signal.signal(signal.SIGINT, self.handler)
# 
#         self.server = HttpServer("test server", "0.0.0.0", 8080,
#                                  server_handler, self)
#         self.server.start()


import pytest
import sys
import os
import socket
import SocketServer
import threading
import time
import requests
from vespa.controller import Controller
        return fstr

    def destroy(self):
        pass

@pytest.fixture(scope='module')
def controller_instance():
    s = Controller(Model_light(), None, testmode=True)
    t = threading.Thread(target=s.start)
    t.start()
    time.sleep(0.1)
    return s

@pytest.fixture(scope='function')
def get_socket(request):
    s = socket.socket()
    s.connect(("127.0.0.1", 8080))
    def fin():
        s.close()
    request.addfinalizer(fin)
    return s

def test_controller_server_handler(controller_instance):
    r = requests.get("http://%s:%s/archi" % (HOST,PORT))
    assert r.content == \
           '{"host": "vo_host", "children": [{"host": "vo_host", "children":'\
           ' [{"host": "vo_host", "children": [], '\
           '"name": "voname", "port": 1234}], '\
           '"name": "voname", "port": 1234}], "name": "voname", "port": 1234}'


# Path: vespa/controller.py
# class Controller(object):
#     def __init__(self, model, view, testmode=False):
#         self.model = model
#         self.view = view
#         self.testmode = testmode
# 
#     def handler(self, signum, false):
#         if signum == 2:
#             debug_init("Controller received shutting down")
#             self._shutdown()
# 
#     def _shutdown(self):
#         self.model.destroy()
# 
#         if not self.testmode:
#             exit(0)
# 
#         self.server.stop()
# 
#     def start(self):
#         debug5("Started Controller")
# 
#         if not self.testmode:
#             signal.signal(signal.SIGINT, self.handler)
# 
#         self.server = HttpServer("test server", "0.0.0.0", 8080,
#                                  server_handler, self)
#         self.server.start()


# Path: tests/test_controller.py
import pytest
import sys
import os
import socket
import SocketServer
import threading
import time
import requests
from vespa.controller import Controller

        return fstr

    def destroy(self):
        pass

@pytest.fixture(scope='module')
def controller_instance():
    s = Controller(Model_light(), None, testmode=True)
    t = threading.Thread(target=s.start)
    t.start()
    time.sleep(0.1)
    return s

@pytest.fixture(scope='function')
def get_socket(request):
    s = socket.socket()
    s.connect(("127.0.0.1", 8080))
    def fin():
        s.close()
    request.addfinalizer(fin)
    return s

def test_controller_server_handler(controller_instance):
    r = requests.get("http://%s:%s/archi" % (HOST,PORT))
    assert r.content == \
           '{"host": "vo_host", "children": [{"host": "vo_host", "children":'\
           ' [{"host": "vo_host", "children": [], '\
           '"name": "voname", "port": 1234}], '\
           '"name": "voname", "port": 1234}], "name": "voname", "port": 1234}'


def test_controller_default_handler(controller_instance):