Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ansys/dynamicreporting/core/adr_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def export_pdf(
if self.service.serverobj is None: # pragma: no cover
self.service.logger.error("No connection to any server")
return ""
try:
try: # pragma: no cover
if query is None:
query = {}
self.service.serverobj.export_report_as_pdf(
Expand Down
15 changes: 12 additions & 3 deletions src/ansys/dynamicreporting/core/adr_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,10 +793,11 @@ def delete(self, items: list) -> None:
----------
items : list
List of objects to delete. The objects can be of one of these types:
``"Item"``, ``"Session"``, or ``Dataset``.
``"Item"``, ``Report``, ``"Session"`` or ``Dataset``.

.. note:: Deleting a session or a dataset also deletes all items
associated with the session or dataset.
associated with the session or dataset. Deleting a Report also
deletes all its children.

Examples
--------
Expand All @@ -807,13 +808,21 @@ def delete(self, items: list) -> None:
adr_service.connect(url='http://localhost:8020')
all_items = adr_service.query(type='Item')
adr_service.delete(all_items)
my_report = adr_service.get_report(report_name='My Report')
adr_service.delete([my_report])
"""
if type(items) is not list:
self.logger.error("Error: passed argument is not a list")
raise TypeError
items_to_delete = [x.item for x in items if type(x) is Item]
reports_to_delete = [x for x in items if type(x) is Report]
if reports_to_delete:
self.logger.warning(
"Warning: Report deletion will result in deletion of " "all its children templates"
)
items_to_delete.extend([x.report for x in reports_to_delete])
# Check the input
not_items = [x for x in items if type(x) is not Item]
not_items = [x for x in items if (type(x) is not Item) and (type(x) is not Report)]
if not_items: # pragma: no cover
session = [x for x in not_items if type(x) is report_objects.SessionREST]
if session:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,23 @@ def test_delete_item(adr_service_query) -> bool:
assert len(newly_items) == 0


@pytest.mark.ado_test
def test_delete_report(adr_service_query) -> bool:
server = adr_service_query.serverobj
old_reports = adr_service_query.get_list_reports()
test_report_name = "To Delete"
top_report = server.create_template(
name=test_report_name, parent=None, report_type="Layout:panel"
)
top_report.params = '{"HTML": "Hello!!"}'
server.put_objects(top_report)
test_report = adr_service_query.get_report(test_report_name)
adr_service_query.delete([test_report])
new_reports = adr_service_query.get_list_reports()
adr_service_query.stop()
assert len(old_reports) == len(new_reports)


def test_vis_report(adr_service_query) -> bool:
success = False
try:
Expand Down