def test_is_valid_args(self): """Return True or False depending on the args.""" self.assertTrue(helpers.is_valid_args(ImmutableMultiDict( [('from', '2018-05-16'), ('to', '2018-05-18')]))) self.assertFalse(helpers.is_valid_args(ImmutableMultiDict([]))) self.assertFalse(helpers.is_valid_args(ImmutableMultiDict( [('bar', 'foo')]))) self.assertFalse(helpers.is_valid_args(ImmutableMultiDict( [('from', 'bar'), ('to', 'foo')])))
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
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
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
def weekly_reports_data(): """Secondhand pipeline for returning weekly JSON data.""" json_weekly_data = get_remote_data( 'http://laghee.pythonanywhere.com/tmp/weekly_issues') if is_valid_args(request.args): json_weekly_data = get_json_slice(json_weekly_data, request.args.get('from'), request.args.get('to')) response = Response(response=json_weekly_data, 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
def needsdiagnosis_data(): """Dumb pipeline for returning the JSON.""" # TODO: Change this to a local file. json_data = get_remote_data( 'http://www.la-grange.net/tmp/needsdiagnosis-timeline.json') if is_valid_args(request.args): json_data = get_json_slice(json_data, request.args.get('from'), request.args.get('to')) response = Response(response=json_data, 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
def sitewait_data(): """Dumb pipeline for returning the JSON.""" # TODO: Change this to a database query. json_data = get_remote_data( 'http://laghee.pythonanywhere.com/tmp/sitewait_timeline') if is_valid_args(request.args): json_data = get_json_slice(json_data, request.args.get('from'), request.args.get('to')) response = Response(response=json_data, 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