Changeset 1d92bf2 in OpenWorkouts-current for ow/tests/views/test_root.py


Ignore:
Timestamp:
Dec 16, 2018, 1:07:04 AM (5 years ago)
Author:
borja <borja@…>
Branches:
current, feature/docs, master
Children:
6560b8f
Parents:
929097a
Message:

(#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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/tests/views/test_root.py

    r929097a r1d92bf2  
    2020
    2121    @pytest.fixture
    22     def root(self):
     22    def john(self):
     23        user = User(firstname='John', lastname='Doe',
     24                    email='john.doe@example.net')
     25        user.password = 's3cr3t'
     26        return user
     27
     28    @pytest.fixture
     29    def root(self, john):
    2330        root = OpenWorkouts()
    24         root['john'] = User(firstname='John', lastname='Doe',
    25                             email='john.doe@example.net')
    26         root['john'].password = 's3cr3t'
     31        root.add_user(john)
    2732        workout = Workout(
    2833            start=datetime(2015, 6, 28, 12, 55, tzinfo=timezone.utc),
     
    3035            distance=30, sport='cycling'
    3136        )
    32         root['john'].add_workout(workout)
     37        john.add_workout(workout)
    3338        return root
    3439
     
    5055        return request
    5156
    52     def test_user_list(self, get_request):
     57    def test_user_list(self, get_request, john):
    5358        request = get_request
    5459        response = user_list(request.root, request)
    55         assert list(response['users']) == [request.root['john']]
     60        assert list(response['users']) == [john]
    5661
    5762    def test_add_user_get(self, get_request):
     
    6671        response = add_user(request.root, request)
    6772        assert 'form' in response
    68         # All required fields (4) are marked in the form errors
     73        # All required fields (3) are marked in the form errors
    6974        # You can see which fields are required in the schema
    7075        # ow.schemas.user.UserAddSchema
    71         assert len(response['form'].form.errors) == 4
     76        errors = response['form'].form.errors
     77        assert len(errors) == 3
     78        assert 'email' in errors
     79        assert 'firstname' in errors
     80        assert 'lastname' in errors
    7281
    7382    def test_add_user_post_valid(self, post_request):
    7483        request = post_request
    75         request.POST['uid'] = 'addeduser'
     84        request.POST['nickname'] = 'addeduser'
    7685        request.POST['email'] = 'addeduser@example.net'
    7786        request.POST['firstname'] = 'added'
     
    8089        assert isinstance(response, HTTPFound)
    8190        assert response.location.endswith('/userlist')
    82         assert len(request.root.all_usernames()) == 2
    83         assert 'addeduser' in request.root.all_usernames()
     91        # 1 nick name, as the default user has no nickname
     92        assert len(request.root.all_nicknames) == 1
     93        assert 'addeduser' in request.root.all_nicknames
Note: See TracChangeset for help on using the changeset viewer.