def setUp(self): super(CustomCommandTestCase, self).setUp() self.name = 'helloWorld' print_var_type_n_val( var001 = self.name , pointer = "#c00000001" )#c00000001 # Value: helloWorld # Type: <class 'str'> self.adapter = MockAdapter() self.command = CustomCommand(self.adapter, self.name)
def create_command(self, command): # type: (Text) -> CustomCommand """ Creates a pre-configured CustomCommand instance. This method is useful for invoking undocumented or experimental methods, or if you just want to troll your node for awhile. :param command: The name of the command to create. """ return CustomCommand(self.adapter, command)
class CustomCommandTestCase(TestCase): def setUp(self): super(CustomCommandTestCase, self).setUp() self.name = 'helloWorld' print_var_type_n_val( var001 = self.name , pointer = "#c00000001" )#c00000001 # Value: helloWorld # Type: <class 'str'> self.adapter = MockAdapter() self.command = CustomCommand(self.adapter, self.name) def test_call(self): """ Sending a custom command. """ expected_response = {'message': 'Hello, IOTA!'} self.adapter.seed_response('helloWorld', expected_response) response = self.command() print_var_type_n_val(var001 = response , pointer = "#23456543FGFD")#23456543FGFD # Value: {'message': 'Hello, IOTA!'} # Type: <class 'dict'> self.assertEqual(response, expected_response) self.assertTrue(self.command.called) self.assertListEqual( self.adapter.requests, [{'command': 'helloWorld'}], ) def test_call_with_parameters(self): """ Sending a custom command with parameters. """ expected_response = {'message': 'Hello, IOTA!'} self.adapter.seed_response('helloWorld', expected_response) response = self.command(foo='bar', baz='luhrmann') self.assertEqual(response, expected_response) self.assertTrue(self.command.called) self.assertListEqual( self.adapter.requests, [{'command': 'helloWorld', 'foo': 'bar', 'baz': 'luhrmann'}], ) def test_call_error_already_called(self): """ A command can only be called once. """ self.adapter.seed_response('helloWorld', {}) self.command() with self.assertRaises(RuntimeError): self.command(extra='params') self.assertDictEqual(self.command.request, {'command': 'helloWorld'}) def test_call_reset(self): """ Resetting a command allows it to be called more than once. """ self.adapter.seed_response('helloWorld', {'message': 'Hello, IOTA!'}) self.command() self.command.reset() self.assertFalse(self.command.called) self.assertIsNone(self.command.request) self.assertIsNone(self.command.response) expected_response = {'message': 'Welcome back!'} self.adapter.seed_response('helloWorld', expected_response) response = self.command(foo='bar') self.assertDictEqual(response, expected_response) self.assertDictEqual(self.command.response, expected_response) self.assertDictEqual( self.command.request, { 'command': 'helloWorld', 'foo': 'bar', }, )
def setUp(self): super(CustomCommandTestCase, self).setUp() self.name = 'helloWorld' self.adapter = MockAdapter() self.command = CustomCommand(self.adapter, self.name)
def setUp(self): super(CustomCommandTestCase, self).setUp() self.name = 'helloWorld' self.adapter = MockAdapter() self.command = CustomCommand(self.adapter, self.name)
class CustomCommandTestCase(TestCase): def setUp(self): super(CustomCommandTestCase, self).setUp() self.name = 'helloWorld' self.adapter = MockAdapter() self.command = CustomCommand(self.adapter, self.name) def test_call(self): """ Sending a custom command. """ expected_response = {'message': 'Hello, IOTA!'} self.adapter.seed_response('helloWorld', expected_response) response = self.command() self.assertEqual(response, expected_response) self.assertTrue(self.command.called) self.assertListEqual( self.adapter.requests, [{'command': 'helloWorld'}], ) def test_call_with_parameters(self): """ Sending a custom command with parameters. """ expected_response = {'message': 'Hello, IOTA!'} self.adapter.seed_response('helloWorld', expected_response) response = self.command(foo='bar', baz='luhrmann') self.assertEqual(response, expected_response) self.assertTrue(self.command.called) self.assertListEqual( self.adapter.requests, [{'command': 'helloWorld', 'foo': 'bar', 'baz': 'luhrmann'}], ) def test_call_error_already_called(self): """ A command can only be called once. """ self.adapter.seed_response('helloWorld', {}) self.command() with self.assertRaises(RuntimeError): self.command(extra='params') self.assertDictEqual(self.command.request, {'command': 'helloWorld'}) def test_call_reset(self): """ Resetting a command allows it to be called more than once. """ self.adapter.seed_response('helloWorld', {'message': 'Hello, IOTA!'}) self.command() self.command.reset() self.assertFalse(self.command.called) self.assertIsNone(self.command.request) self.assertIsNone(self.command.response) expected_response = {'message': 'Welcome back!'} self.adapter.seed_response('helloWorld', expected_response) response = self.command(foo='bar') self.assertDictEqual(response, expected_response) self.assertDictEqual(self.command.response, expected_response) self.assertDictEqual( self.command.request, { 'command': 'helloWorld', 'foo': 'bar', }, )
class CustomCommandTestCase(TestCase): def setUp(self): super(CustomCommandTestCase, self).setUp() self.name = 'helloWorld' self.adapter = MockAdapter() self.command = CustomCommand(self.adapter, self.name) @async_test async def test_call(self): """ Sending a custom command. """ expected_response = {'message': 'Hello, IOTA!'} self.adapter.seed_response('helloWorld', expected_response) response = await self.command() self.assertEqual(response, expected_response) self.assertTrue(self.command.called) self.assertListEqual( self.adapter.requests, [{ 'command': 'helloWorld' }], ) @async_test async def test_call_with_parameters(self): """ Sending a custom command with parameters. """ expected_response = {'message': 'Hello, IOTA!'} self.adapter.seed_response('helloWorld', expected_response) response = await self.command(foo='bar', baz='luhrmann') self.assertEqual(response, expected_response) self.assertTrue(self.command.called) self.assertListEqual( self.adapter.requests, [{ 'command': 'helloWorld', 'foo': 'bar', 'baz': 'luhrmann' }], ) @async_test async def test_call_error_already_called(self): """ A command can only be called once. """ self.adapter.seed_response('helloWorld', {}) await self.command() with self.assertRaises(RuntimeError): await self.command(extra='params') self.assertDictEqual(self.command.request, {'command': 'helloWorld'}) @async_test async def test_call_reset(self): """ Resetting a command allows it to be called more than once. """ self.adapter.seed_response('helloWorld', {'message': 'Hello, IOTA!'}) await self.command() self.command.reset() self.assertFalse(self.command.called) self.assertIsNone(self.command.request) self.assertIsNone(self.command.response) expected_response = {'message': 'Welcome back!'} self.adapter.seed_response('helloWorld', expected_response) response = await self.command(foo='bar') self.assertDictEqual(response, expected_response) self.assertDictEqual(self.command.response, expected_response) self.assertDictEqual( self.command.request, { 'command': 'helloWorld', 'foo': 'bar', }, )