Index: ow/tests/views/test_workout.py
===================================================================
--- ow/tests/views/test_workout.py	(revision 8c2b0949ae91540ee5c8101b9d5ff39003773da3)
+++ ow/tests/views/test_workout.py	(revision 5ec3a0b5cf5640304a0953320daef2a28bbca9a5)
@@ -1,9 +1,7 @@
 import os
-import json
 from io import BytesIO
 from datetime import datetime, timedelta, timezone
 from cgi import FieldStorage
-from unittest.mock import Mock, patch, PropertyMock
-from decimal import Decimal
+from unittest.mock import Mock, patch
 
 import pytest
@@ -11,5 +9,4 @@
 from pyramid.testing import DummyRequest
 from pyramid.httpexceptions import HTTPFound, HTTPNotFound
-from pyramid.response import Response
 
 from webob.multidict import MultiDict
@@ -129,36 +126,9 @@
         assert len(response['form'].form.errors) == 6
 
-    add_workout_params = [
-        # no title, no sport, we generate a title based on when the
-        # workout started
-        ({'title': None, 'sport': None},
-         {'title': 'Morning workout',
-          'distance': 10}),
-        # no title, sport given, we use the sport too in the automatically
-        # generated title
-        ({'title': None, 'sport': 'cycling'},
-         {'title': 'Morning cycling workout',
-          'distance': 10}),
-        # title given, no sport, we use the provided title
-        ({'title': 'Example workout', 'sport': None},
-         {'title': 'Example workout',
-          'distance': 10}),
-        # title given, sport too, we use the provided title
-        ({'title': 'Example workout', 'sport': 'cycling'},
-         {'title': 'Example workout',
-          'distance': 10}),
-    ]
-
-    @pytest.mark.parametrize(('params', 'expected'), add_workout_params)
-    def test_add_workout_manually_post_valid(self, params, expected,
-                                             valid_post_request):
+    def test_add_workout_manually_post_valid(self, valid_post_request):
         """
         POST request to add a workout manually, providing the needed data
         """
         request = valid_post_request
-        if params['title'] is not None:
-            request.POST['title'] = params['title']
-        if params['sport'] is not None:
-            request.POST['sport'] = params['sport']
         user = request.root['john']
         assert len(user.workouts()) == 1
@@ -167,7 +137,4 @@
         assert response.location.endswith('/2/')
         assert len(user.workouts()) == 2
-        assert user['2'].title == expected['title']
-        assert isinstance(user['2'].distance, Decimal)
-        assert user['2'].distance == Decimal(expected['distance'])
 
     def test_add_workout_get(self, dummy_request):
@@ -182,5 +149,4 @@
         assert len(response['form'].form.errors) == 0
         assert isinstance(response['form'].form.schema, UploadedWorkoutSchema)
-        assert response['duplicate'] is None
 
     def test_add_workout_post_invalid(self, dummy_request):
@@ -197,24 +163,4 @@
         # Only one required field in this case, the tracking file
         assert len(response['form'].form.errors) == 1
-        assert response['duplicate'] is None
-
-    def test_add_workout_post_invalid_bytes(self, dummy_request):
-        """
-        POST request to add a workout, without uploading a tracking file,
-        which sends an empty bytes object (b'')
-        """
-        request = dummy_request
-        user = request.root['john']
-        request.method = 'POST'
-        request.POST = MultiDict({
-            'tracking_file': b'',
-            'submit': True,
-            })
-        assert len(request.root['john'].workouts()) == 1
-        response = workout_views.add_workout(user, request)
-        assert 'form' in response
-        # Only one required field in this case, the tracking file
-        assert len(response['form'].form.errors) == 1
-        assert response['duplicate'] is None
 
     @pytest.mark.parametrize('filename', gpx_filenames)
@@ -239,55 +185,4 @@
         self.close_uploaded_file(uploaded_file)
 
