Example #1
0
 def test_append(self):
     view = self.object
     MockClient.insert = \
         lambda conn, keyspace, key, path, value, time, x: True
     rec = Record()
     rec.key = Key(keyspace="eggs", column_family="bacon", key="tomato")
     self.object.append(rec)
Example #2
0
    def test_batch_load(self):
        records, keys = [], []
        for x in range(10):
            record = Record()
            record.key = Key('eggs', 'bacon')
            record['number'] = x
            record['square'] = x * x
            records.append(record)
            keys.append(record.key)

        backing = {}
        for record in records:
            backing[record.key.key] = [ColumnOrSuperColumn(col)
                                       for col in record._columns.values()]

        mock_client = MockClient("Eggs", [])
        mock_client.multiget_slice = \
            lambda keys, parent, pred, clvl: backing
        sets.itr.get_pool = lambda ks: mock_client

        out_records = self.object._batch_load(Record, keys)
        for record in out_records:
            self.assert_(isinstance(record, Record))
            self.assert_(record.key in keys)
            orig = records[records.index(record)]
            self.assert_(orig['number'] == record['number'])
            self.assert_(orig['square'] == record['square'])
Example #3
0
 def test_append(self):
     view = self.object
     MockClient.insert = \
         lambda conn, keyspace, key, path, value, time, x: True
     rec = Record()
     rec.key = Key(keyspace="eggs", column_family="bacon", key="tomato")
     self.object.append(rec)
Example #4
0
    def _get_records(self, count, **kwargs):
        """Return records for testing."""
        records = []
        for n in range(count):
            record = Record()

            if kwargs:
                record.key = Key(**kwargs)
            records.append(record)

        return records
Example #5
0
    def setUp(self):
        """Prepare the test environment."""
        num_records = 15
        keys = [Key(keyspace="spam", column_family="bacon") for x in range(num_records)]

        records = []
        for key in keys:
            r = Record()
            r.key = key
            records.append(r)

        self.records = records
Example #6
0
    def setUp(self):
        """Prepare the test environment."""
        num_records = 15
        keys = [Key(keyspace='spam', column_family='bacon')
                for x in range(num_records)]

        records = []
        for key in keys:
            r = Record()
            r.key = key
            records.append(r)

        self.records = records
Example #7
0
    def save(self):
        for name, field in self.fields.items():
            if name not in self:
                if field.default != None:
                    self[name] = getattr(self, name)
                elif field.required:
                    raise ValueError("Missing required field '%s'." % name)

            if name in self:
                field.validate(self[name])

        # data = dict([(k, self.fields[k].encode(v)) for k, v in self.items()])

        Record.save(self)
Example #8
0
    def _marshal(self):
        result = Record._marshal(self)

        changed = []
        for col in result['changed']:
            col.value = self.fields[col.name].encode(col.value)
            changed.append(col)

        result['changed'] = tuple(changed)

        return result
Example #9
0
    def test_append_view(self):
        """Test PartitionedView._append_view."""
        record = Record()
        self.object._get_view = lambda key: key
        data = (('one', 'two'),
                ['one', 'two'],
                iter(('one', 'two')))

        for data_set in data:
            self.object.partition_keys = lambda: data_set
            self.assert_(self.object._append_view(record) == "one")
Example #10
0
 def delete(self):
     Record.remove(self)
Example #11
0
 def get_key(self):
     return Key(keyspace=self.Meta.keyspace, 
         key=Record.sanitize(self, self[self._key_field]),
         column_family=self.Meta.column_family)