def test_parse_file(self): dir = os.path.dirname(os.path.realpath(__file__)) path = '{0}/../static/olsr-2-links.json'.format(dir) p = BaseParser(path) self.assertIsInstance(p.original_data, dict) with self.assertRaises(NetParserJsonException): BaseParser('../wrong.json')
def test_parse_file(self): dir = os.path.dirname(os.path.realpath(__file__)) path = '{0}/static/olsr-2-links.json'.format(dir) p = BaseParser(file=path) self.assertIsInstance(p.original_data, dict) with self.assertRaises(TopologyRetrievalError): BaseParser(file='../wrong.json')
def test_topology_retrieval_error_http_404(self): responses.add(responses.GET, 'http://404.com', body='not found', status=404) with self.assertRaises(TopologyRetrievalError): BaseParser(url='http://404.com')
def test_topology_retrieval_error_http(self): def request_callback(request): raise ConnectionError('test exception') responses.add_callback(responses.GET, 'http://connectionerror.com', callback=request_callback) with self.assertRaises(TopologyRetrievalError): BaseParser(url='http://connectionerror.com')
def test_parse_http(self): responses.add( responses.GET, 'http://localhost:9090', body=self._load_contents('tests/static/olsr-2-links.json')) p = BaseParser(url='http://localhost:9090') self.assertIsInstance(p.original_data, dict)
def test_parse_json_exception(self): with self.assertRaises(NetParserJsonException): BaseParser('wrong [] ; .')
def test_parse_dict(self): p = BaseParser({}) self.assertIsInstance(p.original_data, dict)
def test_parse_json_string(self): p = BaseParser('{}') self.assertIsInstance(p.original_data, dict) p = BaseParser(u'{}') self.assertIsInstance(p.original_data, dict)
def test_parse_http(self): url = 'http://raw.githubusercontent.com/ninuxorg/netdiff/e7b677fca3f16a4365e1fd5a6a81e1039abedce5/tests/olsr1/2links.json' p = BaseParser(url) self.assertIsInstance(p.original_data, dict)
def test_parse_error(self): with self.assertRaises(ConversionException): BaseParser(data=8)
def test_topology_retrieval_error_file(self): with self.assertRaises(TopologyRetrievalError): BaseParser(file='./tests/static/wrong.json')
def test_telnet_retrieval(self, MockClass): with self.assertRaises(ConversionException): BaseParser(url='telnet://127.0.0.1')
def test_telnet_retrieval_error(self, MockClass): telnetlib.Telnet.side_effect = ValueError('testing exception') with self.assertRaises(TopologyRetrievalError): BaseParser(url='telnet://wrong.com')
def test_no_data_supplied(self): with self.assertRaises(ValueError): BaseParser()
def test_json_not_implemented(self): p = BaseParser(data='{}') with self.assertRaises(NotImplementedError): p.json()
def test_parse_exception(self): with self.assertRaises(NetParserException): BaseParser(8)
def test_json_not_implemented(self): p = BaseParser('{}') with self.assertRaises(NotImplementedError): p.json()
def test_parse_conversion_exception(self): with self.assertRaises(ConversionException): BaseParser(data='wrong [] ; .')