source: OpenWorkouts-current/ow/tests/schemas/test_user.py @ 1d92bf2

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

(#37) Allow login using email address instead of username:

  • Use user uids as keys in the root folder for referencing user objects (instead of username)
  • Use uids for referencing users all over the place (auth, permissions, traversal urls, etc)
  • Replaced the username concept with nickname. This nickname will be used as a shortcut to access "public profile" pages for users
  • Reworked lots of basic methods in the OpenWorkouts root object (s/username/nickname, marked as properties some methods like users, emails, etc)
  • Added new add_user() and delete_user() helpers to the OpenWorkouts root object
  • Fixed bug in the dashboard redirect view, causing an endless loop if an authenticated user does not exist anymore when loading a page.
  • Lots of tests fixes, adaptations and catch up.
  • 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, UniqueNickname, 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 TestUniqueNickname(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 = UniqueNickname()
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 = UniqueNickname()
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.