Skip to content

Commit

Permalink
hen showing a historic report in combination with measurements at mu…
Browse files Browse the repository at this point in the history
…ltiple dates, Quality-time would use the latest report to decide which metrics to retrieve the measurements for, instead of the report at the date shown. Fixes #3722.
  • Loading branch information
fniessink committed Apr 20, 2022
1 parent b2dcc8c commit 0725bc7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
8 changes: 6 additions & 2 deletions components/server/src/external/database/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ def _get_change_key(change: Change) -> str:
return key


def metrics_of_subject(database: Database, subject_uuid: SubjectId) -> list[MetricId]:
def metrics_of_subject(database: Database, subject_uuid: SubjectId, max_iso_timestamp: str = "") -> list[MetricId]:
"""Return all metric uuid's for one subject, without the entities, except for the most recent one."""
report_filter: dict = {f"subjects.{subject_uuid}": DOES_EXIST, "last": True}
report_filter = {f"subjects.{subject_uuid}": DOES_EXIST}
if max_iso_timestamp and max_iso_timestamp < iso_timestamp():
report_filter["timestamp"] = {"$lt": max_iso_timestamp}
else:
report_filter["last"] = True
projection: dict = {"_id": False, f"subjects.{subject_uuid}.metrics": True}
report = database.reports.find_one(report_filter, projection=projection)
return list(report["subjects"][subject_uuid]["metrics"].keys())
Expand Down
9 changes: 5 additions & 4 deletions components/server/src/external/routes/subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,18 @@ def post_subject_attribute(subject_uuid: SubjectId, subject_attribute: str, data

@bottle.get("/api/v3/subject/<subject_uuid>/measurements", authentication_required=False)
def get_subject_measurements(subject_uuid: SubjectId, database: Database):
"""Return all measurements for the subjects within the last 28 weeks."""
metric_uuids: list[MetricId] = metrics_of_subject(database, subject_uuid)
"""Return all measurements for the subject within the last 28 weeks."""
date_time = report_date_time()
metric_uuids: list[MetricId] = metrics_of_subject(database, subject_uuid, date_time)

report_timestamp = datetime.fromisoformat(report_date_time()) if report_date_time() else datetime.now(timezone.utc)
report_timestamp = datetime.fromisoformat(date_time) if date_time else datetime.now(timezone.utc)
min_datetime = report_timestamp - timedelta(weeks=28)
min_iso_timestamp = min_datetime.isoformat()

return dict(
measurements=list(
measurements_by_metric(
database, *metric_uuids, min_iso_timestamp=min_iso_timestamp, max_iso_timestamp=report_date_time()
database, *metric_uuids, min_iso_timestamp=min_iso_timestamp, max_iso_timestamp=date_time
)
)
)
13 changes: 13 additions & 0 deletions components/server/tests/external/routes/test_subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ def test_get_subject_measurements(self):
dict(measurements=[dict(start="0"), dict(start="1")]), get_subject_measurements(SUBJECT_ID, self.database)
)

@patch("bottle.request")
def test_get_subject_measurements_with_time_travel(self, request):
"""Tests that the measurements for the requested metric are returned for past reports."""
request.query = dict(report_date="2022-04-19T23:59:59.000Z")
# Mock reports collection
self.database.reports.find_one.return_value = {"subjects": {SUBJECT_ID: {"metrics": {METRIC_ID: {}}}}}
# Mock measurements collection
self.database.measurements.find_one.return_value = dict(start="1")
self.database.measurements.find.return_value = [dict(start="0"), dict(start="1")]
self.assertEqual(
dict(measurements=[dict(start="0"), dict(start="1")]), get_subject_measurements(SUBJECT_ID, self.database)
)


@patch("bottle.request")
class PostSubjectAttributeTest(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletion docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

<!-- The line "## <square-bracket>Unreleased</square-bracket>" is replaced by the release/release.py script with the new release version and release date. -->

## v3.35.0-rc.6 - 2022-04-20
## [Unreleased]

### Fixed

- When using Axe CVS as source for the accessibility violations metric, the "nested-interactive" violation type would be ignored by *Quality-time*. Fixes [#3628](https://github.com/ICTU/quality-time/issues/3628).
- When using Gatling as source for the source version metric, the source version would not be found, when the version number was not present on the first line of the simulation.log. Fixes [#3661](https://github.com/ICTU/quality-time/issues/3661).
- The data model for SonarQube contained some rules, which no longer exist. These were kept for backwards compatibility but now cause the SonarQube web interface to "freeze". These rules are removed. Fixes [#3706](https://github.com/ICTU/quality-time/issues/3706).
- When measuring 'manual test duration', show an error if the manual test duration field name or id does not exist in Jira, instead of silently ignoring the issue and reporting zero minutes. Fixes [#3714](https://github.com/ICTU/quality-time/issues/3714).
- When showing a historic report in combination with measurements at multiple dates, *Quality-time* would use the latest report to decide which metrics to retrieve the measurements for, instead of the report at the date shown. Fixes [#3722](https://github.com/ICTU/quality-time/issues/3722).

### Changed

Expand Down

0 comments on commit 0725bc7

Please sign in to comment.