Example #1
0
 def test_within_month_interval(self):
     user = utils.generate_user()
     sessions = utils.generate_sessions_within(
         user.id, lambda: datetime.timedelta(days=random.randint(0, 30)))
     query_result = Session.query.last_month(user.id)
     self.assertEqual(sorted(sessions), sorted(query_result))
     self.assertEqual([], Session.query.last_month(-1))
Example #2
0
    def test_get_user_monthly_sessions(self):
        user = utils.generate_user()
        sessions = utils.generate_sessions_within(
            user.id, lambda: datetime.timedelta(days=random.randint(0, 30)))

        response = self.client.get(
            '/api/users/{id}/statistics/monthly'.format(id=user.id))

        json = jsonify({
            'id': user.id,
            'statistics': {
                'monthly': user.monthly_stats.to_json()
            }
        }).get_json()

        self.assertEqual(response.status_code, 200)
        self.assertEqual(json, response.json)