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()
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')
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'))
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()
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()
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)
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()
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")