Beispiel #1
0
    def find_objects(self,
                     names_or_ids,
                     objtype=None,
                     match=False,
                     date_range=None,
                     allow_missing=False):
        matched_objs = []
        objs = self.client.list_objects(objtype or self.objtype)
        if names_or_ids:
            for name_or_id in names_or_ids:
                if util.is_id(name_or_id):
                    matched_objs.append(apiclient.find(objs, 'id', name_or_id))
                elif match:
                    matched_objs.extend(
                        apiclient.match(objs, 'title', name_or_id))
                else:
                    try:
                        matched_objs.append(
                            apiclient.find(objs, 'title', name_or_id))
                    except apiclient.NotFound:
                        if not allow_missing:
                            raise
        else:
            matched_objs = objs

        if date_range:
            matched_objs = [
                x for x in matched_objs if self._match_date(x, date_range)
            ]

        if not names_or_ids and len(matched_objs) == len(objs):
            # Refuse to find all objects because no criteria was specified
            raise _Safety()

        return matched_objs
Beispiel #2
0
 def get_object(self, name_or_id, **kwargs):
     objtype = kwargs.pop('objtype', self.objtype)
     if util.is_id(name_or_id):
         return self.client.get_object(objtype, id_=name_or_id,
                                       **kwargs)
     else:
         return self.client.get_object(objtype, name=name_or_id,
                                       **kwargs)
Beispiel #3
0
    def test_is_id(self):
        ids = ['0b00901f6549abf8a8b7de8b49d24894',
               '0c94be3d-6fd9-45a0-9ca5-e8fd6969b7d3',
               '6505ccef3cfffd6229e71f1528650b9edf8bfb47']
        not_ids = ['0b00901f6549abf8a8b7de8b49d2489z',
                   '0c94be3d-6fd9-45a0-9ca5-e8fd6969b7dz',
                   '0b00901f6549abf8a8b7de8b49d2489',
                   '0b00901f6549abf8a8b7de8b49d248933',
                   '0c94be3d-6fd9-45a0-9ca5:e8fd6969b7dz',
                   '0c94be3d-6fd9-45a0-9ca5 e8fd6969b7dz',
                   'This is a name',
                   'name']

        for i in ids:
            self.assertTrue(util.is_id(i))

        for i in not_ids:
            self.assertFalse(util.is_id(i))
Beispiel #4
0
 def find_objects(self, names_or_ids, objtype=None, match=False):
     matched_objs = []
     objs = self.client.list_objects(objtype or self.objtype)
     for name_or_id in names_or_ids:
         if util.is_id(name_or_id):
             matched_objs.append(apiclient.find(objs, 'id', name_or_id))
         elif match:
             matched_objs.extend(apiclient.match(objs, 'title', name_or_id))
         else:
             matched_objs.append(apiclient.find(objs, 'title', name_or_id))
     return matched_objs