Changeset fe6089a in OpenWorkouts-current for ow


Ignore:
Timestamp:
Dec 21, 2018, 11:11:44 AM (5 years ago)
Author:
borja <borja@…>
Branches:
current, feature/docs, master
Children:
64e8299
Parents:
31adfa5
Message:

Tests and coverage catch up.

Location:
ow
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ow/models/workout.py

    r31adfa5 rfe6089a  
    6262
    6363    @property
     64    def owner(self):
     65        return self.__parent__
     66
     67    @property
    6468    def end(self):
    6569        if not self.duration:
  • ow/tests/models/test_workout.py

    r31adfa5 rfe6089a  
    5959    def test_workout_id(self, root):
    6060        assert root['john']['1'].workout_id == '1'
     61
     62    def test_owner(self, root):
     63        # workout with owner
     64        assert root['john']['1'].owner == root['john']
     65        # workout without owner
     66        w = Workout()
     67        assert w.owner is None
    6168
    6269    def test_end(self, root):
  • ow/tests/views/test_user.py

    r31adfa5 rfe6089a  
    122122        assert response.location == request.resource_url(root, 'login')
    123123
    124     def test_dashboard_redirect_authenticated(self, root):
     124    def test_dashboard_redirect_authenticated(self, root, john):
    125125        """
    126126        Authenticated user accesing the root object, send the user to her
     
    131131        authenticated_userid, which cannot be easily set in the DummyRequest
    132132        """
     133        alt_request = DummyRequest()
    133134        request = Mock()
    134135        request.root = root
    135         request.authenticated_userid = 'john'
    136         request.resource_url.return_value = '/dashboard'
     136        request.authenticated_userid = str(john.uid)
     137        request.resource_url = alt_request.resource_url
    137138        response = user_views.dashboard_redirect(root, request)
    138139        assert isinstance(response, HTTPFound)
    139         assert response.location == '/dashboard'
     140        assert response.location == request.resource_url(john)
     141        # if authenticated_userid is the id of an user that does not exist
     142        # anymore, we send the user to the logout page
     143        request.authenticated_userid = 'faked-uid'
     144        response = user_views.dashboard_redirect(root, request)
     145        assert isinstance(response, HTTPFound)
     146        assert response.location == request.resource_url(root, 'logout')
    140147
    141148    def test_dashboard(self, dummy_request, john):
     
    287294        assert response['form'].errorlist() == html_error
    288295        assert response['form'].errors_for('email') == [error]
     296
     297    def test_edit_profile_post_ok_picture_empty_bytes(
     298            self, profile_post_request, john):
     299        """
     300        POST request with an empty picture, the content of
     301        request['POST'].picture is a empty bytes string (b'') which triggers
     302        a bug in formencode, we put a fix in place, test that
     303        (more in ow.user.views.edit_profile)
     304        """
     305        # for the purposes of this test, we can mock the picture
     306        picture = Mock()
     307        john.picture = picture
     308        request = profile_post_request
     309        user = john
     310        # Mimic what happens when a picture is not provided by the user
     311        request.POST['picture'] = b''
     312        response = user_views.edit_profile(user, request)
     313        assert isinstance(response, HTTPFound)
     314        assert response.location == request.resource_url(user, 'profile')
     315        assert user.picture == picture
     316
     317    def test_edit_profile_post_ok_missing_picture(
     318            self, profile_post_request, john):
     319        """
     320        POST request without picture
     321        """
     322        # for the purposes of this test, we can mock the picture
     323        picture = Mock()
     324        john.picture = picture
     325        request = profile_post_request
     326        user = john
     327        # No pic is provided in the request POST values
     328        del request.POST['picture']
     329        response = user_views.edit_profile(user, request)
     330        assert isinstance(response, HTTPFound)
     331        assert response.location == request.resource_url(user, 'profile')
     332        assert user.picture == picture
     333
     334    def test_edit_profile_post_ok_nickname(self, profile_post_request, john):
     335        """
     336        User with a nickname set saves profile without changing the profile,
     337        we have to be sure there are no "nickname already in use" errors
     338        """
     339        request = profile_post_request
     340        user = john
     341        user.nickname = 'mr_jones'
     342        # add the nickname, the default post request has not a nickname set
     343        request.POST['nickname'] = 'mr_jones'
     344        response = user_views.edit_profile(user, request)
     345        assert isinstance(response, HTTPFound)
     346        assert response.location == request.resource_url(user, 'profile')
    289347
    290348    def test_change_password_get(self, dummy_request, john):
  • ow/tests/views/test_workout.py

    r31adfa5 rfe6089a  
    164164        assert len(response['form'].form.errors) == 1
    165165
     166    def test_add_workout_post_invalid_bytes(self, dummy_request):
     167        """
     168        POST request to add a workout, without uploading a tracking file,
     169        which sends an empty bytes object (b'')
     170        """
     171        request = dummy_request
     172        user = request.root['john']
     173        request.method = 'POST'
     174        request.POST = MultiDict({
     175            'tracking_file': b'',
     176            'submit': True,
     177            })
     178        assert len(request.root['john'].workouts()) == 1
     179        response = workout_views.add_workout(user, request)
     180        assert 'form' in response
     181        # Only one required field in this case, the tracking file
     182        assert len(response['form'].form.errors) == 1
     183
    166184    @pytest.mark.parametrize('filename', gpx_filenames)
    167185    def test_add_workout_post_valid(self, filename, dummy_request):
     
    256274        assert len(response['form'].form.errors) == 1
    257275
     276    def test_update_workout_from_file_post_invalid_bytes(self, dummy_request):
     277        """
     278        POST request to update a workout, without uploading a tracking file,
     279        which sends an empty bytes object (b'')
     280        """
     281        request = dummy_request
     282        user = request.root['john']
     283        workout = user.workouts()[0]
     284        request.method = 'POST'
     285        request.POST = MultiDict({
     286            'tracking_file': b'',
     287            'submit': True,
     288            })
     289        response = workout_views.update_workout_from_file(workout, request)
     290        assert 'form' in response
     291        # Only one required field in this case, the tracking file
     292        assert len(response['form'].form.errors) == 1
     293
    258294    @pytest.mark.parametrize('filen', gpx_filenames)
    259295    def test_update_workout_from_file_post_valid(self, filen, dummy_request):
Note: See TracChangeset for help on using the changeset viewer.