mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-06-07 22:08:41 +02:00
test(bec-atlas-http-service): add tests for http service
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
|
||||
from qtpy.QtWidgets import QWidget
|
||||
|
||||
from bec_widgets.applications.views.admin_view.admin_widget import AdminWidget
|
||||
from bec_widgets.applications.views.view import ViewBase
|
||||
from bec_widgets.utils.error_popups import SafeSlot
|
||||
from bec_widgets.widgets.services.bec_atlas_admin_view.bec_atlas_admin_view import BECAtlasAdminView
|
||||
|
||||
|
||||
class AdminView(ViewBase):
|
||||
@@ -22,7 +22,7 @@ class AdminView(ViewBase):
|
||||
title: str | None = None,
|
||||
):
|
||||
super().__init__(parent=parent, content=content, id=id, title=title)
|
||||
self.admin_widget = AdminWidget(parent=self)
|
||||
self.admin_widget = BECAtlasAdminView(parent=self)
|
||||
self.set_content(self.admin_widget)
|
||||
|
||||
@SafeSlot()
|
||||
@@ -31,7 +31,6 @@ class AdminView(ViewBase):
|
||||
|
||||
Default implementation does nothing. Override in subclasses.
|
||||
"""
|
||||
self.admin_widget.on_enter()
|
||||
|
||||
@SafeSlot()
|
||||
def on_exit(self) -> None:
|
||||
@@ -39,4 +38,4 @@ class AdminView(ViewBase):
|
||||
|
||||
Default implementation does nothing. Override in subclasses.
|
||||
"""
|
||||
self.admin_widget.on_exit()
|
||||
self.admin_widget.logout()
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
"""Module to define a widget for the admin view."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from qtpy.QtWidgets import QVBoxLayout, QWidget
|
||||
|
||||
from bec_widgets.utils.bec_widget import BECWidget
|
||||
from bec_widgets.widgets.services.bec_atlas_admin_view.bec_atlas_admin_view import BECAtlasAdminView
|
||||
|
||||
|
||||
class AdminWidget(BECWidget, QWidget):
|
||||
"""Widget for admin view."""
|
||||
|
||||
RPC = False
|
||||
|
||||
def __init__(self, parent=None, client=None):
|
||||
super().__init__(parent=parent, client=client)
|
||||
# Overview widget
|
||||
layout = QVBoxLayout(self)
|
||||
self.admin_view_widget = BECAtlasAdminView(parent=self, client=self.client)
|
||||
layout.addWidget(self.admin_view_widget)
|
||||
|
||||
def on_enter(self) -> None:
|
||||
"""Called after the widget becomes visible."""
|
||||
|
||||
def on_exit(self) -> None:
|
||||
"""Called before the widget is hidden."""
|
||||
self.admin_view_widget.logout()
|
||||
|
||||
|
||||
# pylint: disable=ungrouped-imports
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
from bec_qthemes import apply_theme
|
||||
from qtpy.QtWidgets import QApplication
|
||||
|
||||
from bec_widgets.widgets.utility.visual.dark_mode_button.dark_mode_button import DarkModeButton
|
||||
|
||||
app = QApplication([])
|
||||
|
||||
apply_theme("dark")
|
||||
w = QWidget()
|
||||
l = QVBoxLayout(w)
|
||||
widget = AdminWidget(parent=w)
|
||||
dark_mode_button = DarkModeButton(parent=w)
|
||||
l.addWidget(dark_mode_button)
|
||||
l.addWidget(widget)
|
||||
w.show()
|
||||
app.exec()
|
||||
@@ -152,6 +152,9 @@ class BECAtlasHTTPService(QWidget):
|
||||
# Logout to invalidate session on server side
|
||||
self.logout()
|
||||
|
||||
# Stop the authentication timer
|
||||
self._auth_timer.stop()
|
||||
|
||||
# Delete all cookies related to the base URL
|
||||
for cookie in self.network_manager.cookieJar().cookiesForUrl(QUrl(self._base_url)):
|
||||
self.network_manager.cookieJar().deleteCookie(cookie)
|
||||
@@ -167,7 +170,7 @@ class BECAtlasHTTPService(QWidget):
|
||||
status = reply.attribute(QNetworkRequest.Attribute.HttpStatusCodeAttribute)
|
||||
raw_bytes = reply.readAll().data()
|
||||
request_url = reply.url().toString()
|
||||
headers = dict(reply.rawHeaderPairs())
|
||||
headers = dict([(i.data().decode(), j.data().decode()) for i, j in reply.rawHeaderPairs()])
|
||||
reply.deleteLater()
|
||||
|
||||
# Any unsuccessful status code should raise here
|
||||
|
||||
-19
@@ -11,7 +11,6 @@ from qtpy.QtWidgets import (
|
||||
QHeaderView,
|
||||
QLabel,
|
||||
QLineEdit,
|
||||
QPushButton,
|
||||
QSizePolicy,
|
||||
QTableWidget,
|
||||
QTableWidgetItem,
|
||||
@@ -25,10 +24,6 @@ from bec_widgets.utils.error_popups import SafeSlot
|
||||
from bec_widgets.widgets.services.bec_atlas_admin_view.experiment_selection.experiment_mat_card import (
|
||||
ExperimentMatCard,
|
||||
)
|
||||
|
||||
# from bec_widgets.widgets.services.bec_atlas_admin_view.experiment_selection.material_push_button import (
|
||||
# MaterialPushButton,
|
||||
# )
|
||||
from bec_widgets.widgets.services.bec_atlas_admin_view.experiment_selection.utils import (
|
||||
format_name,
|
||||
format_schedule,
|
||||
@@ -185,19 +180,6 @@ class ExperimentSelection(QWidget):
|
||||
|
||||
self._setup_search(layout)
|
||||
|
||||
# # Add filter section
|
||||
# filter_layout = QHBoxLayout()
|
||||
# self._with_proposals = QCheckBox("Show experiments with proposals", self)
|
||||
# self._without_proposals = QCheckBox("Show experiments without proposals", self)
|
||||
# self._with_proposals.setChecked(True)
|
||||
# self._without_proposals.setChecked(True)
|
||||
# self._with_proposals.toggled.connect(self._apply_table_filters)
|
||||
# self._without_proposals.toggled.connect(self._apply_table_filters)
|
||||
# filter_layout.addWidget(self._with_proposals)
|
||||
# filter_layout.addWidget(self._without_proposals)
|
||||
# filter_layout.addStretch(1)
|
||||
# layout.addLayout(filter_layout)
|
||||
|
||||
# Add table
|
||||
hor_layout = QHBoxLayout()
|
||||
self._table = QTableWidget(self._table_tab)
|
||||
@@ -276,7 +258,6 @@ class ExperimentSelection(QWidget):
|
||||
|
||||
@SafeSlot()
|
||||
def _update_selection_state(self):
|
||||
has_selection = False
|
||||
if self._tabs.currentWidget() is not self._table_tab:
|
||||
return
|
||||
index = self._table.selectionModel().selectedRows()
|
||||
|
||||
Reference in New Issue
Block a user