def test_get_interface_darwin(monkeypatch): '''Check that when platform.system() returns Darwin, get_interface() should call darwin_iface()''' def mockreturn(): return 'Darwin' monkeypatch.setattr('utils.platform.system', mockreturn) x = get_interface() assert x == darwin_iface()
def test_darwin_read_routes(monkeypatch): '''Check that read_routes() is called and parsed table values''' def mockreturn(): '''Returns a route table like the one returned by Scapy's read_routes method''' data = [(0, 0, '192.168.7.1', 'en0', '192.168.7.190', 1), (2130706432, 4278190080, '0.0.0.0', 'lo0', '127.0.0.1', 1)] return data monkeypatch.setattr('utils.read_routes', mockreturn) x = darwin_iface() assert len(x) == 3 assert 7 <= len(x['gw']) <= 15 and x['gw'].count('.') == 3 assert 7 <= len(x['ifaddr']) <= 15 and x['ifaddr'].count('.') == 3 assert x['gw'] is not x['ifaddr']
def test_darwin_calls_read_routes(self, mocked_read_routes): '''Check that darwin_iface() calls read_routes() once''' darwin_iface() mocked_read_routes.assert_called_once()