Пример #1
0
def test_search_devices_with_part_imei(imei, iot_api):

    body = {'imei': imei, 'active': True}
    devices = iot_api['device'].post(json.dumps(body), url_param='search/all')

    db_count = devices_count('imei', imei)
    assert len(devices) == db_count, \
        'Fail: default number of devices returned api %s = %s db' % (len(devices), db_count)

    for dvc in devices:
        assert imei in dvc['imei'], 'Fail: imei: api %s != %s db' % (
            dvc['imei'], imei)
Пример #2
0
def test_search_devices_with_part_source_id(sid, iot_api):

    body = {'sourceId': sid, 'active': True}
    devices = iot_api['device'].post(json.dumps(body), url_param='search/all')

    db_count = devices_count('source_id', sid)
    assert (len(devices) == db_count), \
        'Fail: default number of devices returned api %s = %s db' % (len(devices), db_count)

    for dvc in devices:
        assert sid in dvc['sourceId'], 'Fail: source id: api %s != %s db' % (
            dvc['sourceId'], sid)
Пример #3
0
def test_search_devices_with_part_sn(sn, iot_api):

    body = {'serialNumber': sn, 'active': True}
    devices = iot_api['device'].post(json.dumps(body), url_param='search/all')

    db_count = devices_count('serial_number', sn)
    assert (len(devices) == db_count), \
        'Fail: id: default number of devices returned api %s = %s db' % (len(devices), db_count)

    for dvc in devices:
        assert sn in dvc['serialNumber'], 'Fail: SN: api %s != %s db' % (
            dvc['serialNumber'], sn)
Пример #4
0
def test_search_devices_with_part_imei(imei, iot_api):
    body = {'imei': imei, 'active': True}
    devices = iot_api['device'].post(json.dumps(body), url_param='search')

    db_count = devices_count('imei', imei)
    assert devices['totalElements'] == db_count, \
        'Fail: id: default number of devices returned api %s = %s db' % (devices['totalElements'], db_count)

    assert devices['size'] in range(1, 21), \
        'Fail: id: default number of devices returned api %s less or equal to 20' % devices['size']

    for dvc in devices['content']:
        assert imei in dvc['imei'], 'Fail: imei: api %s != %s db' % (dvc['imei'], imei)
Пример #5
0
def test_search_devices_with_part_source_id(sid, iot_api):

    body = {'sourceId': sid, 'active': True}
    devices = iot_api['device'].post(json.dumps(body), url_param='search')

    db_count = devices_count('source_id', sid)
    assert devices['totalElements'] == db_count, \
        'Fail: id: default number of devices returned api %s = %s db' % (devices['totalElements'], db_count)

    assert devices['size'] in range(1, 21), \
        'Fail: id: default number of devices returned api %s less or equal to 20' % devices['size']

    for dvc in devices['content']:
        assert sid in dvc['sourceId'], 'Fail: source id: api %s != %s db' % (dvc['sourceId'], sid)
Пример #6
0
def test_search_devices_vendors(iot_api):

    search_list = [row[0] for row in vendors_info()[:3]]
    db_count = devices_count('vendor_id', search_list, active_flag=0)
    body = {'vendors': search_list}
    devices = iot_api['device'].post(json.dumps(body),
                                     url_param='search/all?size=100')

    assert (len(devices) == db_count), \
        'Fail: number of devices returned api %s != %s db' % (len(devices), db_count)

    for dvc in devices:
        assert dvc['vendor'][
            'id'] in search_list, 'Fail: vendor is not found: api %s' % dvc[
                'vendor']['id']
Пример #7
0
def test_search_devices_groups(iot_api):

    search_list = [row[0] for row in groups_stat()[:5]]
    db_count = devices_count('device_group_id', search_list, active_flag=0)

    body = {'groupIds': search_list}
    devices = iot_api['device'].post(json.dumps(body),
                                     url_param='search/all?size=100')

    assert (
        len(devices) == db_count
    ), 'Fail: id: total devices found api %s !=  %s' % (len(devices), db_count)

    for dvc in devices:
        assert any(
            group in dvc['groupIds'] for group in
            search_list), 'Fail: group is not found: api %s' % dvc['groupIds']
Пример #8
0
def test_search_devices_with_location(i_lon, i_lat, iot_api):
    k = 0.5
    polygon = [[i_lon, i_lat], [i_lon + k, i_lat], [i_lon + k, i_lat + k],
               [i_lon, i_lat + k], [i_lon, i_lat]]
    body = {"location": {"type": "Polygon", "coordinates": [polygon]}}
    devices = iot_api['device'].post(json.dumps(body), url_param='search/all')

    p_shape = Polygon(polygon)

    db_count = devices_count(None, p_shape, active_flag=0)

    assert (len(devices) == db_count), \
        'Fail: id: default number of devices returned api %s = %s db' % (len(devices), db_count)

    for dvc in devices:
        p = Point(dvc['coordinates']['coordinates'])
        assert p.within(
            p_shape), 'Fail: device %s: lon, lat %s not within %s' % (
                dvc['id'], p, p_shape)