summaryrefslogtreecommitdiff
path: root/tests/test_discovery.py
blob: 96d262efaba5be6035e3b1ea5dcccd8f49bd9716 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
import unittest
import pprint

from context import haircontrol
from haircontrol import discovery, data

class MockInspector(object):
    def __init__(self, testDataPath):
        self.testDataPath = testDataPath

    def connect(self, e):
        self.name = e.name

    def disconnect(self):
        self.name = None

    def command(self, command):
        if not self.name:
            return None
        mockfile = self.testDataPath + '/' + self.name + '-' + command + '.out'
        return open(mockfile)


class TestDiscovery(unittest.TestCase):
    
    # http://stackoverflow.com/questions/3768895/how-to-make-a-class-json-serializable
    def setUp(self):
        self.discovery = discovery.Discovery(MockInspector('../test-data/input'))
        self.maxDiff=None
        self.ref_equipments = [] #json.load('../test-data/ref-output/equipments.json')

    def test_wire_graph(self):
        self.discovery.discover_hinting_from_lldp(data.Equipment('stg2'))
        self.discovery.discover_from_root(data.Equipment('stg'))
        for e in self.discovery.equipments:
            print(e)
            for i in e.ifaces:
                print(i)
        self.assertEqual(self.discovery.equipments, self.ref_equipments)

if __name__ == '__main__':
    unittest.main()