Ejemplo n.º 1
0
 def test_json_dict(self):
     p = NetJsonParser(links2)
     data = p.json(dict=True)
     self.assertIsInstance(data, dict)
     self.assertEqual(data['type'], 'NetworkGraph')
     self.assertEqual(data['protocol'], 'OLSR')
     self.assertEqual(data['version'], '0.6.6')
     self.assertEqual(data['revision'], '5031a799fcbe17f61d57e387bc3806de')
     self.assertEqual(data['metric'], 'ETX')
     self.assertIsInstance(data['nodes'], list)
     self.assertIsInstance(data['links'], list)
     self.assertEqual(len(data['nodes']), 3)
     self.assertEqual(len(data['links']), 2)
     # ensure additional node properties are present
     self.assertIn('properties', data['nodes'][0])
     self.assertIn('hostname', data['nodes'][0]['properties'])
     # ensure local_addresses is present
     self.assertIn('local_addresses', data['nodes'][0])
     # ensure additional link properties are present
     self.assertIn('properties', data['links'][0])
     self.assertIn('custom_property', data['links'][0]['properties'])
     # check presence of labels, we need to find 2
     labels = []
     for node in data['nodes']:
         if 'label' in node:
             labels.append(node['label'])
     self.assertEqual(len(labels), 2)
     self.assertIn('nodeA', labels)
     self.assertIn('nodeB', labels)
Ejemplo n.º 2
0
 def test_json_dict(self):
     p = NetJsonParser(links2)
     data = p.json(dict=True)
     self.assertIsInstance(data, dict)
     self.assertEqual(data['type'], 'NetworkGraph')
     self.assertEqual(data['protocol'], 'OLSR')
     self.assertEqual(data['version'], '0.6.6')
     self.assertEqual(data['revision'], '5031a799fcbe17f61d57e387bc3806de')
     self.assertEqual(data['metric'], 'ETX')
     self.assertIsInstance(data['nodes'], list)
     self.assertIsInstance(data['links'], list)
     self.assertEqual(len(data['nodes']), 3)
     self.assertEqual(len(data['links']), 2)
Ejemplo n.º 3
0
 def test_json_string(self):
     p = NetJsonParser(links2)
     data = p.json()
     self.assertIsInstance(data, six.string_types)
     self.assertIn('NetworkGraph', data)
     self.assertIn('protocol', data)
     self.assertIn('version', data)
     self.assertIn('revision', data)
     self.assertIn('metric', data)
     self.assertIn('OLSR', data)
     self.assertIn('0.6.6', data)
     self.assertIn('5031a799fcbe17f61d57e387bc3806de', data)
     self.assertIn('ETX', data)
     self.assertIn('links', data)
     self.assertIn('nodes', data)
Ejemplo n.º 4
0
 def test_json_dict(self):
     p = NetJsonParser(links2)
     data = p.json(dict=True)
     self.assertIsInstance(data, dict)
     self.assertEqual(data['type'], 'NetworkGraph')
     self.assertEqual(data['protocol'], 'OLSR')
     self.assertEqual(data['version'], '0.6.6')
     self.assertEqual(data['revision'], '5031a799fcbe17f61d57e387bc3806de')
     self.assertEqual(data['metric'], 'ETX')
     self.assertIsInstance(data['nodes'], list)
     self.assertIsInstance(data['links'], list)
     self.assertEqual(len(data['nodes']), 3)
     self.assertEqual(len(data['links']), 2)
     # ensure additional node properties are present
     self.assertIn('properties', data['nodes'][0])
     self.assertIn('hostname', data['nodes'][0]['properties'])
     # ensure local_addresses is present
     self.assertIn('local_addresses', data['nodes'][0])
     # ensure additional link properties are present
     self.assertIn('properties', data['links'][0])
     self.assertIn('custom_property', data['links'][0]['properties'])
Ejemplo n.º 5
0
 def test_parse_exception(self):
     with self.assertRaises(ParserError):
         NetJsonParser('{ "test": "test" }')
Ejemplo n.º 6
0
 def diff(self):
     """ shortcut to netdiff.diff """
     latest = self.latest
     current = NetJsonParser(self.json())
     return diff(current, latest)