source: OpenWorkouts-current/ow/tests/models/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.4 KB
Line 
1import pytest
2from pyramid.security import Allow
3
4from ow.models.root import OpenWorkouts
5from ow.models.workout import Workout
6from ow.models.user import User
7
8
9class TestUser(object):
10    @pytest.fixture
11    def root(self):
12        root = OpenWorkouts()
13        root['john'] = User(firstname='John', lastname='Doe',
14                            email='john.doe@example.net')
15        root['john'].password = 's3cr3t'
16        return root
17
18    @pytest.fixture
19    def workouts(self):
20        workouts = [Workout(sport='running'),
21                    Workout(sport='cycling'),
22                    Workout(sport='swimming')]
23        return workouts
24
25    def test_user_attrs(self, root):
26        assert root['john'].firstname == 'John'
27        assert root['john'].lastname == 'Doe'
28        assert root['john'].email == 'john.doe@example.net'
29
30    def test__acl__(self, root):
31        uid = str(root['john'].uid)
32        permissions = [(Allow, uid, 'edit'), (Allow, uid, 'view')]
33        assert root['john'].__acl__() == permissions
34
35    def test__str__(self, root):
36        email = root['john'].email
37        uid = str(root['john'].uid)
38        assert root['john'].__str__() == u'User: ' + email + ' (' + uid + ')'
39
40    def test_fullname(self, root):
41        assert root['john'].fullname == 'John Doe'
42
43    def test_password_is_encrypted(self, root):
44        assert root['john'].password != 's3cr3t'
45
46    def test_check_wrong_password(self, root):
47        assert not root['john'].check_password('badpass')
48
49    def test_check_good_password(self, root):
50        assert root['john'].check_password('s3cr3t')
51
52    def test_add_workout(self, root, workouts):
53        # First add all workouts at once
54        for workout in workouts:
55            root['john'].add_workout(workout)
56        # Then check they are there, in the correct position/number
57        for workout in workouts:
58            index = workouts.index(workout) + 1
59            assert root['john'][str(index)] == workout
60
61    def test_workouts(self, root, workouts):
62        # First add all workouts at once
63        for workout in workouts:
64            root['john'].add_workout(workout)
65        # workouts() will return the workouts sorted from newest to oldest
66        workouts.reverse()
67        assert list(root['john'].workouts()) == workouts
68        assert list(root['john'].workout_ids()) == ['1', '2', '3']
69        assert root['john'].num_workouts == len(workouts)
Note: See TracBrowser for help on using the repository browser.