source: OpenWorkouts-current/ow/tests/schemas/test_user.py @ 5ec3a0b

currentfeature/docs
Last change on this file since 5ec3a0b was 5ec3a0b, checked in by borja <borja@…>, 5 years ago

Imported sources from the old python2-only repository:

  • Modified the code so it is python 3.6 compatible
  • Fixed deprecation warnings, pyramid 1.10.x supported now
  • Fixed deprecation warnings about some libraries, like pyramid-simpleform
  • Added pytest-pycodestyle and pytest-flakes for automatic checks on the source code files when running tests.
  • Added default pytest.ini setup to enforce some default parameters when running tests.
  • Cleaned up the code a bit, catched up with tests coverage.
  • Property mode set to 100644
File size: 2.0 KB
Line 
1import pytest
2from formencode.validators import Invalid
3from pyramid_simpleform import State
4
5from ow.models.user import User
6from ow.schemas.user import PasswordMatch, UniqueUsername, UniqueEmail
7
8
9class 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
29class 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
49class 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
Note: See TracBrowser for help on using the repository browser.