def test_recursive(self): Options = collections.namedtuple('args', 'recursive command_args') options = Options(recursive=True, command_args=['/some_path']) command = Cat() command.prepare(options) client = mock.Mock() token = Token(version=10, name='/some_path/some_token', owner='some_owner', expirationTime=10, data='some_data') query_response = QueryResponse(tokens=[[token]]) client.query.return_value = query_response output = command.execute(client, None) query = Query(namePrefix='/some_path') query_request = QueryRequest(queries=[query]) client.query.assert_called_once_with(query_request) self.assertEqual('total 1\nToken(version=10, owner=some_owner, ' 'expirationTime=1970-01-01 00:00:10 UTC, ' 'priority=0.000000, name=/some_path/some_token, ' 'data=some_data)\n', output)
def test_empty(self): Options = collections.namedtuple('args', 'recursive command_args') options = Options(recursive=False, command_args=['/some_path']) command = Cat() command.prepare(options) client = mock.Mock() response = QueryResponse() client.query.return_value = response output = command.execute(client, None) query = Query(namePrefix='/some_path') request = QueryRequest(queries=[query]) client.query.assert_called_once_with(request) self.assertEqual('total 0\n', output)
def test_recursive(self): Options = collections.namedtuple("args", "recursive command_args") options = Options(recursive=True, command_args=["/some_path"]) command = Cat() command.prepare(options) client = mock.Mock() token = Token(version=10, name="/some_path/some_token", owner="some_owner", expirationTime=10, data="some_data") query_response = QueryResponse(tokens=[[token]]) client.query.return_value = query_response output = command.execute(client, None) query = Query(namePrefix="/some_path") query_request = QueryRequest(queries=[query]) client.query.assert_called_once_with(query_request) self.assertEqual( "total 1\nToken(version=10, owner=some_owner, " "expirationTime=1970-01-01 00:00:10 UTC, " "priority=0.000000, name=/some_path/some_token, " "data=some_data)\n", output, )