Ejemplo n.º 1
0
    def test_get_object_item_desired_fields_differ_from_item(self):
        class Fake(object):
            def __init__(self):
                self.id = 'test_id_1'
                self.name = 'test_name'
                self.test_user = '******'

        fields = ('name', 'id', 'test user')
        item = Fake()
        actual = utils.get_item_properties(item, fields)
        self.assertNotEqual(('test_name', 'test_id', 'test'), actual)
Ejemplo n.º 2
0
    def test_get_object_item_desired_fields_is_empty(self):
        class Fake(object):
            def __init__(self):
                self.id = 'test_id_1'
                self.name = 'test_name'
                self.test_user = '******'

        fields = []
        item = Fake()
        actual = utils.get_item_properties(item, fields)
        self.assertEqual((), actual)
Ejemplo n.º 3
0
    def test_get_object_item_desired_fields_is_empty(self):
        class Fake(object):
            def __init__(self):
                self.id = 'test_id_1'
                self.name = 'test_name'
                self.test_user = '******'

        fields = []
        item = Fake()
        actual = utils.get_item_properties(item, fields)
        self.assertEqual((), actual)
Ejemplo n.º 4
0
    def test_get_object_item_desired_fields_differ_from_item(self):
        class Fake(object):
            def __init__(self):
                self.id = 'test_id_1'
                self.name = 'test_name'
                self.test_user = '******'

        fields = ('name', 'id', 'test user')
        item = Fake()
        actual = utils.get_item_properties(item, fields)
        self.assertNotEqual(('test_name', 'test_id', 'test'), actual)
Ejemplo n.º 5
0
    def test_get_object_item_properties_mixed_case_fields(self):
        class Fake(object):
            def __init__(self):
                self.id = 'test_id'
                self.name = 'test_name'
                self.test_user = '******'

        fields = ('name', 'id', 'test user')
        mixed_fields = ('test user', 'ID')
        item = Fake()
        actual = utils.get_item_properties(item, fields, mixed_fields)
        self.assertEqual(('test_name', 'test_id', 'test'), actual)
Ejemplo n.º 6
0
    def test_get_object_item_properties_mixed_case_fields(self):
        class Fake(object):
            def __init__(self):
                self.id = 'test_id'
                self.name = 'test_name'
                self.test_user = '******'

        fields = ('name', 'id', 'test user')
        mixed_fields = ('test user', 'ID')
        item = Fake()
        actual = utils.get_item_properties(item, fields, mixed_fields)
        self.assertEqual(('test_name', 'test_id', 'test'), actual)
Ejemplo n.º 7
0
 def setup_columns(self, info, parsed_args):
     _columns = len(info) > 0 and sorted(info[0].keys()) or []
     if not _columns:
         # clean the parsed_args.columns so that cliff will not break
         parsed_args.columns = []
     elif parsed_args.columns:
         _columns = [x for x in parsed_args.columns if x in _columns]
     elif self.list_columns:
         # if no -c(s) by user and list_columns, we use columns in
         # both list_columns and returned resource.
         # Also Keep their order the same as in list_columns
         _columns = [x for x in self.list_columns if x in _columns]
     return (_columns, (utils.get_item_properties(
         s, _columns, formatters=self._formatters, )
         for s in info), )
Ejemplo n.º 8
0
 def setup_columns(self, info, parsed_args):
     _columns = len(info) > 0 and sorted(info[0].keys()) or []
     if not _columns:
         # clean the parsed_args.columns so that cliff will not break
         parsed_args.columns = []
     elif parsed_args.columns:
         _columns = [x for x in parsed_args.columns if x in _columns]
     elif self.list_columns:
         # if no -c(s) by user and list_columns, we use columns in
         # both list_columns and returned resource.
         # Also Keep their order the same as in list_columns
         _columns = [x for x in self.list_columns if x in _columns]
     return (_columns, (utils.get_item_properties(
         s, _columns, formatters=self._formatters, )
         for s in info), )
Ejemplo n.º 9
0
    def test_get_object_item_with_formatters(self):
        class Fake(object):
            def __init__(self):
                self.id = 'test_id'
                self.name = 'test_name'
                self.test_user = '******'

        class FakeCallable(object):
            def __call__(self, *args, **kwargs):
                return 'pass'

        fields = ('name', 'id', 'test user', 'is_public')
        formatters = {'is_public': FakeCallable()}
        item = Fake()
        act = utils.get_item_properties(item, fields, formatters=formatters)
        self.assertEqual(('test_name', 'test_id', 'test', 'pass'), act)
Ejemplo n.º 10
0
    def test_get_object_item_with_formatters(self):
        class Fake(object):
            def __init__(self):
                self.id = 'test_id'
                self.name = 'test_name'
                self.test_user = '******'

        class FakeCallable(object):
            def __call__(self, *args, **kwargs):
                return 'pass'

        fields = ('name', 'id', 'test user', 'is_public')
        formatters = {'is_public': FakeCallable()}
        item = Fake()
        act = utils.get_item_properties(item, fields, formatters=formatters)
        self.assertEqual(('test_name', 'test_id', 'test', 'pass'), act)
Ejemplo n.º 11
0
 def test_get_dict_item_properties(self):
     item = {'name': 'test_name', 'id': 'test_id'}
     fields = ('name', 'id')
     actual = utils.get_item_properties(item=item, fields=fields)
     self.assertEqual(('test_name', 'test_id'), actual)
Ejemplo n.º 12
0
 def test_get_dict_item_properties(self):
     item = {'name': 'test_name', 'id': 'test_id'}
     fields = ('name', 'id')
     actual = utils.get_item_properties(item=item, fields=fields)
     self.assertEqual(('test_name', 'test_id'), actual)