Changeset d6f8304 in OpenWorkouts-current for ow/tests/models/test_workout.py


Ignore:
Timestamp:
Feb 11, 2019, 6:55:55 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
02aee97
Parents:
93bbb89
Message:

(#52) - screenshots of the workouts maps were corrupted randomly.

Replaced our screenshot_map shell script that was calling chrome headless
directly with some python code running splinter + selenium webdriver.

Using chromedriver in such environment we can first visit the map site
for the given workout, then wait a bit for it to completely load, then
take the screenshot.

I've also removed all traces of screenshot_map from the code.

File:
1 edited

Legend:

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

    r93bbb89 rd6f8304  
    77import pytest
    88from pyramid.security import Allow, Everyone, Deny, ALL_PERMISSIONS
     9from pyramid.testing import DummyRequest
    910
    1011from ow.models.workout import Workout
     
    576577    def test_map_screenshot_no_gpx(self, sms, os, root):
    577578        workout = root['john']['1']
    578         assert workout.map_screenshot is None
     579        request = DummyRequest()
     580        assert workout.map_screenshot(request) is None
    579581        assert not os.path.abspath.called
    580582        assert not os.path.dirname.called
     
    602604
    603605        uid = str(root['john'].uid)
    604         assert workout.map_screenshot == 'ow:/static/maps/' + uid + '/1.png'
     606        request = DummyRequest()
     607        # dummyrequest can't resolve static assets without adding a lot
     608        # of boilerplate, no need for that here
     609        request.static_url = Mock()
     610        request.static_url.return_value = 'ow:/static/maps/' + uid + '/1.png'
     611        res = workout.map_screenshot(request)
     612        assert res == 'ow:/static/maps/' + uid + '/1.png'
    605613        assert os.path.abspath.called
    606614        assert os.path.dirname.called
    607         assert os.path.join.call_count == 2
     615        assert os.path.join.call_count == 3
    608616        assert os.path.exists.called
    609         sms.assert_called_once_with(workout)
     617        sms.assert_called_once_with(workout, request)
    610618
    611619    @patch('ow.models.workout.os')
     
    619627        os.path.join.side_effect = join
    620628        # This forces the "save screenshot" code NOT to be run
    621         os.path.exists.return_value = True
     629        os.path.eisxts.return_value = True
    622630
    623631        workout = root['john']['1']
     
    626634
    627635        uid = str(root['john'].uid)
    628         assert workout.map_screenshot == 'ow:/static/maps/' + uid + '/1.png'
     636        request = DummyRequest()
     637        # dummyrequest can't resolve static assets without adding a lot
     638        # of boilerplate, no need for that here
     639        request.static_url = Mock()
     640        request.static_url.return_value = 'ow:/static/maps/' + uid + '/1.png'
     641        res = workout.map_screenshot(request)
     642        assert res == 'ow:/static/maps/' + uid + '/1.png'
    629643        assert os.path.abspath.called
    630644        assert os.path.dirname.called
    631         assert os.path.join.call_count == 2
     645        assert os.path.join.call_count == 3
    632646        assert os.path.exists.called
    633647        assert not sms.called
Note: See TracChangeset for help on using the changeset viewer.