Ejemplo n.º 1
0
def test_list_pagination(tmpdir, setup, browser):
    # type: (LocalPath, SetupTest, Chrome) -> None
    """Test pagination.

    This forces the pagination to specific values, rather than using the page controls, since we
    don't create more than 100 permissions for testing.
    """
    permissions = create_test_data(setup)
    settings = FrontendSettings()
    settings.update_from_config(src_path("config", "dev.yaml"))
    expected_permissions = [
        (p.name, p.description, format_date(settings, p.created_on)) for p in permissions
    ]

    with frontend_server(tmpdir, "*****@*****.**") as frontend_url:
        browser.get(url(frontend_url, "/permissions?limit=1&offset=1"))
        page = PermissionsPage(browser)
        seen_permissions = [(r.name, r.description, r.created_on) for r in page.permission_rows]
        assert seen_permissions == sorted(expected_permissions)[1:2]
        assert page.limit_label == "Limit: 1"

        # Retrieve the last permission but with a larger limit to test that the limit isn't capped
        # to the number of returned items.
        browser.get(url(frontend_url, "/permissions?limit=10&offset=2"))
        page = PermissionsPage(browser)
        seen_permissions = [(r.name, r.description, r.created_on) for r in page.permission_rows]
        assert seen_permissions == sorted(expected_permissions)[2:]
        assert page.limit_label == "Limit: 10"
Ejemplo n.º 2
0
def test_list_pagination(tmpdir, setup, browser):
    # type: (LocalPath, SetupTest, Chrome) -> None
    """Test pagination.

    This forces the pagination to specific values, rather than using the page controls, since we
    don't create more than 100 permissions for testing.
    """
    permissions = create_test_data(setup)
    settings = FrontendSettings()
    settings.update_from_config(src_path("config", "dev.yaml"))
    expected_permissions = [
        (p.name, p.description, format_date(settings, p.created_on)) for p in permissions
    ]

    with frontend_server(tmpdir, "*****@*****.**") as frontend_url:
        browser.get(url(frontend_url, "/permissions?limit=1&offset=1"))
        page = PermissionsPage(browser)
        seen_permissions = [(r.name, r.description, r.created_on) for r in page.permission_rows]
        assert seen_permissions == sorted(expected_permissions)[1:2]
        assert page.limit_label == "Limit: 1"

        # Retrieve the last permission but with a larger limit to test that the limit isn't capped
        # to the number of returned items.
        browser.get(url(frontend_url, "/permissions?limit=10&offset=2"))
        page = PermissionsPage(browser)
        seen_permissions = [(r.name, r.description, r.created_on) for r in page.permission_rows]
        assert seen_permissions == sorted(expected_permissions)[2:]
        assert page.limit_label == "Limit: 10"
Ejemplo n.º 3
0
def test_list(tmpdir, setup, browser):
    # type: (LocalPath, SetupTest, Chrome) -> None
    permissions = create_test_data(setup)
    settings = FrontendSettings()
    settings.update_from_config(src_path("config", "dev.yaml"))
    expected_permissions = [
        (p.name, p.description, format_date(settings, p.created_on)) for p in permissions
    ]

    with frontend_server(tmpdir, "*****@*****.**") as frontend_url:
        browser.get(url(frontend_url, "/permissions"))

        # Check the basic permission list.
        page = PermissionsPage(browser)
        seen_permissions = [(r.name, r.description, r.created_on) for r in page.permission_rows]
        assert seen_permissions == sorted(expected_permissions)
        assert page.heading == "Permissions"
        assert page.subheading == "{} permission(s)".format(len(expected_permissions))
        assert page.limit_label == "Limit: 100"

        # Switch to only audited permissions.
        page.click_show_audited_button()
        seen_permissions = [(r.name, r.description, r.created_on) for r in page.permission_rows]
        audited = [p for p in expected_permissions if p[0] == "audited-permission"]
        assert seen_permissions == sorted(audited)
        assert page.heading == "Audited Permissions"
        assert page.subheading == "{} permission(s)".format(len(audited))

        # Switch back to all permissions and sort by date.
        page.click_show_all_button()
        page.click_sort_by_date()
        seen_permissions = [(r.name, r.description, r.created_on) for r in page.permission_rows]
        expected_permissions_sorted_by_time = [
            (p.name, p.description, format_date(settings, p.created_on))
            for p in sorted(permissions, key=lambda p: p.created_on, reverse=True)
        ]
        assert seen_permissions == expected_permissions_sorted_by_time

        # Reverse the sort order.
        page.click_sort_by_date()
        seen_permissions = [(r.name, r.description, r.created_on) for r in page.permission_rows]
        assert seen_permissions == list(reversed(expected_permissions_sorted_by_time))
Ejemplo n.º 4
0
def test_list(tmpdir, setup, browser):
    # type: (LocalPath, SetupTest, Chrome) -> None
    permissions = create_test_data(setup)
    settings = FrontendSettings()
    settings.update_from_config(src_path("config", "dev.yaml"))
    expected_permissions = [
        (p.name, p.description, format_date(settings, p.created_on)) for p in permissions
    ]

    with frontend_server(tmpdir, "*****@*****.**") as frontend_url:
        browser.get(url(frontend_url, "/permissions"))

        # Check the basic permission list.
        page = PermissionsPage(browser)
        seen_permissions = [(r.name, r.description, r.created_on) for r in page.permission_rows]
        assert seen_permissions == sorted(expected_permissions)
        assert page.heading == "Permissions"
        assert page.subheading == "{} permission(s)".format(len(expected_permissions))
        assert page.limit_label == "Limit: 100"

        # Switch to only audited permissions.
        page.click_show_audited_button()
        seen_permissions = [(r.name, r.description, r.created_on) for r in page.permission_rows]
        audited = [p for p in expected_permissions if p[0] == "audited-permission"]
        assert seen_permissions == sorted(audited)
        assert page.heading == "Audited Permissions"
        assert page.subheading == "{} permission(s)".format(len(audited))

        # Switch back to all permissions and sort by date.
        page.click_show_all_button()
        page.click_sort_by_date()
        seen_permissions = [(r.name, r.description, r.created_on) for r in page.permission_rows]
        expected_permissions_sorted_by_time = [
            (p.name, p.description, format_date(settings, p.created_on))
            for p in sorted(permissions, key=lambda p: p.created_on, reverse=True)
        ]
        assert seen_permissions == expected_permissions_sorted_by_time

        # Reverse the sort order.
        page.click_sort_by_date()
        seen_permissions = [(r.name, r.description, r.created_on) for r in page.permission_rows]
        assert seen_permissions == list(reversed(expected_permissions_sorted_by_time))