Beispiel #1
0
  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')
Beispiel #2
0
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)
Beispiel #3
0
    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!')
Beispiel #4
0
  def test_unregistered_command(self):
    """
    Attempting to create an unsupported command.
    """
    api = StrictIota(MockAdapter())

    with self.assertRaises(InvalidCommand):
      # noinspection PyStatementEffect
      api.helloWorld
Beispiel #5
0
  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)
Beispiel #6
0
 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)
Beispiel #7
0
 class CustomClient(with_metaclass(ABCMeta)):
     client = StrictIota(MockAdapter())
Beispiel #8
0
 class CustomClient(object):
     client = StrictIota(MockAdapter())
Beispiel #9
0
 def test_nodeinfo(self):
     #print(__version__)
     api = StrictIota(self.uri)
     node_info = api.get_node_info()
Beispiel #10
0
 class CustomClient(object, metaclass=ABCMeta):
     client = StrictIota(MockAdapter())