From a8e4e9f5d17a72f384191dc5567e95569d5ac945 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 20 2017 09:51:54 +0000 Subject: Fix the api_view_user_activity_stats to return the expected data In flask 0.11 quite some changes were made to flask.jsonify() changing its behavior and in this case breaking the calendar heatmap widget. This commit fixes this. While at it, highlight in the calendar heatmap today just to make it prettier. Let's not speak about the change to the tests here, not now, not ever... Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/api/user.py b/pagure/api/user.py index b07e602..8d522ba 100644 --- a/pagure/api/user.py +++ b/pagure/api/user.py @@ -225,10 +225,7 @@ def api_view_user_activity_stats(username): d = d.isoformat() return d - stats = [ - (format_date(d[0]), d[1]) - for d in stats - ] + stats = {format_date(d[0]): d[1] for d in stats} jsonout = flask.jsonify(stats) return jsonout diff --git a/pagure/templates/_render_repo.html b/pagure/templates/_render_repo.html index e726fba..5769b0b 100644 --- a/pagure/templates/_render_repo.html +++ b/pagure/templates/_render_repo.html @@ -314,6 +314,8 @@ data: "{{ url_for( 'api_ns.api_view_user_activity_stats', username=username, format='timestamp') }}", + dataType: "json", + highlight: "now", onClick: function(date, nb) { date = date.getFullYear() + '-' + padStr(date.getMonth() + 1) + '-' + padStr(date.getDate()); diff --git a/tests/test_pagure_flask_api_user.py b/tests/test_pagure_flask_api_user.py index a1c8868..a3c0f00 100644 --- a/tests/test_pagure_flask_api_user.py +++ b/tests/test_pagure_flask_api_user.py @@ -325,13 +325,7 @@ class PagureFlaskApiUSertests(tests.Modeltests): self.assertEqual(output.status_code, 200) data = json.loads(output.data) date = datetime.datetime.utcnow().date().strftime('%Y-%m-%d') - # There seems to be a difference in the JSON generated between - # flask-0.10.1 (F23) and 0.11.1 (jenkins) - self.assertTrue( - data == {date: 4} - or - data == [[date, 4]] - ) + self.assertDictEqual(data, {date: 4}) @patch('pagure.lib.notify.send_email') def test_api_view_user_activity_date(self, mockemail):