-    def test_add_workout_post_duplicate(self, dummy_request):
-        """
-        POST request, first add a workout uploading one of the sample
-        tracking files, then try to upload it again.
-        """
-        # first, upload the workout
-        filename = self.gpx_filenames[0]
-        request = dummy_request
-        uploaded_file = self.open_uploaded_file(filename)
-        filestorage = self.create_filestorage(uploaded_file)
-        user = request.root['john']
-        request.method = 'POST'
-        request.POST = MultiDict({
-            'tracking_file': filestorage,
-            'submit': True,
-            })
-        assert len(request.root['john'].workouts()) == 1
-        response = workout_views.add_workout(user, request)
-        assert isinstance(response, HTTPFound)
-        assert response.location.endswith('/2/')
-        assert len(request.root['john'].workouts()) == 2
-        self.close_uploaded_file(uploaded_file)
-        # now, try to upload it again
-        uploaded_file = self.open_uploaded_file(filename)
-        filestorage = self.create_filestorage(uploaded_file)
-        user = request.root['john']
-        request.method = 'POST'
-        request.POST = MultiDict({
-            'tracking_file': filestorage,
-            'submit': True,
-            })
-        response = workout_views.add_workout(user, request)
-        assert response['duplicate'] == request.root['john']['2']
-        assert len(request.root['john'].workouts()) == 2
-        self.close_uploaded_file(uploaded_file)
-        # finally, override the duplicate prevention code and save it
-        uploaded_file = self.open_uploaded_file(filename)
-        filestorage = self.create_filestorage(uploaded_file)
-        user = request.root['john']
-        request.method = 'POST'
-        request.POST = MultiDict({
-            'tracking_file': filestorage,
-            'allow_duplicates': 'on',
-            'submit': True,
-            })
-        response = workout_views.add_workout(user, request)
-        assert isinstance(response, HTTPFound)
-        assert response.location.endswith('/3/')
-        assert len(request.root['john'].workouts()) == 3
-        self.close_uploaded_file(uploaded_file)
-
     def test_edit_workout_get(self, dummy_request):
         """
@@ -356,22 +251,4 @@
         request.method = 'POST'
         request.POST = MultiDict({'submit': True})
-        response = workout_views.update_workout_from_file(workout, request)
-        assert 'form' in response
-        # Only one required field in this case, the tracking file
-        assert len(response['form'].form.errors) == 1
-
-    def test_update_workout_from_file_post_invalid_bytes(self, dummy_request):
-        """
-        POST request to update a workout, without uploading a tracking file,
-        which sends an empty bytes object (b'')
-        """
-        request = dummy_request
-        user = request.root['john']
-        workout = user.workouts()[0]
-        request.method = 'POST'
-        request.POST = MultiDict({
-            'tracking_file': b'',
-            'submit': True,
-            })
         response = workout_views.update_workout_from_file(workout, request)
         assert 'form' in response
@@ -516,81 +393,2 @@
                 assert response.content_type == 'application/xml'
                 assert expected_body in response.body
-
-    def test_workout_map_no_gpx(self, dummy_request):
-        request = dummy_request
-        user = request.root['john']
-        workout = user.workouts()[0]
-        response = workout_views.workout_map(workout, request)
-        assert response == {'start_point': {}}
-
-    def test_workout_map(self, dummy_request):
-        request = dummy_request
-        user = request.root['john']
-        workout = user.workouts()[0]
-        # to ensure has_gpx returns true
-        workout.tracking_filetype = 'gpx'
-        gpx_file_path = os.path.join(
-            os.path.dirname(os.path.dirname(__file__)),
-            'fixtures/20131013.gpx')
-        with patch.object(workout, 'tracking_file') as tf:
-            with open(gpx_file_path, 'r') as gpx_file:
-                tf.open.return_value = BytesIO(gpx_file.read().encode('utf-8'))
-                response = workout_views.workout_map(workout, request)
-                assert response == {
-                    'start_point': {
-                        'elevation': None,
-                        'latitude': 37.108735040304566,
-                        'longitude': 25.472489344630546
-                    }
-                }
-
-    @patch('ow.views.workout.save_map_screenshot')
-    def test_workout_map_shot_generate_map(self, save_map, dummy_request):
-        """
-        Call the view that returns the url to the screenshot of a workout
-        tracking map, without a map being generated previously, the map is
-        generated using save_map_screenshot
-        """
-        def static_url(url):
-            return url
-        request = dummy_request
-        # mock static url to make testing this a bit easier
-        request.static_url = static_url
-        user = request.root['john']
-        workout = user.workouts()[0]
-        # we mock map_screenshot so the first access is None, triggering the
-        # save_map_screenshot call. The second access returns a string we can
-        # use with static_url for testing purposes
-        type(workout).map_screenshot = PropertyMock(
-            side_effect=[None, 'ow:static/maps/somemap.png'])
-        response = workout_views.workout_map_shot(workout, request)
-        save_map.assert_called_once_with(workout, request)
-        assert isinstance(response, Response)
-        assert response.content_type == 'application/json'
-        # the body is a valid json-encoded stream
-        obj = json.loads(response.body)
-        assert 'ow:static/maps/somemap.png' in obj['url']
-
-    @patch('ow.views.workout.save_map_screenshot')
-    def test_workout_map_shot_existing(self, save_map, dummy_request):
-        """
-        Call the view that returns the url to the screenshot of a workout
-        tracking map, with an existing map already there
-        """
-        def static_url(url):
-            return url
-        request = dummy_request
-        # mock static url to make testing this a bit easier
-        request.static_url = static_url
-        user = request.root['john']
-        workout = user.workouts()[0]
-        type(workout).map_screenshot = PropertyMock(
-            side_effect=['ow:static/maps/somemap.png',
-                         'ow:static/maps/somemap.png'])
-        response = workout_views.workout_map_shot(workout, request)
-        assert not save_map.called
-        assert isinstance(response, Response)
-        assert response.content_type == 'application/json'
-        # the body is a valid json-encoded stream
-        obj = json.loads(response.body)
-        assert 'ow:static/maps/somemap.png' in obj['url']
