def _fetch(self, version, project, freqmode): start_time = get_args.get_datetime('start_time') end_time = get_args.get_datetime('end_time') limit = get_args.get_int('limit') or DEFAULT_LIMIT offset = get_args.get_int('offset') or DEFAULT_OFFSET if start_time and end_time and start_time > end_time: abort(400) param = { 'start_time': start_time, 'end_time': end_time, 'comment': get_args.get_string('comment')} db = level2db.Level2DB(project) scans = list( db.get_failed_scans(freqmode, offset=offset, limit=limit, **param)) for scan in scans: scan['URLS'] = get_scan_urls( version, project, freqmode, scan['ScanID']) scan['Error'] = scan.pop('Comments')[0] scan['Date'] = time_util.stw2datetime( scan['ScanID']).date().isoformat() count = db.count_failed_scans(freqmode, **param) data = { 'scans': scans, 'count': count, } headers = { 'Link': make_rfc5988_pagination_header( offset, limit, count, self._get_endpoint(), version=version, project=project, freqmode=freqmode, **param ), } return data, HTTPStatus.OK, headers
def _get_v5(self, version, freqmode, scanno, species): try: backend = FREQMODE_TO_BACKEND[freqmode] except KeyError: abort(404) # TODO: Not always correct date? date = time_util.stw2datetime(scanno).strftime('%Y-%m-%d') return self._get_v4(version, species, date, backend, freqmode, scanno)
def test_stw2datetime(self, stw, expect): date = time_util.stw2datetime(stw) assert ( (date - expect).total_seconds() == pytest.approx(0, abs=1e2) )