def test_yaml_includes_children_on_recursive_flag(self, mock_kazoo_class): foo = { 'path': '/foo', 'data': {'foo': 'bar'}, 'children': {'bar': {'foo': 'bar'}} } foobar = {'path': '/foo/bar', 'data': {'bar': 'baz'}} def side_effect(arg): arg_value_dict = {'/': foo, '/foo/bar': foobar} return arg_value_dict[arg] mock_kazoo_class.get.side_effect = side_effect fauxGflags = type('foo', (object,), {"quiet": True, "server": None, "username": None, "password": None, "outputformat": "yaml", "data": False, "recursive": True}) expected = {"/foo": {"children": [{"/foo/bar": {}}]}} get = Get(mock_kazoo_class) output = get.execute([], fauxGflags) assert output == yaml.safe_dump(expected, default_flow_style=False)
def test_dir_includes_grandchildren_on_recursive_flag(self, mock_kazoo_class): foo = { 'path': '/foo', 'data': {'foo': 'bar'}, 'children': {'bar': {'foo': 'bar'}} } foobar = { 'path': '/foo/bar', 'data': {'bar': 'baz'}, 'children': {'baz': 'foo'} } foobarbaz = {'path': '/foo/bar/baz'} def side_effect(arg): arg_value_dict = { '/': foo, '/foo/bar': foobar, '/foo/bar/baz': foobarbaz } return arg_value_dict[arg] mock_kazoo_class.get.side_effect = side_effect fauxGflags = type('foo', (object,), {"quiet": True, "server": None, "username": None, "password": None, "outputformat": "dir", "data": False, "recursive": True}) get = Get(mock_kazoo_class) output = get.execute([], fauxGflags) assert output == "/foo\n/foo/bar\n/foo/bar/baz"
def test_json_includes_children_on_recursive_flag(self, mock_kazoo_class): foo = { 'path': '/foo', 'data': {'foo': 'bar'}, 'children': {'bar': {'foo': 'bar'}} } foobar = {'path': '/foo/bar', 'data': {'bar': 'baz'}} def side_effect(arg): arg_value_dict = {'/': foo, '/foo/bar': foobar} return arg_value_dict[arg] mock_kazoo_class.get.side_effect = side_effect fauxGflags = type('foo', (object,), {"quiet": True, "server": None, "username": None, "password": None, "outputformat": "json", "data": False, "recursive": True}) expected = {"/foo": {"children": [{"/foo/bar": {}}]}} get = Get(mock_kazoo_class) output = get.execute([], fauxGflags) assert output == json.dumps(expected, sort_keys=True, indent=4, separators=(',', ': '))
def test_creates_simple_dir_outputformat(self, mock_kazoo_class): retval = {'path': '/foo'} mock_kazoo_class.get.return_value = retval fauxGflags = type('foo', (object,), {"quiet": True, "server": None, "username": None, "password": None, "outputformat": "dir", "data": False, "recursive": False}) get = Get(mock_kazoo_class) output = get.execute([], fauxGflags) assert output == "/foo"
def test_yaml_includes_data_on_data_flag(self, mock_kazoo_class): retval = {'path': '/foo', 'data': {'foo': 'bar'}} mock_kazoo_class.get.return_value = retval fauxGflags = type('foo', (object,), {"quiet": True, "server": None, "username": None, "password": None, "outputformat": "yaml", "data": True, "recursive": False}) expected = {"/foo": {"data": {"foo": "bar"}}} get = Get(mock_kazoo_class) output = get.execute([], fauxGflags) assert output == yaml.dump(expected, default_flow_style=False)
def test_creates_simple_yaml_outputformat(self, mock_kazoo_class): retval = {'path': '/foo'} mock_kazoo_class.get.return_value = retval fauxGflags = type('foo', (object,), {"quiet": True, "server": None, "username": None, "password": None, "outputformat": "yaml", "data": False, "recursive": False}) expected = {"/foo": {}} get = Get(mock_kazoo_class) output = get.execute([], fauxGflags) assert output == yaml.dump(expected, default_flow_style=False)
def test_json_includes_data_on_data_flag(self, mock_kazoo_class): retval = {'path': '/foo', 'data': {'foo': 'bar'}} mock_kazoo_class.get.return_value = retval fauxGflags = type('foo', (object,), {"quiet": True, "server": None, "username": None, "password": None, "outputformat": "json", "data": True, "recursive": False}) expected = {"/foo": {"data": {"foo": "bar"}}} get = Get(mock_kazoo_class) output = get.execute([], fauxGflags) assert output == json.dumps(expected, sort_keys=True, indent=4, separators=(',', ': '))
def test_creates_simple_json_outputformat(self, mock_kazoo_class): retval = {'path': '/foo'} mock_kazoo_class.get.return_value = retval fauxGflags = type('foo', (object,), {"quiet": True, "server": None, "username": None, "password": None, "outputformat": "json", "data": False, "recursive": False}) expected = {"/foo": {}} get = Get(mock_kazoo_class) output = get.execute([], fauxGflags) assert output == json.dumps(expected, sort_keys=True, indent=4, separators=(',', ': '))