Skip to content

Commit

Permalink
Merge branch 'master' into product-icons-2
Browse files Browse the repository at this point in the history
  • Loading branch information
jsaq007 authored Sep 26, 2024
2 parents 3ecbd18 + 2889c20 commit 751dcf9
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 46 deletions.
27 changes: 23 additions & 4 deletions packages/pytest-simcore/src/pytest_simcore/helpers/playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ def __call__(self, message: str) -> bool:

return False

def is_progress_succesfully_finished(self) -> bool:
return all(
round(progress, 1) == 1.0 for progress in self._current_progress.values()
)

def get_current_progress(self):
return self._current_progress.values()


def wait_for_pipeline_state(
current_state: RunningState,
Expand Down Expand Up @@ -327,10 +335,21 @@ def expected_service_running(
with log_context(logging.INFO, msg="Waiting for node to run") as ctx:
waiter = SocketIONodeProgressCompleteWaiter(node_id=node_id, logger=ctx.logger)
service_running = ServiceRunning(iframe_locator=None)
with websocket.expect_event("framereceived", waiter, timeout=timeout):
if press_start_button:
_trigger_service_start(page, node_id)
yield service_running

try:
with websocket.expect_event("framereceived", waiter, timeout=timeout):
if press_start_button:
_trigger_service_start(page, node_id)
except TimeoutError:
if waiter.is_progress_succesfully_finished() is False:
ctx.logger.warning(
"⚠️ Progress bar didn't receive 100 percent: %s ⚠️", # https://github.com/ITISFoundation/osparc-simcore/issues/6449
waiter.get_current_progress(),
)
else:
raise

yield service_running

service_running.iframe_locator = page.frame_locator(
f'[osparc-test-id="iframe_{node_id}"]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import random
import sys
from collections.abc import AsyncIterable, AsyncIterator, Awaitable, Callable
from contextlib import AbstractAsyncContextManager, AsyncExitStack
from contextlib import AbstractAsyncContextManager, AsyncExitStack, suppress
from pathlib import Path
from typing import Any, Protocol

Expand Down Expand Up @@ -60,10 +60,12 @@ async def stop(self, *, graceful: bool = False):
assert self.process is not None
assert self.pid is not None

parent = psutil.Process(self.pid)
children = parent.children(recursive=True)
for child_pid in [child.pid for child in children]:
psutil.Process(child_pid).kill()
with suppress(psutil.NoSuchProcess):
parent = psutil.Process(self.pid)
children = parent.children(recursive=True)
for child_pid in [child.pid for child in children]:
with suppress(psutil.NoSuchProcess):
psutil.Process(child_pid).kill()

self.process = None
self.pid = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ qx.Class.define("osparc.announcement.AnnouncementUIFactory", {
},

statics: {
createLoginAnnouncement: function(title, text) {
createLoginAnnouncement: function(title, description) {
const loginAnnouncement = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({
backgroundColor: "strong-main",
alignX: "center",
Expand All @@ -46,22 +46,20 @@ qx.Class.define("osparc.announcement.AnnouncementUIFactory", {
const titleLabel = new qx.ui.basic.Label().set({
value: title,
font: "text-16",
textColor: "white",
alignX: "center",
rich: true,
wrap: true
textAlign: "center",
rich: true
});
loginAnnouncement.add(titleLabel);
}

if (text) {
if (description) {
const descriptionLabel = new qx.ui.basic.Label().set({
value: text,
value: description,
font: "text-14",
textColor: "white",
alignX: "center",
rich: true,
wrap: true
textAlign: "center",
rich: true
});
loginAnnouncement.add(descriptionLabel);
}
Expand All @@ -75,16 +73,12 @@ qx.Class.define("osparc.announcement.AnnouncementUIFactory", {

__isValid: function(widgetType) {
const announcement = this.getAnnouncement();

const now = new Date();
if (
announcement &&
announcement.getProducts().includes(osparc.product.Utils.getProductName()) &&
announcement.getWidgets().includes(widgetType) &&
now > announcement.getStart() &&
now < announcement.getEnd()
) {
return true;
if (announcement) {
const now = new Date();
const validPeriod = now > announcement.getStart() && now < announcement.getEnd();
const validProduct = announcement.getProducts().includes(osparc.product.Utils.getProductName());
const validWidgetType = widgetType ? announcement.getWidgets().includes(widgetType) : true;
return validPeriod && validProduct && validWidgetType;
}
return false;
},
Expand Down Expand Up @@ -124,8 +118,10 @@ qx.Class.define("osparc.announcement.AnnouncementUIFactory", {
return;
}

let text = announcement.getTitle() + ": ";
text += announcement.getDescription();
let text = announcement.getTitle();
if (announcement.getDescription()) {
text += ": " + announcement.getDescription();
}

const ribbonAnnouncement = this.__ribbonAnnouncement = new osparc.notification.RibbonNotification(text, "announcement", true);
ribbonAnnouncement.announcementId = announcement.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ qx.Class.define("osparc.auth.ui.LoginView", {
this.addAt(announcementUIFactory.createLoginAnnouncement(), 0);
} else {
announcementUIFactory.addListenerOnce("changeAnnouncement", e => {
const announcement = e.getData();
if (announcement) {
if (announcementUIFactory.hasLoginAnnouncement()) {
this.addAt(announcementUIFactory.createLoginAnnouncement(), 0);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ qx.Class.define("osparc.po.PreRegistration", {
break;
case "finding-status":
control = new qx.ui.basic.Label();
this._add(control);
this._add(control, {
rich: true
});
break;
case "pre-registration-container":
control = new qx.ui.container.Scroll();
Expand Down Expand Up @@ -76,11 +78,27 @@ qx.Class.define("osparc.po.PreRegistration", {
}
if (form.validate()) {
submitBtn.setFetching(true);

const flashErrorMsg = this.tr("Pre-Registration Failed. See details below");
const findingStatus = this.getChildControl("finding-status");
findingStatus.setValue(this.tr("Searching Pre-Registered users..."));
const params = {
data: JSON.parse(requestAccountData.getValue())
};

let params;
try {
params = {
data: JSON.parse(requestAccountData.getValue())
};
} catch (err) {
console.error(err);

const detailErrorMsg = `Error parsing Request Form JSON. ${err}`;
findingStatus.setValue(detailErrorMsg);

osparc.FlashMessenger.logAs(flashErrorMsg, "ERROR");
submitBtn.setFetching(false);
return
}

osparc.data.Resources.fetch("users", "preRegister", params)
.then(data => {
if (data.length) {
Expand All @@ -91,9 +109,10 @@ qx.Class.define("osparc.po.PreRegistration", {
this.__populatePreRegistrationLayout(data);
})
.catch(err => {
findingStatus.setValue(this.tr("Error searching Pre-Registered users"));
const detailErrorMsg = this.tr(`Error during Pre-Registeristration: ${err.message}`)
findingStatus.setValue(detailErrorMsg);
console.error(err);
osparc.FlashMessenger.logAs(err.message, "ERROR");
osparc.FlashMessenger.logAs(flashErrorMsg, "ERROR");
})
.finally(() => submitBtn.setFetching(false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ async def get_service_resources(request: Request):
)
@login_required
@permission_required("services.catalog.*")
@_handlers_errors.reraise_catalog_exceptions_as_http_errors
async def get_service_pricing_plan(request: Request):
ctx = CatalogRequestContext.create(request)
path_params = parse_request_path_parameters_as(ServicePathParams, request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from aiohttp import web
from servicelib.aiohttp.typing_extension import Handler

from ..resource_usage.errors import DefaultPricingPlanNotFoundError
from .exceptions import (
CatalogForbiddenError,
CatalogItemNotFoundError,
Expand All @@ -19,6 +20,7 @@ async def _wrapper(request: web.Request) -> web.StreamResponse:

except (
CatalogItemNotFoundError,
DefaultPricingPlanNotFoundError,
DefaultPricingUnitForServiceNotFoundError,
) as exc:
raise web.HTTPNotFound(reason=f"{exc}") from exc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
from ..groups.exceptions import GroupNotFoundError
from ..login.decorators import login_required
from ..projects.api import has_user_project_access_rights
from ..resource_usage.errors import DefaultPricingPlanNotFoundError
from ..security.decorators import permission_required
from ..users.api import get_user_id_from_gid, get_user_role
from ..users.exceptions import UserDefaultWalletNotFoundError
Expand Down Expand Up @@ -101,6 +102,7 @@ async def wrapper(request: web.Request) -> web.StreamResponse:
ProjectNotFoundError,
NodeNotFoundError,
UserDefaultWalletNotFoundError,
DefaultPricingPlanNotFoundError,
DefaultPricingUnitNotFoundError,
GroupNotFoundError,
CatalogItemNotFoundError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from ..login.decorators import login_required
from ..notifications import project_logs
from ..products.api import Product, get_current_product
from ..resource_usage.errors import DefaultPricingPlanNotFoundError
from ..security.decorators import permission_required
from ..users import api
from ..users.exceptions import UserDefaultWalletNotFoundError
Expand All @@ -37,6 +38,7 @@
from . import projects_api
from ._common_models import ProjectPathParams, RequestContext
from .exceptions import (
DefaultPricingUnitNotFoundError,
ProjectInvalidRightsError,
ProjectNotFoundError,
ProjectStartsTooManyDynamicNodesError,
Expand All @@ -57,7 +59,12 @@ async def _wrapper(request: web.Request) -> web.StreamResponse:
try:
return await handler(request)

except (ProjectNotFoundError, UserDefaultWalletNotFoundError) as exc:
except (
ProjectNotFoundError,
UserDefaultWalletNotFoundError,
DefaultPricingPlanNotFoundError,
DefaultPricingUnitNotFoundError,
) as exc:
raise web.HTTPNotFound(reason=f"{exc}") from exc

except ProjectInvalidRightsError as exc:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
from models_library.users import UserID
from models_library.wallets import WalletID
from pydantic import NonNegativeInt, parse_obj_as
from servicelib.aiohttp import status
from servicelib.aiohttp.client_session import get_client_session
from settings_library.resource_usage_tracker import ResourceUsageTrackerSettings
from yarl import URL

from ._utils import handle_client_exceptions
from .errors import DefaultPricingPlanNotFoundError
from .settings import get_plugin_settings

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -95,10 +97,15 @@ async def get_default_service_pricing_plan(
}
)
with handle_client_exceptions(app) as session:
async with session.get(url) as response:
response.raise_for_status()
body: dict = await response.json()
return parse_obj_as(PricingPlanGet, body)
try:
async with session.get(url) as response:
response.raise_for_status()
body: dict = await response.json()
return parse_obj_as(PricingPlanGet, body)
except ClientResponseError as e:
if e.status == status.HTTP_404_NOT_FOUND:
raise DefaultPricingPlanNotFoundError from e
raise


async def get_pricing_plan_unit(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from ..errors import WebServerBaseError


class ResourceUsageValueError(WebServerBaseError, ValueError):
...


class DefaultPricingPlanNotFoundError(ResourceUsageValueError):
msg_template = "Default pricing plan not found"
15 changes: 12 additions & 3 deletions tests/e2e-playwright/tests/tip/test_ti_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,19 @@ def test_classic_ti_plan( # noqa: PLR0915
create_tip_plan_from_dashboard: Callable[[str], dict[str, Any]],
):
with log_context(logging.INFO, "Checking 'Access TIP' teaser"):
# click to open and expand
page.get_by_test_id("userMenuBtn").click()
page.get_by_test_id("userMenuAccessTIPBtn").click()
assert page.get_by_test_id("tipTeaserWindow").is_visible()
page.get_by_test_id("tipTeaserWindowCloseBtn").click()

if is_product_lite:
page.get_by_test_id("userMenuAccessTIPBtn").click()
assert page.get_by_test_id("tipTeaserWindow").is_visible()
page.get_by_test_id("tipTeaserWindowCloseBtn").click()
else:
assert (
page.get_by_test_id("userMenuAccessTIPBtn").count() == 0
), "full version should NOT have a teaser"
# click to close
page.get_by_test_id("userMenuBtn").click()

# press + button
project_data = create_tip_plan_from_dashboard("newTIPlanButton")
Expand Down

0 comments on commit 751dcf9

Please sign in to comment.