Skip to content

Commit d5d975e

Browse files
authored
in the delete method, add support for deleting Report objects (#85)
1 parent 65599ea commit d5d975e

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/ansys/dynamicreporting/core/adr_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def export_pdf(
239239
if self.service.serverobj is None: # pragma: no cover
240240
self.service.logger.error("No connection to any server")
241241
return ""
242-
try:
242+
try: # pragma: no cover
243243
if query is None:
244244
query = {}
245245
self.service.serverobj.export_report_as_pdf(

src/ansys/dynamicreporting/core/adr_service.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,10 +793,11 @@ def delete(self, items: list) -> None:
793793
----------
794794
items : list
795795
List of objects to delete. The objects can be of one of these types:
796-
``"Item"``, ``"Session"``, or ``Dataset``.
796+
``"Item"``, ``Report``, ``"Session"`` or ``Dataset``.
797797
798798
.. note:: Deleting a session or a dataset also deletes all items
799-
associated with the session or dataset.
799+
associated with the session or dataset. Deleting a Report also
800+
deletes all its children.
800801
801802
Examples
802803
--------
@@ -807,13 +808,21 @@ def delete(self, items: list) -> None:
807808
adr_service.connect(url='http://localhost:8020')
808809
all_items = adr_service.query(type='Item')
809810
adr_service.delete(all_items)
811+
my_report = adr_service.get_report(report_name='My Report')
812+
adr_service.delete([my_report])
810813
"""
811814
if type(items) is not list:
812815
self.logger.error("Error: passed argument is not a list")
813816
raise TypeError
814817
items_to_delete = [x.item for x in items if type(x) is Item]
818+
reports_to_delete = [x for x in items if type(x) is Report]
819+
if reports_to_delete:
820+
self.logger.warning(
821+
"Warning: Report deletion will result in deletion of " "all its children templates"
822+
)
823+
items_to_delete.extend([x.report for x in reports_to_delete])
815824
# Check the input
816-
not_items = [x for x in items if type(x) is not Item]
825+
not_items = [x for x in items if (type(x) is not Item) and (type(x) is not Report)]
817826
if not_items: # pragma: no cover
818827
session = [x for x in not_items if type(x) is report_objects.SessionREST]
819828
if session:

tests/test_service.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,23 @@ def test_delete_item(adr_service_query) -> bool:
286286
assert len(newly_items) == 0
287287

288288

289+
@pytest.mark.ado_test
290+
def test_delete_report(adr_service_query) -> bool:
291+
server = adr_service_query.serverobj
292+
old_reports = adr_service_query.get_list_reports()
293+
test_report_name = "To Delete"
294+
top_report = server.create_template(
295+
name=test_report_name, parent=None, report_type="Layout:panel"
296+
)
297+
top_report.params = '{"HTML": "Hello!!"}'
298+
server.put_objects(top_report)
299+
test_report = adr_service_query.get_report(test_report_name)
300+
adr_service_query.delete([test_report])
301+
new_reports = adr_service_query.get_list_reports()
302+
adr_service_query.stop()
303+
assert len(old_reports) == len(new_reports)
304+
305+
289306
def test_vis_report(adr_service_query) -> bool:
290307
success = False
291308
try:

0 commit comments

Comments
 (0)