def testHost(self): # Create a host and check the etag also result = Host.create('api-test', '2.3.4.5') self.assertTrue(result.href.startswith('http')) # Get Etag host = Host('api-test') self.assertIsNotNone(host.etag) self.assertEqual(host.address, '2.3.4.5') self.assertEqual(host.data.get('address'), '2.3.4.5') host.modify_attribute(address='1.1.1.1') self.assertEqual(host.data.get('address'), '1.1.1.1') host.secondary = ['8.8.8.8', '9.9.9.9'] for ip in host.secondary: self.assertIn(ip, ['8.8.8.8', '9.9.9.9']) host.ipv6_address = '2001:0db8:85a3:0000:0000:8a2e:0370:7334' self.assertEqual(host.ipv6_address, '2001:0db8:85a3:0000:0000:8a2e:0370:7334') host.add_secondary(address=['25.25.25.25'], append_lists=True) self.assertIn('25.25.25.25', host.data.get('secondary')) with self.assertRaises(AttributeError): host.foobarattribute host.rename('renamedhost') self.assertEqual(host.data.get('name'), 'renamedhost') # Cache refreshed host.update(etag=host.etag, name='anothername') self.assertEqual(host.name, 'anothername') host.delete()
def test_modify_non_system_element(self): # Non system elements can be modified result = Host.create('api-test', '2.3.4.5') self.assertTrue(result.href.startswith('http')) host = Host('api-test') result = host.modify_attribute(name='newapi-test') self.assertTrue(result.startswith('http')) Host('newapi-test').delete()
def test_modify_system_element(self): # System elements should not be able to be modified host = Host('Localhost') with self.assertRaises(ModificationFailed): host.modify_attribute(name='myLocalhost')