|
14 | 14 | from typing import Any, AsyncIterable, AsyncIterator, Callable
|
15 | 15 | from unittest.mock import MagicMock, Mock
|
16 | 16 |
|
| 17 | +import aiopg.sa |
17 | 18 | import pytest
|
18 | 19 | import redis.asyncio as aioredis
|
19 | 20 | from aiohttp import web
|
|
33 | 34 | from redis import Redis
|
34 | 35 | from servicelib.aiohttp.application import create_safe_application
|
35 | 36 | from servicelib.rest_constants import RESPONSE_MODEL_POLICY
|
| 37 | +from simcore_postgres_database.models.products import products |
36 | 38 | from simcore_postgres_database.models.users import UserRole
|
37 | 39 | from simcore_service_webserver._meta import api_version_prefix as API_VERSION
|
38 | 40 | from simcore_service_webserver.application_settings import setup_settings
|
@@ -727,3 +729,60 @@ async def test_list_permissions_with_overriden_extra_properties(
|
727 | 729 |
|
728 | 730 | assert override_services_specifications.name == "override_services_specifications"
|
729 | 731 | assert override_services_specifications.allowed is True
|
| 732 | + |
| 733 | + |
| 734 | +@pytest.fixture |
| 735 | +async def with_no_product_name_defined( |
| 736 | + aiopg_engine: aiopg.sa.engine.Engine, |
| 737 | +) -> AsyncIterator[None]: |
| 738 | + async with aiopg_engine.acquire() as conn: |
| 739 | + result = await conn.execute(products.select()) |
| 740 | + assert result |
| 741 | + list_of_products = await result.fetchall() |
| 742 | + |
| 743 | + # remove them all |
| 744 | + result = await conn.execute(products.delete()) |
| 745 | + assert result |
| 746 | + |
| 747 | + yield |
| 748 | + |
| 749 | + # revert changes |
| 750 | + if list_of_products: |
| 751 | + async with aiopg_engine.acquire() as conn: |
| 752 | + await conn.execute( |
| 753 | + products.insert().values( |
| 754 | + [dict(product.items()) for product in list_of_products] |
| 755 | + ) |
| 756 | + ) |
| 757 | + |
| 758 | + |
| 759 | +@pytest.mark.parametrize( |
| 760 | + "user_role,expected_response", |
| 761 | + [ |
| 762 | + (UserRole.USER, web.HTTPOk), |
| 763 | + ], |
| 764 | +) |
| 765 | +async def test_list_permissions_with_no_group_defined_returns_default_false_for_services_override( |
| 766 | + logged_user: UserInfoDict, |
| 767 | + client: TestClient, |
| 768 | + expected_response: type[web.HTTPException], |
| 769 | + with_no_product_name_defined: None, |
| 770 | +): |
| 771 | + assert client.app |
| 772 | + url = client.app.router["list_user_permissions"].url_for() |
| 773 | + assert f"{url}" == "/v0/me/permissions" |
| 774 | + resp = await client.get(f"{url}") |
| 775 | + data, error = await assert_status(resp, expected_response) |
| 776 | + assert data |
| 777 | + assert not error |
| 778 | + list_of_permissions = parse_obj_as(list[PermissionGet], data) |
| 779 | + filtered_permissions = list( |
| 780 | + filter( |
| 781 | + lambda x: x.name == "override_services_specifications", list_of_permissions |
| 782 | + ) |
| 783 | + ) |
| 784 | + assert len(filtered_permissions) == 1 |
| 785 | + override_services_specifications = filtered_permissions[0] |
| 786 | + |
| 787 | + assert override_services_specifications.name == "override_services_specifications" |
| 788 | + assert override_services_specifications.allowed is False |
0 commit comments