Ejemplo n.º 1
0
 def filter(self, name, subval=None):
     check_state_for('index', self._declared_in)
     if '=' in name and subval is None:
         name, subval = name.split('=', 1)
     if subval is None:
         subval = ''
     if not isinstance(subval, basestring):
         subval = str(subval)
     # maxresults because of riak bug with small number of results
     # https://github.com/basho/riak/issues/608
     declared = self._declared_in
     if not subval.endswith('*'):
         res = declared._get_index('{}_bin'.format(self.fname),
                                   startkey='{}~{}'.format(name, subval),
                                   endkey='{}~{} '.format(name, subval),
                                   max_results=100000,
                                   return_terms=True).results
     else:
         subval = subval.replace('*', '')
         res = declared._get_index('{}_bin'.format(self.fname),
                                   startkey='{}~{}'.format(name, subval),
                                   endkey='{}~{}~'.format(name, subval),
                                   max_results=100000,
                                   return_terms=True).results
     return set(map(itemgetter(1), res))
Ejemplo n.º 2
0
 def filter(self, name, subval=None):
     check_state_for('index', self._declared_in)
     if '=' in name and subval is None:
         name, subval = name.split('=', 1)
     if subval is None:
         subval = ''
     if not isinstance(subval, basestring):
         subval = str(subval)
     # maxresults because of riak bug with small number of results
     # https://github.com/basho/riak/issues/608
     declared = self._declared_in
     if not subval.endswith('*'):
         res = declared._get_index('{}_bin'.format(self.fname),
                                   startkey='{}~{}'.format(name, subval),
                                   endkey='{}~{} '.format(name, subval),
                                   max_results=100000,
                                   return_terms=True).results
     else:
         subval = subval.replace('*', '')
         res = declared._get_index('{}_bin'.format(self.fname),
                                   startkey='{}~{}'.format(name, subval),
                                   endkey='{}~{}~'.format(name, subval),
                                   max_results=100000,
                                   return_terms=True).results
     return set(map(itemgetter(1), res))
Ejemplo n.º 3
0
def test_changes_state(rk):
    key = next(rk)
    r = create_resource(key, {'name': 'a name'})
    r.inputs['a'] = 1
    with pytest.raises(Exception):
        # raise exception when something is changed
        r.inputs['a']
    r.save()
    check_state_for('index', r)
Ejemplo n.º 4
0
def test_changes_state(rk):
    key = next(rk)
    r = create_resource(key, {'name': 'a name'})
    r.inputs['a'] = 1
    with pytest.raises(Exception):
        # raise exception when something is changed
        r.inputs['a']
    r.save()
    check_state_for('index', r)
Ejemplo n.º 5
0
 def _get_field_val(self, name, other=None):
     # maybe it should be tco
     if other:
         full_name = '{}_other_{}'.format(name, other)
     else:
         full_name = name
     try:
         return self._cache[full_name]
     except KeyError:
         pass
     with self.inputs_index_cache as c:
         check_state_for('index', self._instance)
         fname = self.fname
         my_name = self._instance.key
         self._has_own_input(name)
         ind_name = '{}_recv_bin'.format(fname)
         kwargs = dict(startkey='{}|'.format(my_name),
                       endkey='{}|~'.format(my_name),
                       return_terms=True)
         my_type = self._input_type(self._instance, name)
         if my_type == InputTypes.simple:
             max_results = 1
         else:
             max_results = 99999
         c.get_index(self._instance._get_index, ind_name, **kwargs)
         recvs = tuple(c.filter(startkey="{}|{}|".format(my_name, name),
                                endkey="{}|{}|~".format(my_name, name),
                                max_results=max_results))
     if not recvs:
         _res = self._get_raw_field_val(name)
         self._cache[name] = _res
         if other:
             if other == '_key':
                 k = self._instance.key
                 self._cache[full_name] = k
                 return k
             other_res = self._get_field_val(other)
             self._cache[full_name] = other_res
             return other_res
         return _res
     my_meth = getattr(self, '_map_field_val_{}'.format(my_type.name))
     return my_meth(recvs, name, my_name, other=other)