def test_synchronize_device(provd, device): timestamp = datetime.utcnow() response = confd.devices(device['id']).synchronize.get() response.assert_ok() synchonized = provd.has_synchronized(device['id'], timestamp) assert_that(synchonized, "Device was not synchronized")
def test_get(device): response = confd.devices(device['id']).get() assert_that( response.item, has_entries(ip=device['ip'], mac=device['mac'], template_id="mockdevicetemplate", plugin='zero', vendor='myvendor', version='1.0', description='getdevice', options={'switchboard': True}))
def test_edit_device_null_parameters(device): url = confd.devices(device['id']) response = url.put(mac=None, template_id=None, plugin=None, vendor=None, version=None, description=None, options=None) response.assert_updated() response = confd.devices(device['id']).get() assert_that( response.item, has_entries(mac=none(), template_id=none(), status='not_configured', plugin=none(), vendor=none(), version=none(), description=none(), options=none()))
def test_edit_device_all_parameters(device): mac, ip = h.device.generate_mac_and_ip() parameters = { 'ip': ip, 'mac': mac, 'model': '6731i', 'plugin': 'null', 'sn': 'sn', 'template_id': 'mockdevicetemplate', 'vendor': 'Aastra', 'version': '1.0', 'description': 'mydevice', 'options': { 'switchboard': True } } response = confd.devices(device['id']).put(**parameters) response.assert_updated() response = confd.devices(device['id']).get() assert_that(response.item, has_entries(parameters))
def test_reset_to_autoprov_device_associated_to_line(provd, device, line): with a.line_device(line, device, check=False): response = confd.devices(device['id']).autoprov.get() response.assert_ok() response = confd.lines(line['id']).get() assert_that(response.item, has_entry('device_id', none())) device_cfg = provd.devices.get(device['id']) assert_that(device_cfg, has_entries(config=starts_with('autoprov'))) assert_that(device_cfg, is_not(has_key('options'))) config_cfg = provd.configs.get(device_cfg['config']) assert_that(config_cfg, not_none()) response = confd.lines(line['id']).get() assert_that(response.item, has_entries(device_id=none()))
def generate_autoprov(): mac, ip = generate_mac_and_ip() autoprov_id = 'autoprov{}'.format(randint(100000000, 9999999999)) sip_username = "".join(choice(string.ascii_letters) for _ in range(20)) random_id = hashlib.md5(str(random())).hexdigest() device = { 'added': u'auto', 'config': autoprov_id, 'configured': True, 'id': random_id, 'ip': ip, 'mac': mac, 'model': u'6731i', 'plugin': u'xivo-aastra-3.3.1-SP4', 'remote_state_sip_username': sip_username, 'vendor': u'Aastra', 'version': u'3.3.1.4322' } config = { 'id': autoprov_id, 'transient': True, 'parent_ids': ['autoprov'], 'raw_config': { 'sip_lines': { '1': { 'username': sip_username } } } } provd.devices.add(device) provd.configs.add(config) return confd.devices(random_id).get().item
def test_put_errors(device): url = confd.devices(device['id']).put for check in error_checks(url): yield check
def test_get_errors(): fake_get = confd.devices(999999).get yield s.check_resource_not_found, fake_get, 'Device'
def test_delete_device(device): response = confd.devices(device['id']).delete() response.assert_deleted() provd_devices = provd.devices.find({'id': device['id']}) assert_that(provd_devices, empty())
def test_edit_device_with_fake_template(device): response = confd.devices( device['id']).put(template_id='superdupertemplate') response.assert_match(400, e.not_found('DeviceTemplate'))
def test_edit_device_with_fake_plugin(device): response = confd.devices(device['id']).put(plugin='superduperplugin') response.assert_match(400, e.not_found('Plugin'))
def test_edit_device_with_same_mac(first_device, second_device): response = confd.devices(first_device['id']).put(mac=second_device['mac']) response.assert_match(400, e.resource_exists('Device'))
def delete_device(device_id, check=False): response = confd.devices(device_id).delete() if check: response.assert_ok()
def test_dissociate_line_to_a_device(device, line): response = confd.devices(device['id']).remove_line(line['id']).get() response.assert_status(403)
def test_edit_device_with_fake_template(device): response = confd.devices(device['id']).put(template_id='superdupertemplate') response.assert_match(400, e.not_found('DeviceTemplate'))