Beispiel #1
0
 def test_normalize_date_range(self):
     """Test dates normalization."""
     self.assertEqual(
         helpers.normalize_date_range('2019-01-01', '2019-01-03'),
         ('2019-01-01', '2019-01-04'))
     self.assertEqual(
         helpers.normalize_date_range('not_date', '2019-01-03'),
         None)
     self.assertEqual(
         helpers.normalize_date_range('2019-01-01', '2019-01-01'),
         ('2019-01-01', '2019-01-02'))
 def needsdiagnosis_from_db():
     """Test route that queries database to serve data to client."""
     if is_valid_args(request.args):
         date_pair = normalize_date_range(request.args.get('from'),
                                          request.args.get('to'))
         needsdiagnosis_data = IssuesCount.query.filter_by(
             milestone='needsdiagnosis').filter(
                 IssuesCount.timestamp.between(date_pair[0],
                                               date_pair[1])).all()
         timeline = []
         for item in needsdiagnosis_data:
             hourly_count = dict(timestamp=item.timestamp.isoformat() + 'Z',
                                 count=item.count)
             timeline.append(hourly_count)
         response_object = {
             'about': 'Hourly NeedsDiagnosis issues count',
             'date_format': 'w3c',
             'timeline': timeline
         }
         response = Response(response=json.dumps(response_object),
                             status=200,
                             mimetype='application/json')
     else:
         response = Response(status=400)
     response.headers.add('Access-Control-Allow-Origin', '*')
     response.headers.add('Access-Control-Allow-Credentials', 'true')
     response.headers.add('Vary', 'Origin')
     return response
Beispiel #3
0
def issues_count_data(category):
    """Route for issues count."""
    if not is_valid_category(category):
        abort(404)
    if not request.args:
        abort(404)
    if not is_valid_args(request.args):
        abort(404)
    # Extract the dates
    from_date = request.args.get("from")
    to_date = request.args.get("to")
    start, end = normalize_date_range(from_date, to_date)
    # Grab the data
    timeline = get_timeline_data(category, start, end)
    # Prepare the response
    about = "Hourly {category} issues count".format(category=category)
    response_object = {
        "about": about,
        "date_format": "w3c",
        "timeline": timeline,
    }
    response = Response(
        response=json.dumps(response_object),
        status=200,
        mimetype="application/json",
    )
    response.headers.add("Access-Control-Allow-Origin", "*")
    response.headers.add("Access-Control-Allow-Credentials", "true")
    response.headers.add("Vary", "Origin")
    return response
Beispiel #4
0
def weekly_reports_data():
    """Route for weekly bug reports."""
    if not request.args:
        abort(404)
    if not is_valid_args(request.args):
        abort(404)
    # Extract the dates
    from_date = request.args.get("from")
    to_date = request.args.get("to")
    # Adding the extra day for weekly reports isn't necessary, but won't hurt
    start, end = normalize_date_range(from_date, to_date)
    # Fetch the data
    timeline = get_weekly_data(from_date, to_date)
    # Prepare the response
    response_object = {
        "about": "Weekly Count of New Issues Reported",
        "numbering_of_weeks": "ISO calendar",
        "timeline": timeline,
    }
    response = Response(
        response=json.dumps(response_object),
        status=200,
        mimetype="application/json",
    )
    response.headers.add("Access-Control-Allow-Origin", "*")
    response.headers.add("Access-Control-Allow-Credentials", "true")
    response.headers.add("Vary", "Origin")
    return response