[5ec3a0b] | 1 | import pytest |
---|
| 2 | from formencode.validators import Invalid |
---|
| 3 | from pyramid_simpleform import State |
---|
| 4 | |
---|
| 5 | from ow.models.user import User |
---|
| 6 | from ow.schemas.user import PasswordMatch, UniqueUsername, UniqueEmail |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | class TestPasswordMatch(object): |
---|
| 10 | |
---|
| 11 | @pytest.fixture |
---|
| 12 | def state(self): |
---|
| 13 | user = User(email='test@example.net') |
---|
| 14 | user.password = 's3cr3t' |
---|
| 15 | state = State(user=user) |
---|
| 16 | return state |
---|
| 17 | |
---|
| 18 | def test_validate_python_match(self, state): |
---|
| 19 | validator = PasswordMatch() |
---|
| 20 | res = validator._validate_python('s3cr3t', state) |
---|
| 21 | assert res is None |
---|
| 22 | |
---|
| 23 | def test_validate_python_not_match(self, state): |
---|
| 24 | validator = PasswordMatch() |
---|
| 25 | with pytest.raises(Invalid): |
---|
| 26 | validator._validate_python('wr0ng#p4ss', state) |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | class TestUniqueUsername(object): |
---|
| 30 | |
---|
| 31 | @pytest.fixture |
---|
| 32 | def state(self): |
---|
| 33 | state = State(names=['test', 'existing']) |
---|
| 34 | return state |
---|
| 35 | |
---|
| 36 | def test_validate_python_exists(self, state): |
---|
| 37 | validator = UniqueUsername() |
---|
| 38 | with pytest.raises(Invalid): |
---|
| 39 | validator._validate_python('test', state) |
---|
| 40 | with pytest.raises(Invalid): |
---|
| 41 | validator._validate_python('ExiSTing', state) |
---|
| 42 | |
---|
| 43 | def test_validate_python_not_exists(self, state): |
---|
| 44 | validator = UniqueUsername() |
---|
| 45 | res = validator._validate_python('not-existing', state) |
---|
| 46 | assert res is None |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | class TestUniqueEmail(object): |
---|
| 50 | |
---|
| 51 | @pytest.fixture |
---|
| 52 | def state(self): |
---|
| 53 | state = State(emails=['test@example.net', 'existing@example.net']) |
---|
| 54 | return state |
---|
| 55 | |
---|
| 56 | def test_validate_python_exists(self, state): |
---|
| 57 | validator = UniqueEmail() |
---|
| 58 | with pytest.raises(Invalid): |
---|
| 59 | validator._validate_python('test@example.net', state) |
---|
| 60 | with pytest.raises(Invalid): |
---|
| 61 | validator._validate_python('ExiSTing@example.net', state) |
---|
| 62 | |
---|
| 63 | def test_validate_python_not_exists(self, state): |
---|
| 64 | validator = UniqueEmail() |
---|
| 65 | res = validator._validate_python('not-existing@example.net', state) |
---|
| 66 | assert res is None |
---|