Exemplo n.º 1
0
 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')
Exemplo n.º 2
0
 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')
Exemplo n.º 3
0
 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')
Exemplo n.º 4
0
 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')
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 def test_parse_json_exception(self):
     with self.assertRaises(NetParserJsonException):
         BaseParser('wrong [] ; .')
Exemplo n.º 7
0
 def test_parse_dict(self):
     p = BaseParser({})
     self.assertIsInstance(p.original_data, dict)
Exemplo n.º 8
0
 def test_parse_json_string(self):
     p = BaseParser('{}')
     self.assertIsInstance(p.original_data, dict)
     p = BaseParser(u'{}')
     self.assertIsInstance(p.original_data, dict)
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
 def test_parse_error(self):
     with self.assertRaises(ConversionException):
         BaseParser(data=8)
Exemplo n.º 11
0
 def test_topology_retrieval_error_file(self):
     with self.assertRaises(TopologyRetrievalError):
         BaseParser(file='./tests/static/wrong.json')
Exemplo n.º 12
0
 def test_telnet_retrieval(self, MockClass):
     with self.assertRaises(ConversionException):
         BaseParser(url='telnet://127.0.0.1')
Exemplo n.º 13
0
 def test_telnet_retrieval_error(self, MockClass):
     telnetlib.Telnet.side_effect = ValueError('testing exception')
     with self.assertRaises(TopologyRetrievalError):
         BaseParser(url='telnet://wrong.com')
Exemplo n.º 14
0
 def test_no_data_supplied(self):
     with self.assertRaises(ValueError):
         BaseParser()
Exemplo n.º 15
0
 def test_json_not_implemented(self):
     p = BaseParser(data='{}')
     with self.assertRaises(NotImplementedError):
         p.json()
Exemplo n.º 16
0
 def test_parse_exception(self):
     with self.assertRaises(NetParserException):
         BaseParser(8)
Exemplo n.º 17
0
 def test_json_not_implemented(self):
     p = BaseParser('{}')
     with self.assertRaises(NotImplementedError):
         p.json()
Exemplo n.º 18
0
 def test_parse_conversion_exception(self):
     with self.assertRaises(ConversionException):
         BaseParser(data='wrong [] ; .')