| |
@@ -468,6 +468,132 @@
|
| |
}
|
| |
self.assertEqual(data, exp)
|
| |
|
| |
+ @patch('pagure.lib.notify.send_email')
|
| |
+ def test_api_view_user_activity_timezone_negative(self, mockemail):
|
| |
+ """Test api_view_user_activity{_stats,_date} with a timezone
|
| |
+ 5 hours behind UTC. The activities will occur on 2018-02-15 in
|
| |
+ UTC, but on 2018-02-14 in local time.
|
| |
+ """
|
| |
+ tests.create_projects(self.session)
|
| |
+ repo = pagure.lib._get_project(self.session, 'test')
|
| |
+
|
| |
+ dateobj = datetime.datetime(2018, 2, 15, 3, 30)
|
| |
+ utcdate = '2018-02-15'
|
| |
+ localdate = '2018-02-14'
|
| |
+ # Create a single commit log
|
| |
+ log = model.PagureLog(
|
| |
+ user_id=1,
|
| |
+ user_email='foo@bar.com',
|
| |
+ project_id=1,
|
| |
+ log_type='committed',
|
| |
+ ref_id='githash',
|
| |
+ date=dateobj.date(),
|
| |
+ date_created=dateobj
|
| |
+ )
|
| |
+ self.session.add(log)
|
| |
+ self.session.commit()
|
| |
+
|
| |
+ # Retrieve the user's stats with no offset
|
| |
+ output = self.app.get('/api/0/user/pingou/activity/stats')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ data = json.loads(output.data)
|
| |
+ # date in output should be UTC date
|
| |
+ self.assertDictEqual(data, {utcdate: 1})
|
| |
+
|
| |
+ # Retrieve the user's stats with correct offset
|
| |
+ output = self.app.get('/api/0/user/pingou/activity/stats?offset=-300')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ data = json.loads(output.data)
|
| |
+ # date in output should be local date
|
| |
+ self.assertDictEqual(data, {localdate: 1})
|
| |
+
|
| |
+ # Retrieve the user's logs for 2018-02-15 with no offset
|
| |
+ output = self.app.get(
|
| |
+ '/api/0/user/pingou/activity/%s?grouped=1' % utcdate)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ data = json.loads(output.data)
|
| |
+ exp = {
|
| |
+ "activities": [
|
| |
+ {
|
| |
+ "description_mk": "<p>pingou committed on test#githash</p>"
|
| |
+ }
|
| |
+ ],
|
| |
+ "date": utcdate,
|
| |
+ }
|
| |
+ self.assertEqual(data, exp)
|
| |
+
|
| |
+ # Now retrieve the user's logs for 2018-02-14 with correct
|
| |
+ # offset applied
|
| |
+ output = self.app.get(
|
| |
+ '/api/0/user/pingou/activity/%s?grouped=1&offset=-300' % localdate)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ data = json.loads(output.data)
|
| |
+ exp['date'] = localdate
|
| |
+ self.assertEqual(data, exp)
|
| |
+
|
| |
+ @patch('pagure.lib.notify.send_email')
|
| |
+ def test_api_view_user_activity_timezone_positive(self, mockemail):
|
| |
+ """Test api_view_user_activity{_stats,_date} with a timezone
|
| |
+ 4 hours ahead of UTC. The activities will occur on 2018-02-15
|
| |
+ in UTC, but on 2018-02-16 in local time.
|
| |
+ """
|
| |
+ tests.create_projects(self.session)
|
| |
+ repo = pagure.lib._get_project(self.session, 'test')
|
| |
+
|
| |
+ dateobj = datetime.datetime(2018, 2, 15, 22, 30)
|
| |
+ utcdate = '2018-02-15'
|
| |
+ localdate = '2018-02-16'
|
| |
+ # Create a single commit log
|
| |
+ log = model.PagureLog(
|
| |
+ user_id=1,
|
| |
+ user_email='foo@bar.com',
|
| |
+ project_id=1,
|
| |
+ log_type='committed',
|
| |
+ ref_id='githash',
|
| |
+ date=dateobj.date(),
|
| |
+ date_created=dateobj
|
| |
+ )
|
| |
+ self.session.add(log)
|
| |
+ self.session.commit()
|
| |
+
|
| |
+ # Retrieve the user's stats with no offset
|
| |
+ output = self.app.get('/api/0/user/pingou/activity/stats')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ data = json.loads(output.data)
|
| |
+ # date in output should be UTC date
|
| |
+ self.assertDictEqual(data, {utcdate: 1})
|
| |
+
|
| |
+ # Retrieve the user's stats with correct offset
|
| |
+ output = self.app.get('/api/0/user/pingou/activity/stats?offset=240')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ data = json.loads(output.data)
|
| |
+ # date in output should be local date
|
| |
+ self.assertDictEqual(data, {localdate: 1})
|
| |
+
|
| |
+ # Retrieve the user's logs for 2018-02-15 with no offset
|
| |
+ output = self.app.get(
|
| |
+ '/api/0/user/pingou/activity/%s?grouped=1' % utcdate)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ data = json.loads(output.data)
|
| |
+ exp = {
|
| |
+ "activities": [
|
| |
+ {
|
| |
+ "description_mk": "<p>pingou committed on test#githash</p>"
|
| |
+ }
|
| |
+ ],
|
| |
+ "date": utcdate,
|
| |
+ }
|
| |
+ self.assertEqual(data, exp)
|
| |
+
|
| |
+ # Now retrieve the user's logs for 2018-02-16 with correct
|
| |
+ # offset applied
|
| |
+ output = self.app.get(
|
| |
+ '/api/0/user/pingou/activity/%s?grouped=1&offset=240' % localdate)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ data = json.loads(output.data)
|
| |
+ exp['date'] = localdate
|
| |
+ self.assertEqual(data, exp)
|
| |
+
|
| |
|
| |
class PagureFlaskApiUsertestrequests(tests.Modeltests):
|
| |
""" Tests for the user requests endpoints """
|
| |
As discussed in #1642, there is a problem with the user activity
log page in the web UI caused by a timezone mismatch. The
library used to generate the heatmap assumes any date / time you
feed it is in the browser timezone. Pagure ultimately feeds it
the 'date' value of PagureLog instances, converted to a Unix
timestamp. This timestamp reflects 00:00 on the date in question
in the UTC timezone. If the browser timezone is behind UTC, the
heatmap library treats the event as falling on the previous
day, because in the browser timezone, that precise time falls on
the previous day.
It would be relatively easy to 'fix' this if all we wanted to do
was have the heatmap reflect what date each event occurred on in
the UTC timezone, as the activity log currently does. However, I
don't think that's the best fix. I think the best behaviour here
is for both the heatmap and the activity log to be relative to
the browser timezone. As a Pagure user in a timezone several
hours behind UTC, if I make a commit in the late afternoon of
Wednesday, I'd expect the heatmap and the activity log to show
that commit as occuring on Wednesday, not Thursday.
So, this commit dumps the use of the 'date' value in this code,
and works with the 'date_created' value instead, which is a
precise UTC date and time (as opposed to just the date relative
to UTC). We allow a timezone offset to be passed to the relevant
methods, and figure out what date the events fell on if that
offset is applied, rather than just what date they fell on in
the UTC timezone. To facilitate this we add a custom method to
the database model,
date_offset
, which gives the date when anarbitrary offset (in minutes, positive or negative) is applied.
We tweak the relevant functions in pagure.lib to get all the
necessary data from the database, then use the
date_offset
method to adjust and refine the results before returning.
Fixes https://pagure.io/pagure/issue/1642