Пример #1
0
def check_url ( url, code):
    r = s.get("{0}/{1}".format(get_rest_url(True), url), allow_redirects=False)
    if r.status_code == code:
        print("URL {0} get the expected code {1}".format(url, code))
    else:
        print("URL {0} get an unexpected code exp:{1} got:{2}".format(url, code, r.status_code))
        assert RuntimeError("URL {0} got an unexpected status code exp:{1} got:{2}".format(url, code, r.status_code))
Пример #2
0
def client_devices_known(client_id):
    detail = get_client_detail(client_id)

    if app.datatypes == {}:
        cli = MQSyncReq(app.zmq_context)
        msg = MQMessage()
        msg.set_action('datatype.get')
        res = cli.request('manager', msg.get(), timeout=10)
        if res is not None:
            app.datatypes = res.get_data()['datatypes']
        else:
            app.datatypes = {}

    # todo : grab from MQ ?
    with app.db.session_scope():
        devices = app.db.list_devices_by_plugin(client_id)

    # sort clients per device type
    devices_by_device_type_id = {}
    for dev in devices:
        if devices_by_device_type_id.has_key(dev['device_type_id']):
            devices_by_device_type_id[dev['device_type_id']].append(dev)
        else:
            devices_by_device_type_id[dev['device_type_id']] = [dev]

    return render_template('client_devices.html',
            datatypes = app.datatypes,
            devices = devices,
            devices_by_device_type_id = devices_by_device_type_id,
            clientid = client_id,
            mactive="clients",
            active = 'devices',
            rest_url = get_rest_url(),
            client_detail = detail
            )
Пример #3
0
    def __init__(self):
        """ Construtor
            @param rest_url : url of the rest server
        """
        # rest url
        self.rest_url = get_rest_url()

        # package informations
        self.client_id = None

        # device informations
        self.device_name = None
        self.device_type = None
Пример #4
0
    def __init__(self):
        """ Construtor
            @param rest_url : url of the rest server
        """
        # rest url
        self.rest_url = get_rest_url()

        # package informations
        self.client_id = None

        # device informations
        self.device_name = None
        self.device_type = None
Пример #5
0
    def __init__(self, device_id, command_reference):
        """ Construtor
            @param rest_url : url of the rest server
            @param command_reference : command reference
        """
        # rest url
        self.rest_url = get_rest_url()

        # package informations
        self.device_id = device_id
        self.command_reference = command_reference
        try:
            self.command_id = self.get_command_id()
        except:
            self.command_id = None
Пример #6
0
    def __init__(self, device_id, sensor_reference):
        """ Construtor
            @param rest_url : url of the rest server
            @param sensor_reference : sensor reference
        """
        # rest url
        self.rest_url = get_rest_url()

        # package informations
        self.device_id = device_id
        self.sensor_reference = sensor_reference
        try:
            self.sensor_id = self.get_sensor_id()
        except:
            self.sensor_id = None
Пример #7
0
    def __init__(self, device_id, command_reference):
        """ Construtor
            @param rest_url : url of the rest server
            @param command_reference : command reference
        """
        # rest url
        self.rest_url = get_rest_url()

        # package informations
        self.device_id = device_id
        self.command_reference = command_reference
        try:
            self.command_id, self.command_keys = self.get_command_id()
        except:
            self.command_id = None
            self.command_keys = None
Пример #8
0
def client_devices_known(client_id):
    detail = get_client_detail(client_id)

    if app.datatypes == {}:
        cli = MQSyncReq(app.zmq_context)
        msg = MQMessage()
        msg.set_action('datatype.get')
        res = cli.request('manager', msg.get(), timeout=10)
        if res is not None:
            app.datatypes = res.get_data()['datatypes']
        else:
            app.datatypes = {}

    # todo : grab from MQ ?
    with app.db.session_scope():
        try:
            devices = app.db.list_devices_by_plugin(client_id)
            error = None
        except:
            error = "Error while retrieving the devices list. Error is : {0}".format(
                traceback.format_exc())
            devices = []

    # sort clients per device type
    devices_by_device_type_id = {}
    for dev in devices:
        if dev['device_type_id'] in devices_by_device_type_id:
            devices_by_device_type_id[dev['device_type_id']].append(dev)
        else:
            devices_by_device_type_id[dev['device_type_id']] = [dev]

    return render_template('client_devices.html',
                           datatypes=app.datatypes,
                           devices=devices,
                           devices_by_device_type_id=devices_by_device_type_id,
                           clientid=client_id,
                           mactive="clients",
                           active='devices',
                           rest_url=get_rest_url(),
                           client_detail=detail,
                           error=error)
Пример #9
0
def client_devices_known(client_id):
    detail = get_client_detail(client_id)

    if app.datatypes == {}:
        cli = MQSyncReq(app.zmq_context)
        msg = MQMessage()
        msg.set_action('datatype.get')
        res = cli.request('manager', msg.get(), timeout=10)
        if res is not None:
            app.datatypes = res.get_data()['datatypes']
        else:
            app.datatypes = {}

    # todo : grab from MQ ?
    with app.db.session_scope():
        try:
            devices = app.db.list_devices_by_plugin(client_id)
            error = None
        except:
            error = "Error while retrieving the devices list. Error is : {0}".format(traceback.format_exc())
            devices = []

    # sort clients per device type
    devices_by_device_type_id = {}
    for dev in devices:
        if dev['device_type_id'] in devices_by_device_type_id:
            devices_by_device_type_id[dev['device_type_id']].append(dev)
        else:
            devices_by_device_type_id[dev['device_type_id']] = [dev]

    return render_template('client_devices.html',
            datatypes = app.datatypes,
            devices = devices,
            devices_by_device_type_id = devices_by_device_type_id,
            clientid = client_id,
            mactive="clients",
            active = 'devices',
            rest_url = get_rest_url(),
            client_detail = detail,
            error = error)
Пример #10
0
check_url( '/timeline/', 302)
check_url( '/battery/', 302)
check_url( '/orphans', 302)
check_url( '/users', 302)
print("")

print("Cheking rest URLS")
check_url('/rest/', 200)
check_url('/rest/map', 200)
check_url('/rest/device/', 200)
check_url('/rest/datatype', 200)
check_url('/rest/sensor/', 200)
print("")

print("Log in")
r = s.post("{0}/login".format(get_rest_url(True)), data={"user" : "admin", "passwd" : "123"})
print("")

print("Checking URLS that need authentication")
check_url( '/', 200)
check_url( '/clients', 200)
check_url( '/scenario', 200)
check_url( '/scenario/edit/0', 200)
check_url( '/timeline/', 200)
check_url( '/battery/', 200)
check_url( '/orphans', 200)
check_url( '/users', 200)
print("")

print("Cheking client specifick URLS with authentication")
check_url( cid, 200)