def test_to_python_invalid_digest(self): field = ChallengeField('md5') with pytest.raises(ValueError): field.to_python(None, { 'salt': base64.b64encode(b'salt').decode(), 'digest': '==Za' })
def test_to_python_invalid_salt(self): field = ChallengeField('md5') with pytest.raises(ValueError): field.to_python(MockConfig(), { 'salt': '==Zaa', 'digest': base64.b64encode(b'digest').decode() })
def test_to_python_dict(self): field = ChallengeField('md5') salt = base64.b64encode(b'salt').decode() digest = base64.b64encode(b'digest').decode() val = field.to_python(MockConfig(), {'salt': salt, 'digest': digest}) assert val.salt == b'salt' assert val.digest == b'digest' assert val.algorithm is hashlib.md5
def test_to_python_none(self): field = ChallengeField('md5', key='test') assert field.to_python(None, None) is None
def test_to_python_error(self): field = ChallengeField('md5') with pytest.raises(ValueError): field.to_python(None, 100)
def test_to_python_str(self): field = ChallengeField('md5') field._hash = MagicMock() field.to_python(None, 'message') field._hash.assert_called_with('message')