def test_moving_devices_1(self, management_client, inventory_attributes): """ Create 2 devices and move them amoung 2 different groups """ d1 = management_client.createDevice(attributes=inventory_attributes) d2 = management_client.createDevice(attributes=inventory_attributes) group = management_client.group(group="group-test-1") management_client.addDeviceToGroup(group=group, device=d1) management_client.addDeviceToGroup(group=group, device=d2) assert len(management_client.getGroupDevices("group-test-1")) == 2 group = management_client.group(group="group-test-2") management_client.addDeviceToGroup(group=group, device=d2) assert len(management_client.getGroupDevices("group-test-1")) == 1 assert len(management_client.getGroupDevices("group-test-2")) == 1 management_client.addDeviceToGroup(group=group, device=d1) assert len(management_client.getGroupDevices("group-test-1", expected_error=True)) == 0 assert len(management_client.getGroupDevices("group-test-2")) == 2 group = management_client.group(group="group-test-1") management_client.addDeviceToGroup(group=group, device=d1) management_client.addDeviceToGroup(group=group, device=d2) assert len(management_client.getGroupDevices("group-test-1")) == 2 assert len(management_client.getGroupDevices("group-test-2", expected_error=True)) == 0
def test_inventory_searching(self, management_client, inventory_attributes): extra_inventory_items = { "users_logged_in": 100, "open_connections": 1231, "open_ports": 523, } for i in extra_inventory_items.keys(): it = list(inventory_attributes) it.append( management_client.inventoryAttribute( name=i, value=extra_inventory_items[i])) management_client.createDevice(attributes=it) r = requests.get(management_client.client.swagger_spec.api_url + "/devices", params=({ "users_logged_in": 100 }), verify=False) assert len(r.json()) == 1 r = requests.get(management_client.client.swagger_spec.api_url + "/devices", params=({ "open_connections": 1231 }), verify=False) assert len(r.json()) == 1
def test_inventory_sorting(self, management_client, inventory_attributes): numbers = [100, 1000, 1, 999] for n in range(20): management_client.createDevice(attributes=inventory_attributes) for n in numbers: it = list(inventory_attributes) it.append(management_client.inventoryAttribute(name="number", value=n)) management_client.createDevice(attributes=it) t = [] r = management_client.getAllDevices(sort="number:asc") for deviceInventoryList in r: for i in deviceInventoryList.attributes: if i.name == "number": t.append(i.value) assert sorted(numbers) == t t = [] r, h = management_client.client.devices.get_devices(sort="number:desc", Authorization="foo").result() for deviceInventoryList in r: for i in deviceInventoryList.attributes: if i.name == "number": t.append(i.value) assert sorted(numbers, reverse=True) == t
def test_delete_device_non_existent_2(self, management_client, inventory_attributes): """ Delete existent device from non-existent group """ d1 = management_client.createDevice(attributes=inventory_attributes) management_client.deleteDeviceInGroup(device=d1, group="404 group", expected_error=True)
def test_get_groups(self, management_client, inventory_attributes): for i in range(10): group = management_client.group(group="group" + str(i)) did = management_client.createDevice(inventory_attributes) management_client.client.devices.put_devices_id_group(group=group, Authorization="foo", id=did).result() assert len(management_client.client.groups.get_groups().result()[0]) == 10
def test_delete_device(self, management_client, inventory_attributes): d1 = management_client.createDevice(attributes=inventory_attributes) g1 = "group-test-3" management_client.addDeviceToGroup( device=d1, group=management_client.group(group=g1)) assert len(management_client.getGroupDevices(g1)) == 1 management_client.deleteDeviceInGroup(device=d1, group=g1, expected_error=False) assert len(management_client.getGroupDevices(g1, expected_error=True)) == 0
def test_get_groups_3(self, management_client, inventory_attributes): """ Create 1 device, and move through 100 different groups """ device = management_client.createDevice(attributes=inventory_attributes) for i in range(10): group = management_client.group(group="group" + str(i)) management_client.client.devices.put_devices_id_group(group=group, id=device, Authorization="foo").result() assert len(management_client.client.groups.get_groups().result()[0]) == 1
def test_has_group(self, management_client, inventory_attributes): """ Verify has_group functionality """ did = management_client.createDevice(attributes=inventory_attributes) assert len(management_client.getAllGroups()) == 0 assert len(management_client.getAllDevices(has_group=True)) == 0 group = management_client.group(group="has_group_test_1") management_client.addDeviceToGroup(group=group, device=did) assert len(management_client.getAllDevices(has_group=True)) == 1 management_client.deleteDeviceInGroup(group="has_group_test_1", device=did) assert len(management_client.getAllDevices(has_group=True)) == 0
def test_moving_device_group_1(self, management_client, inventory_attributes): """ Create 1 device and move it amung 2 different groups """ did = management_client.createDevice(attributes=inventory_attributes) group = management_client.group(group="groupA") management_client.client.devices.put_devices_id_group(group=group, id=did, Authorization="foo").result() group_a_devs = management_client.getGroupDevices("groupA") print(group_a_devs) assert len(group_a_devs) == 1 group = management_client.group(group="groupB") management_client.client.devices.put_devices_id_group(group=group, id=did, Authorization="foo").result() assert len(management_client.getGroupDevices("groupA", expected_error=True)) == 0 assert len(management_client.getGroupDevices("groupB")) == 1
def test_generic_groups_1(self, management_client, inventory_attributes): total_groups = 10 items_per_group = 2 devices_in_groups = {} for i in range(total_groups): group = management_client.group(group="group" + str(i)) for j in range(items_per_group): device = management_client.createDevice(attributes=inventory_attributes) devices_in_groups.setdefault(str(i), []).append(device) management_client.client.devices.put_devices_id_group(group=group, id=device, Authorization="foo").result() assert len(management_client.getAllGroups()) == 10 groups = management_client.getAllGroups() for idx, g in enumerate(groups): assert sorted(management_client.getGroupDevices(g)) == sorted(devices_in_groups[str(idx)])