From 3a730c1663fd6096f9abf285e79fb897908d339e Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 9 Dec 2019 17:31:07 +0100 Subject: [PATCH] Rest APi added for importing a complete report. (#818) --- components/server/src/routes/report.py | 2 +- components/server/tests/routes/test_report.py | 13 ++++++++++++- docs/CHANGELOG.md | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/components/server/src/routes/report.py b/components/server/src/routes/report.py index c068fdd1e0..1fc5077f76 100644 --- a/components/server/src/routes/report.py +++ b/components/server/src/routes/report.py @@ -334,7 +334,7 @@ def post_reports_attribute(reports_attribute: str, database: Database): @bottle.post("/api/v1/report/import") -def post_reports_attribute(database: Database): +def post_report_import(database: Database): """Set a reports overview attribute.""" value = dict(bottle.request.json) return import_json_report(database, value) diff --git a/components/server/tests/routes/test_report.py b/components/server/tests/routes/test_report.py index e1228776ff..d5b72847e3 100644 --- a/components/server/tests/routes/test_report.py +++ b/components/server/tests/routes/test_report.py @@ -9,7 +9,8 @@ from routes.report import ( delete_metric, delete_report, delete_source, delete_subject, export_report_as_pdf, get_metrics, get_reports, get_tag_report, post_metric_attribute, post_metric_new, post_new_subject, post_report_attribute, post_report_new, - post_reports_attribute, post_source_attribute, post_source_new, post_source_parameter, post_subject_attribute + post_reports_attribute, post_source_attribute, post_source_new, post_source_parameter, post_subject_attribute, + post_report_import ) from server_utilities.functions import iso_timestamp from server_utilities.type import MetricId, ReportId, SourceId, SubjectId @@ -715,6 +716,16 @@ def test_post_reports_attribute_layout(self, request): inserted = self.database.reports_overviews.insert.call_args_list[0][0][0] self.assertEqual("Jenny changed the layout of the reports overview.", inserted["delta"]["description"]) + @patch("bottle.request") + def test_post_report_import(self, request): + """Test that a report is imported correctly.""" + #self.database.reports_overviews.find_one.return_value = dict(_id="id", title="Reports") + request.json = dict(_id="id", title="QT", report_uuid="qt", subjects={}) + post_report_import(self.database) + inserted = self.database.reports.insert.call_args_list[0][0][0] + self.assertEqual("QT", inserted["title"]) + self.assertEqual("qt", inserted["report_uuid"]) + @patch("bottle.request") def test_get_tag_report(self, request): """Test that a tag report can be retrieved.""" diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 559cb2acf2..bf8cc9034e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - If you have a [Gravatar](https://gravatar.com), it will be shown next to your username after you log in. +- Rest APi added for importing a complete report. Closes [#818](https://github.com/ICTU/quality-time/issues/818). ### Changed