def test_create_command(self): """ Preparing an experimental/undocumented command. """ api = StrictIota(MockAdapter()) custom_command = api.create_command('helloWorld') self.assertIsInstance(custom_command, CustomCommand) self.assertEqual(custom_command.command, 'helloWorld')
def main(uri): # type: (Text) -> None api = StrictIota(uri) try: node_info = api.get_node_info() except NetworkError as e: print("Hm. {uri} isn't responding; is the node running?".format( uri=uri)) print(e) except BadApiResponse as e: print("Looks like {uri} isn't very talkative today ):".format(uri=uri)) print(e) else: print('Hello {uri}!'.format(uri=uri)) pprint(node_info)
def test_wireup(self): """ Verify that the command is wired up correctly. The API method indeed calls the appropiate command. """ with patch( 'iota.commands.core.add_neighbors.AddNeighborsCommand.__call__', MagicMock(return_value='You found me!')) as mocked_command: api = StrictIota(self.adapter) response = api.add_neighbors('test_uri') self.assertTrue(mocked_command.called) self.assertEqual(response, 'You found me!')
def test_unregistered_command(self): """ Attempting to create an unsupported command. """ api = StrictIota(MockAdapter()) with self.assertRaises(InvalidCommand): # noinspection PyStatementEffect api.helloWorld
def test_registered_command(self): """ Preparing a documented command. """ api = StrictIota(MockAdapter()) # We just need to make sure the correct command type is # instantiated; individual commands have their own unit tests. command = api.getNodeInfo self.assertIsInstance(command, GetNodeInfoCommand)
def test_init_with_uri(self): """ Passing a URI to the initializer instead of an adapter instance. """ api = StrictIota('mock://') self.assertIsInstance(api.adapter, MockAdapter)
class CustomClient(with_metaclass(ABCMeta)): client = StrictIota(MockAdapter())
class CustomClient(object): client = StrictIota(MockAdapter())
def test_nodeinfo(self): #print(__version__) api = StrictIota(self.uri) node_info = api.get_node_info()
class CustomClient(object, metaclass=ABCMeta): client = StrictIota(MockAdapter())