Skip to content

Commit

Permalink
squash UI for PanDDA 2.x run results
Browse files Browse the repository at this point in the history
  • Loading branch information
elmjag committed Mar 11, 2024
1 parent ef692a8 commit e755177
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions tests/test_views_pandda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from typing import Optional
from pathlib import Path
from projects.database import db_session
from fragview.tools import Tool
from tests.utils import ViewTesterMixin, ProjectTestCase


def _make_combo_dir(
pandda_dir: Path, proc: Tool, refine: Tool, results_json: Optional[str] = "{}"
):
pandda_dir.mkdir(exist_ok=True)
combo_dir = Path(pandda_dir, f"{proc.get_name()}-{refine.get_name()}")
combo_dir.mkdir()

if results_json is not None:
file = Path(combo_dir, "result", "results.json")
file.parent.mkdir()
file.write_text(results_json)


class TestResultsView(ViewTesterMixin, ProjectTestCase):
"""
test /pandda/results/ view
"""

def setUp(self):
super().setUp()
self.setup_client(self.proposals)

def create_pandda_results(self):
pandda_dir = self.project.pandda_dir

_make_combo_dir(pandda_dir, Tool.AUTOPROC, Tool.DIMPLE)
_make_combo_dir(pandda_dir, Tool.XDS, Tool.DIMPLE)

# 'failed' pandda run
_make_combo_dir(pandda_dir, Tool.EDNA, Tool.DIMPLE, results_json=None)

# random file in the pandda directory
Path(pandda_dir, "some_file").touch()

@db_session
def test_no_results(self):
resp = self.client.get("/pandda/results/")
self.assert_response(resp, 200, "ok")

# check that correct template was rendered
self.assert_contains_template(resp, "pandda_results.html")
# the results combo should be empty
self.assertListEqual(resp.context["result_combos"], [])

@db_session
def test_got_results(self):
self.create_pandda_results()

resp = self.client.get("/pandda/results/")
self.assert_response(resp, 200, "ok")

# check that correct template was rendered
self.assert_contains_template(resp, "pandda_results.html")

result_combos = {f"{t.ui_label}" for t in resp.context["result_combos"]}
self.assertSetEqual(result_combos, {"autoPROC - DIMPLE", "XIA2/XDS - DIMPLE"})


class TestEventsView(ViewTesterMixin, ProjectTestCase):
def setUp(self):
super().setUp()
self.setup_client(self.proposals)

def test_no_pandda_dir(self):
resp = self.client.get("/pandda/events/edna/dimple")
self.assert_response(resp, 500, "Error reading data.*")

def test_unparsable_result_json(self):
_make_combo_dir(
self.project.pandda_dir, Tool.XDS, Tool.DIMPLE, "not-proper-json"
)
resp = self.client.get("/pandda/events/xds/dimple")
self.assert_response(resp, 500, "Error parsing.*")

def test_invalid_shema_result_json(self):
_make_combo_dir(self.project.pandda_dir, Tool.XDS, Tool.DIMPLE, '{"foo": 1}')
resp = self.client.get("/pandda/events/xds/dimple")
self.assert_response(resp, 500, "Unexpected json schema.*")

0 comments on commit e755177

Please sign in to comment.