diff options
-rw-r--r-- | .gitlab-ci.yml | 28 | ||||
-rw-r--r-- | MANIFEST.in | 2 | ||||
-rw-r--r-- | fietsboek/models/track.py | 1 | ||||
-rw-r--r-- | fietsboek/models/user.py | 1 | ||||
-rw-r--r-- | fietsboek/routes.py | 2 | ||||
-rw-r--r-- | fietsboek/scripts/fietsctl.py | 1 | ||||
-rw-r--r-- | fietsboek/summaries.py | 3 | ||||
-rw-r--r-- | fietsboek/util.py | 12 | ||||
-rw-r--r-- | fietsboek/views/default.py | 7 | ||||
-rw-r--r-- | fietsboek/views/detail.py | 1 | ||||
-rw-r--r-- | fietsboek/views/profile.py | 1 | ||||
-rw-r--r-- | fietsboek/views/upload.py | 3 | ||||
-rw-r--r-- | tests/unit/test_util.py | 1 | ||||
-rw-r--r-- | tox.ini | 36 |
14 files changed, 78 insertions, 21 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..781f772 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,28 @@ +image: python:latest + +# Change pip's cache directory to be inside the project directory since we can +# only cache local items. +variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + +# Pip's cache doesn't store the python packages +# https://pip.pypa.io/en/stable/topics/caching/ +# +# If you want to also cache the installed packages, you have to install +# them in a virtualenv and cache it as well. +cache: + paths: + - .cache/pip + - .tox + +before_script: + - python --version # For debugging + - pip install tox + +test: + script: + - tox -e python + +lint: + script: + - tox -e pylint,flake8 diff --git a/MANIFEST.in b/MANIFEST.in index 38898e6..ad17997 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include *.txt *.ini *.cfg *.rst +include *.txt *.ini *.cfg *.rst *.md recursive-include fietsboek *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml *.jinja2 recursive-include fietsboek/static * recursive-include fietsboek/locale *.pot *.po *.mo *.html diff --git a/fietsboek/models/track.py b/fietsboek/models/track.py index 1b1c38a..95344d9 100644 --- a/fietsboek/models/track.py +++ b/fietsboek/models/track.py @@ -121,6 +121,7 @@ track_badge_assoc = Table( # as some of them store timestamps as UTC time. The problem of finding some # local timestamp is delegated to util.guess_gpx_timestamp(). + class Track(Base): """A :class:`Track` represents a single GPX track. diff --git a/fietsboek/models/user.py b/fietsboek/models/user.py index 84aa4d9..fa6bd7f 100644 --- a/fietsboek/models/user.py +++ b/fietsboek/models/user.py @@ -107,7 +107,6 @@ class User(Base): friends_2 = relationship('User', secondary='friends_assoc', back_populates='friends_1', foreign_keys=[friends_assoc.c.user_2_id]) - @classmethod def query_by_email(cls, email): """Returns a query that can be used to query a user by its email. diff --git a/fietsboek/routes.py b/fietsboek/routes.py index 9b17173..a28f926 100644 --- a/fietsboek/routes.py +++ b/fietsboek/routes.py @@ -1,4 +1,6 @@ """Route definitions for the main Fietsboek application.""" + + def includeme(config): # pylint: disable=missing-function-docstring config.add_static_view('static', 'static', cache_max_age=3600) diff --git a/fietsboek/scripts/fietsctl.py b/fietsboek/scripts/fietsctl.py index 1c6a8c0..e8f7b3f 100644 --- a/fietsboek/scripts/fietsctl.py +++ b/fietsboek/scripts/fietsctl.py @@ -136,7 +136,6 @@ def cmd_passwd(env, args): return EXIT_OKAY - def parse_args(argv): """Parse the given args. diff --git a/fietsboek/summaries.py b/fietsboek/summaries.py index efaab42..9d4c0aa 100644 --- a/fietsboek/summaries.py +++ b/fietsboek/summaries.py @@ -1,4 +1,6 @@ """Module for a yearly/monthly track summary.""" + + class Summary: """A summary of a user's tracks. @@ -42,6 +44,7 @@ class Summary: """ return sum(track.length for track in self.all_tracks()) + class YearSummary: """A summary over a single year. diff --git a/fietsboek/util.py b/fietsboek/util.py index f62a0d5..1014c87 100644 --- a/fietsboek/util.py +++ b/fietsboek/util.py @@ -99,7 +99,7 @@ def guess_gpx_timezone(gpx): # that some devices save their times in UTC, so we need to look for a # timestamp different than UTC. for time in times: - if time.tzinfo and time.tzinfo.utcoffset(time): + if time.tzinfo and time.tzinfo.utcoffset(time): return time.tzinfo # Next, we look if there's a "localTime" extension on the track, so we can @@ -125,16 +125,6 @@ def guess_gpx_timezone(gpx): offset = round_timedelta_to_multiple(offset, datetime.timedelta(minutes=15)) return datetime.timezone(offset) - # Special case for MyTourbook exports, which have a 'mt:TourStartTime' extension - if gpx.time: - for extension in gpx.metadata_extensions: - if extension.tag.lower() == '{net.tourbook/1}tourstarttime': - local_time = datetime.datetime.fromtimestamp(int(extension.text) // 1000) - time = gpx.time.astimezone(datetime.timezone.utc).replace(tzinfo=None) - offset = local_time - time - offset = round_timedelta_to_multiple(offset, datetime.timedelta(minutes=15)) - return datetime.timezone(offset) - # If all else fails, we assume that we are UTC+00:00 return datetime.timezone.utc diff --git a/fietsboek/views/default.py b/fietsboek/views/default.py index 042e48c..e7a1cb0 100644 --- a/fietsboek/views/default.py +++ b/fietsboek/views/default.py @@ -134,10 +134,9 @@ def do_password_reset(request): request.localizer.translate(_("page.password_reset.email.subject")), ) mail.set_content( - request - .localizer - .translate(_("page.password_reset.email.body")) - .format(request.route_url('use-token', uuid=token.uuid)) + request.localizer + .translate(_("page.password_reset.email.body")) + .format(request.route_url('use-token', uuid=token.uuid)) ) email.send_message(request.registry.settings, mail) diff --git a/fietsboek/views/detail.py b/fietsboek/views/detail.py index 4990953..a15b29d 100644 --- a/fietsboek/views/detail.py +++ b/fietsboek/views/detail.py @@ -30,6 +30,7 @@ def details(request): 'description': description, } + @view_config(route_name='gpx', http_cache=3600, permission='track.view') def gpx(request): """Returns the actual GPX data from the stored track. diff --git a/fietsboek/views/profile.py b/fietsboek/views/profile.py index ad481db..f4acd3d 100644 --- a/fietsboek/views/profile.py +++ b/fietsboek/views/profile.py @@ -58,7 +58,6 @@ def do_change_profile(request): return HTTPFound(request.route_url('profile')) - @view_config(route_name='add-friend', permission='user', request_method='POST') def do_add_friend(request): """Sends a friend request. diff --git a/fietsboek/views/upload.py b/fietsboek/views/upload.py index 7a1059b..979291e 100644 --- a/fietsboek/views/upload.py +++ b/fietsboek/views/upload.py @@ -151,7 +151,7 @@ def do_finish_upload(request): track = models.Track( owner=request.identity, title=request.params["title"], - visibility = Visibility[request.params["visibility"]], + visibility=Visibility[request.params["visibility"]], description=request.params["description"], badges=badges, link_secret=util.random_alphanum_string(), @@ -173,6 +173,7 @@ def do_finish_upload(request): return HTTPFound(request.route_url('details', track_id=track.id)) + @view_config(route_name='cancel-upload', permission='upload.finish', request_method="POST") def cancel_upload(request): """Cancels the upload and clears the temporary data. diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py index 13f4bfe..debf229 100644 --- a/tests/unit/test_util.py +++ b/tests/unit/test_util.py @@ -56,7 +56,6 @@ def test_round_timedelta_to_multiple(delta, multiple, expected): @pytest.mark.parametrize('gpx_file, offset', [ ("Teasi_1.gpx.gz", timedelta(hours=2)), - ("MyTourbook_1.gpx.gz", timedelta(hours=2)), ]) def test_guess_gpx_timezone(gpx_file, offset): parsed_gpx = gpxpy.parse(load_gpx_asset(gpx_file)) @@ -0,0 +1,36 @@ +[flake8] +max-line-length = 100 +exclude = fietsboek/alembic +per-file-ignores = + fietsboek/models/__init__.py:F401 + +[tox] +envlist = python,pylint,flake8 + +[testenv] +deps = pytest +extras = testing +passenv = + TERM +commands = + pytest {posargs} + +[testenv:pylint] +deps = pylint +usedevelop = true +commands = + pylint fietsboek + +[testenv:flake8] +deps = flake8 +usedevelop = true +commands = + flake8 fietsboek + +[testenv:sphinx] +deps = sphinx +usedevelop = true +allowlist_externals = make +changedir={toxinidir}{/}doc +commands = + make html |