def test_boolean_resource_get(self):
     communicator = mock.Mock()
     response = base.AsynchronousResponse([{'boolean': b'yes'}], command='')
     communicator.call.return_value.get.return_value = response
     some_resource = resource.RouterOsResource(communicator, '/boolean',
                                               BOOLEAN_STRUCTURE)
     result = some_resource.get()
     self.assertEqual(result, [{'boolean': True}])
 def test_bytes_resource_get(self):
     communicator = mock.Mock()
     response = base.AsynchronousResponse([{'bytes': b'y'}], command='')
     communicator.call.return_value.get.return_value = response
     some_resource = resource.RouterOsResource(communicator, '/bytes',
                                               BYTES_STRUCTURE)
     result = some_resource.get()
     self.assertEqual(result, [{'bytes': b'y'}])
 def test_unknown_resource_get(self):
     communicator = mock.Mock()
     response = base.AsynchronousResponse([{'x': b'y'}], command='')
     communicator.call.return_value.get.return_value = response
     some_resource = resource.RouterOsResource(communicator, '/unknown',
                                               structure.default_structure)
     result = some_resource.get()
     self.assertEqual(result, [{'x': 'y'}])
 def test_boolean_resource_set(self):
     communicator = mock.Mock()
     some_resource = resource.RouterOsResource(communicator, '/boolean',
                                               BOOLEAN_STRUCTURE)
     some_resource.set(boolean=True)
     communicator.call.assert_called_with('/boolean/',
                                          'set',
                                          arguments={'boolean': b'yes'},
                                          queries={},
                                          additional_queries=())
 def test_bytes_resource_set(self):
     communicator = mock.Mock()
     some_resource = resource.RouterOsResource(communicator, '/bytes',
                                               BYTES_STRUCTURE)
     some_resource.set(bytes=b'y')
     communicator.call.assert_called_with('/bytes/',
                                          'set',
                                          arguments={'bytes': b'y'},
                                          queries={},
                                          additional_queries=())
 def test_unknown_resource_set(self):
     communicator = mock.Mock()
     some_resource = resource.RouterOsResource(communicator, '/unknown',
                                               structure.default_structure)
     some_resource.set(x='y')
     communicator.call.assert_called_with('/unknown/',
                                          'set',
                                          arguments={'x': b'y'},
                                          queries={},
                                          additional_queries=())
Пример #7
0
 def get_resource(self, path, structure=None):
     structure = structure or api_structure.default_structure
     return resource.RouterOsResource(self.communicator, path, structure)