示例#1
0
class CurrentTag(Model):
    # key is flattened tag
    current_batch = ForeignKey(Batch, null=True)
    tag = Tag()
    metadata = Dynamic(Unicode())

    @staticmethod
    def _flatten_tag(tag):
        return "%s:%s" % tag

    @staticmethod
    def _split_key(key):
        return tuple(key.split(':', 1))

    @classmethod
    def _tag_and_key(cls, tag_or_key):
        if isinstance(tag_or_key, tuple):
            # key looks like a tag
            tag, key = tag_or_key, cls._flatten_tag(tag_or_key)
        else:
            tag, key = cls._split_key(tag_or_key), tag_or_key
        return tag, key

    def __init__(self, manager, key, _riak_object=None, **kw):
        tag, key = self._tag_and_key(key)
        if _riak_object is None:
            kw['tag'] = tag
        super(CurrentTag, self).__init__(manager, key,
                                         _riak_object=_riak_object, **kw)

    @classmethod
    def load(cls, manager, key, result=None):
        _tag, key = cls._tag_and_key(key)
        return super(CurrentTag, cls).load(manager, key, result)
示例#2
0
class Batch(Model):
    # key is batch_id
    tags = ListOf(Tag())
    metadata = Dynamic(Unicode())
示例#3
0
class BatchVNone(Model):
    bucket = 'batch'

    # key is batch_id
    tags = ListOf(Tag())
    metadata = Dynamic(Unicode())
示例#4
0
 def test_validate(self):
     t = Tag()
     t.validate(("pool", "tagname"))
     self.assertRaises(ValidationError, t.validate, ["pool", "tagname"])
     self.assertRaises(ValidationError, t.validate, ("pool",))
示例#5
0
 def test_from_riak(self):
     t = Tag()
     self.assertEqual(t.from_riak(["pool", "tagname"]), ("pool", "tagname"))
示例#6
0
 def test_to_riak(self):
     t = Tag()
     self.assertEqual(t.to_riak(("pool", "tagname")), ["pool", "tagname"])
示例#7
0
 def test_validate(self):
     t = Tag()
     t.validate(("pool", "tagname"))
     self.assertRaises(ValidationError, t.validate, ["pool", "tagname"])
     self.assertRaises(ValidationError, t.validate, ("pool", ))
示例#8
0
 def test_from_riak(self):
     t = Tag()
     self.assertEqual(t.from_riak(["pool", "tagname"]), ("pool", "tagname"))
示例#9
0
 def test_to_riak(self):
     t = Tag()
     self.assertEqual(t.to_riak(("pool", "tagname")), ["pool", "tagname"])