-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
squash UI for PanDDA 2.x run results
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.*") |