Skip to content

Commit

Permalink
fix ProjectZoneView ui test issues (#1732)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Aug 2, 2023
1 parent 3982feb commit 372537c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 66 deletions.
2 changes: 2 additions & 0 deletions landingzones/static/landingzones/js/landingzones.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var isSuperuser = false;
Zone status updating function
*****************************/
var updateZoneStatus = function() {
window.zoneStatusUpdated = false;
var zoneUuids = [];

$('.sodar-lz-zone-tr-existing').each(function() {
Expand Down Expand Up @@ -114,6 +115,7 @@ var updateZoneStatus = function() {
}
}
});
window.zoneStatusUpdated = true;
});
};

Expand Down
1 change: 1 addition & 0 deletions landingzones/templates/landingzones/project_zones.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ <h3><i class="iconify" data-icon="mdi:briefcase-upload"></i> Landing Zones</h3>

<!-- Settings for Javascript -->
<script type="text/javascript">
window.zoneStatusUpdated = false;
window.statusInterval = {{ zone_status_interval }} * 1000;
window.irodsShowChecksumCol = true;
var zoneStatusUrl = "{% url 'landingzones:ajax_status' project=project.sodar_uuid %}";
Expand Down
143 changes: 77 additions & 66 deletions landingzones/tests/test_ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""UI tests for the landingzones app"""

import time

from django.test import override_settings
from django.urls import reverse

Expand Down Expand Up @@ -38,7 +40,7 @@ def _setup_investigation(self):
self.study = self.investigation.studies.first()
self.assay = self.study.assays.first()

def assert_element(self, by, element, expected=True):
def _assert_element(self, by, element, expected=True):
"""Assert element existence for an already logged in user"""
# TODO: Add this into TestUIBase (see bihealth/sodar-core#1104)
if expected:
Expand All @@ -47,13 +49,24 @@ def assert_element(self, by, element, expected=True):
with self.assertRaises(NoSuchElementException):
self.selenium.find_element(by, element)

def assert_btn_enabled(self, element, expected=True):
def _assert_btn_enabled(self, element, expected=True):
"""Assert button is enabled"""
if expected:
self.assertNotIn('disabled', element.get_attribute('class'))
else:
self.assertIn('disabled', element.get_attribute('class'))

def _wait_for_status_update(self):
"""Wait for JQuery landing zone status updates to finish"""
max_retries = 5
retry = 0
while (
not self.selenium.execute_script('return window.zoneStatusUpdated')
and retry < max_retries
):
time.sleep(0.5)
retry += 1

def setUp(self):
super().setUp()
# Users with access to landing zones
Expand All @@ -74,38 +87,38 @@ def test_render_no_sheets(self):
"""Test ProjectZoneView rendering with no sheets"""
# NOTE: Only testing with owner as this doesn't depend on user
self.login_and_redirect(self.user_owner, self.url)
self.assert_element(By.ID, 'sodar-lz-alert-archive', False)
self.assert_element(By.ID, 'sodar-lz-alert-disable', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-sheets', True)
self.assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self.assert_element(By.ID, 'sodar-lz-zone-list-own', False)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', False)
self._assert_element(By.ID, 'sodar-lz-alert-archive', False)
self._assert_element(By.ID, 'sodar-lz-alert-disable', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-sheets', True)
self._assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)

def test_render_no_colls(self):
"""Test ProjectZoneView with investigation but no colls"""
self._setup_investigation()
self.assertIsNotNone(self.investigation)
self.login_and_redirect(self.user_owner, self.url)
self.assert_element(By.ID, 'sodar-lz-alert-disable', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-colls', True)
self.assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self.assert_element(By.ID, 'sodar-lz-zone-list-own', False)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', False)
self._assert_element(By.ID, 'sodar-lz-alert-disable', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-colls', True)
self._assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)

def test_render_no_zones(self):
"""Test ProjectZoneView with iRODS enabled but no zones"""
self._setup_investigation()
self.investigation.irods_status = True
self.investigation.save()
self.login_and_redirect(self.user_owner, self.url)
self.assert_element(By.ID, 'sodar-lz-alert-disable', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-zones', True)
self.assert_element(By.ID, 'sodar-lz-zone-list-own', False)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', False)
self._assert_element(By.ID, 'sodar-lz-alert-disable', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-zones', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)

@override_settings(LANDINGZONES_DISABLE_FOR_USERS=True)
def test_render_disable(self):
Expand All @@ -114,12 +127,12 @@ def test_render_disable(self):
self.investigation.irods_status = True
self.investigation.save()
self.login_and_redirect(self.user_owner, self.url)
self.assert_element(By.ID, 'sodar-lz-alert-disable', True)
self.assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self.assert_element(By.ID, 'sodar-lz-zone-list-own', False)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', False)
self._assert_element(By.ID, 'sodar-lz-alert-disable', True)
self._assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)

@override_settings(LANDINGZONES_DISABLE_FOR_USERS=True)
def test_render_disable_superuser(self):
Expand All @@ -131,12 +144,12 @@ def test_render_disable_superuser(self):
'superuser_zone', self.project, self.superuser, self.assay
)
self.login_and_redirect(self.superuser, self.url)
self.assert_element(By.ID, 'sodar-lz-alert-disable', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self.assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', False)
self._assert_element(By.ID, 'sodar-lz-alert-disable', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)

def test_render_own_zone(self):
"""Test ProjectZoneView as contributor with own zone"""
Expand All @@ -147,12 +160,12 @@ def test_render_own_zone(self):
'contrib_zone', self.project, self.user_contributor, self.assay
)
self.login_and_redirect(self.user_contributor, self.url)
self.assert_element(By.ID, 'sodar-lz-alert-disable', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self.assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self.assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', False)
self._assert_element(By.ID, 'sodar-lz-alert-disable', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-sheets', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-colls', False)
self._assert_element(By.ID, 'sodar-lz-alert-no-zones', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)
zones = self.selenium.find_elements(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)
Expand All @@ -172,8 +185,8 @@ def test_render_other_zone(self):
)
self.login_and_redirect(self.user_owner, self.url)
# NOTE: Element for own zones is visible while table is empty
self.assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', True)
zones = self.selenium.find_elements(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)
Expand All @@ -195,8 +208,8 @@ def test_render_both_zones_contrib(self):
'contrib_zone', self.project, self.user_contributor, self.assay
)
self.login_and_redirect(self.user_contributor, self.url)
self.assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', False)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', False)
zones = self.selenium.find_elements(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)
Expand All @@ -218,8 +231,8 @@ def test_render_both_zones_owner(self):
'contrib_zone', self.project, self.user_contributor, self.assay
)
self.login_and_redirect(self.user_owner, self.url)
self.assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self.assert_element(By.ID, 'sodar-lz-zone-list-other', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-own', True)
self._assert_element(By.ID, 'sodar-lz-zone-list-other', True)
zones = self.selenium.find_elements(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)
Expand All @@ -232,7 +245,7 @@ def test_render_both_zones_owner(self):
zones[1].get_attribute('data-zone-uuid'),
str(contrib_zone.sodar_uuid),
)
self.assert_element(By.CLASS_NAME, 'sodar-lz-zone-warn-access', False)
self._assert_element(By.CLASS_NAME, 'sodar-lz-zone-warn-access', False)

def test_render_other_user_guest_access(self):
"""Test ProjectZoneView with guest access for other user"""
Expand All @@ -253,7 +266,7 @@ def test_render_other_user_guest_access(self):
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)
self.assertEqual(len(zones), 2)
self.assert_element(By.CLASS_NAME, 'sodar-lz-zone-warn-access', True)
self._assert_element(By.CLASS_NAME, 'sodar-lz-zone-warn-access', True)

def test_render_other_user_no_access(self):
"""Test ProjectZoneView with no project access for other user"""
Expand All @@ -273,7 +286,7 @@ def test_render_other_user_no_access(self):
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)
self.assertEqual(len(zones), 2)
self.assert_element(By.CLASS_NAME, 'sodar-lz-zone-warn-access', True)
self._assert_element(By.CLASS_NAME, 'sodar-lz-zone-warn-access', True)

def test_zone_buttons(self):
"""Test ProjectZoneView zone buttons"""
Expand All @@ -284,22 +297,23 @@ def test_zone_buttons(self):
'contrib_zone', self.project, self.user_contributor, self.assay
)
self.login_and_redirect(self.user_contributor, self.url)
self._wait_for_status_update()
zone = self.selenium.find_elements(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)[0]
self.assert_btn_enabled(
self._assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-validate'),
True,
)
self.assert_btn_enabled(
self._assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-move'),
True,
)
self.assert_btn_enabled(
self._assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-copy'),
True,
)
self.assert_btn_enabled(
self._assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-delete'),
True,
)
Expand All @@ -314,22 +328,23 @@ def test_zone_buttons_archive(self):
)
self.project.set_archive()
self.login_and_redirect(self.user_contributor, self.url)
self._wait_for_status_update()
zone = self.selenium.find_elements(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)[0]
self.assert_btn_enabled(
self._assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-validate'),
False,
)
self.assert_btn_enabled(
self._assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-move'),
False,
)
self.assert_btn_enabled(
self._assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-copy'),
True,
)
self.assert_btn_enabled(
self._assert_btn_enabled(
zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-btn-delete'),
True,
)
Expand All @@ -339,22 +354,18 @@ def test_zone_locked_buttons_superuser(self):
self._setup_investigation()
self.investigation.irods_status = True
self.investigation.save()
zone = self.make_landing_zone(
self.make_landing_zone(
'contrib_zone', self.project, self.user_contributor, self.assay
)
# Set zone status to CREATING
zone.status = 'CREATING'
self.login_and_redirect(self.superuser, self.url)
self._wait_for_status_update()
zone = self.selenium.find_elements(
By.CLASS_NAME, 'sodar-lz-zone-tr-existing'
)[0]
dropdown_div = zone.find_element(By.CLASS_NAME, 'sodar-lz-zone-buttons')
try:
attr = dropdown_div.find_element(
By.CLASS_NAME, 'sodar-list-dropdown'
).get_attribute('disabled')
except AssertionError:
attr = None
attr = dropdown_div.find_element(
By.CLASS_NAME, 'sodar-list-dropdown'
).get_attribute('disabled')
self.assertIsNone(attr)
self.assertNotIn(
'text-muted',
Expand All @@ -375,6 +386,6 @@ def test_zone_locked_buttons_superuser(self):
'sodar-lz-zone-btn-delete',
]
for class_name in class_names:
self.assert_btn_enabled(
self._assert_btn_enabled(
zone.find_element(By.CLASS_NAME, class_name), True
)

0 comments on commit 372537c

Please sign in to comment.