コード例 #1
0
    def test_validate_enforces_binary_strings(self):
        field = BinaryField()

        expect(field.validate(1)).to_be_false()
        expect(field.validate(b'abc')).to_be_true()
        expect(field.validate(six.u('abc'))).to_be_false()
        expect(field.validate(None)).to_be_true()
コード例 #2
0
class User(Document):
    def __init__(self, **kwargs):
        super(User, self).__init__(**kwargs)

    id = IntField(unique=True)
    email = EmailField()

    _salt = BinaryField(12)
    # 64 is the length of the SHA-256 encoded string length
    _password = StringField(64)

    group = ReferenceField('scheduler.model.Group')
    timetable = EmbeddedDocumentField('scheduler.model.Schedule')
コード例 #3
0
 def test_from_son(self):
     field = BinaryField()
     expect(field.from_son(None)).to_be_null()
     expect(field.from_son(six.u('data'))).to_equal(six.b('data'))
コード例 #4
0
 def test_is_empty(self):
     field = BinaryField()
     expect(field.is_empty(None)).to_be_true()
     expect(field.is_empty("")).to_be_true()
     expect(field.is_empty("123")).to_be_false()
コード例 #5
0
    def test_validate_enforces_max_bytes(self):
        field = BinaryField(max_bytes=20)

        expect(field.validate(b"-----")).to_be_true()
        expect(field.validate(b"-----" * 40)).to_be_false()
コード例 #6
0
 def test_create_binary_field(self):
     field = BinaryField(db_field="test", max_bytes=200)
     expect(field.db_field).to_equal("test")
     expect(field.max_bytes).to_equal(200)
コード例 #7
0
 def test_is_empty(self):
     field = BinaryField()
     expect(field.is_empty(None)).to_be_true()
     expect(field.is_empty("")).to_be_true()
     expect(field.is_empty("123")).to_be_false()
コード例 #8
0
    def test_validate_enforces_max_bytes(self):
        field = BinaryField(max_bytes=20)

        expect(field.validate(b"-----")).to_be_true()
        expect(field.validate(b"-----" * 40)).to_be_false()
コード例 #9
0
    def test_validate_enforces_binary_strings(self):
        field = BinaryField()

        expect(field.validate(1)).to_be_false()
        expect(field.validate(b'abc')).to_be_true()
        expect(field.validate(six.u('abc'))).to_be_false()
コード例 #10
0
 def test_to_son(self):
     field = BinaryField()
     expect(field.to_son(b"abc")).to_equal(b"abc")
     expect(field.to_son("abc")).to_equal(b"abc")
コード例 #11
0
 def test_to_son(self):
     field = BinaryField()
     expect(field.to_son(b"abc")).to_equal(b"abc")
     expect(field.to_son("abc")).to_equal(b"abc")