Changeset d517001 in OpenWorkouts-current for ow/tests/views/test_workout.py


Ignore:
Timestamp:
Feb 15, 2019, 6:09:04 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
d5429c5
Parents:
d459ee2
Message:

(#58) Set a title automatically when adding manually a workout without
providing one.

The title is generated based on the only required data we have (starting
date and time) + sport (if provided).

File:
1 edited

Legend:

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

    rd459ee2 rd517001  
    126126        assert len(response['form'].form.errors) == 6
    127127
    128     def test_add_workout_manually_post_valid(self, valid_post_request):
     128    add_workout_params = [
     129        # no title, no sport, we generate a title based on when the
     130        # workout started
     131        ({'title': None, 'sport': None}, 'Morning workout'),
     132        # no title, sport given, we use the sport too in the automatically
     133        # generated title
     134        ({'title': None, 'sport': 'cycling'}, 'Morning cycling workout'),
     135        # title given, no sport, we use the provided title
     136        ({'title': 'Example workout', 'sport': None}, 'Example workout'),
     137        # title given, sport too, we use the provided title
     138        ({'title': 'Example workout', 'sport': 'cycling'}, 'Example workout'),
     139    ]
     140
     141    @pytest.mark.parametrize(('params', 'expected'), add_workout_params)
     142    def test_add_workout_manually_post_valid(self, params, expected,
     143                                             valid_post_request):
    129144        """
    130145        POST request to add a workout manually, providing the needed data
    131146        """
    132147        request = valid_post_request
     148        if params['title'] is not None:
     149            request.POST['title'] = params['title']
     150        if params['sport'] is not None:
     151            request.POST['sport'] = params['sport']
    133152        user = request.root['john']
    134153        assert len(user.workouts()) == 1
     
    137156        assert response.location.endswith('/2/')
    138157        assert len(user.workouts()) == 2
     158        assert user['2'].title == expected
    139159
    140160    def test_add_workout_get(self, dummy_request):
Note: See TracChangeset for help on using the changeset viewer.