示例#1
0
def test_compressables_can_be_compressed():
    string = "a" * 1000
    text = props.Text(compressed=True, compression_level=9)
    compressed_bytes = text.prepare_to_store(None, string)
    assert len(compressed_bytes) == 17

    uncompressed_string = text.prepare_to_load(None, compressed_bytes)
    assert uncompressed_string == string
示例#2
0
class Post(Model):
    author = props.Key(indexed=True, kind=User)
    title = props.String()

    def __compute_slug(self):
        if self.title is None:
            return None

        return slugify(self.title)

    def __compute_body(self):
        if self.body is None:
            return None

        return markdown(self.body)

    slug = props.Computed(__compute_slug)
    body = props.Text()
    body_markdown = props.Computed(__compute_body)
    tags = props.String(indexed=True, repeated=True)
    created_at = props.DateTime(indexed=True, auto_now_add=True)
    updated_at = props.DateTime(indexed=True, auto_now=True)
示例#3
0
def test_compressables_compression_level_needs_to_be_in_a_specific_range():
    with pytest.raises(ValueError):
        props.Text(compressed=True, compression_level=20)
示例#4
0
class GuestbookEntry(Model):
    author = props.String(optional=True)
    message = props.Text()
    created_at = props.DateTime(indexed=True, auto_now_add=True)