瀏覽代碼

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 <pingou@pingoured.fr>
Pierre-Yves Chibon 6 年之前
父節點
當前提交
a8e4e9f5d1
共有 3 個文件被更改,包括 4 次插入11 次删除
  1. 1 4
      pagure/api/user.py
  2. 2 0
      pagure/templates/_render_repo.html
  3. 1 7
      tests/test_pagure_flask_api_user.py

+ 1 - 4
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

+ 2 - 0
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());

+ 1 - 7
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):