Exemplo n.º 1
0
def test_how_to_cite(user_alice_logged_in, handle_usage_statistics):
    browser, user_alice = user_alice_logged_in

    #
    # Alice has a surface and publishes it
    #
    surface_name = "Diamond Structure"
    topo_name = "Diamond Cut"
    topo_description = "My nice measurement"

    surface = SurfaceFactory(creator=user_alice, name=surface_name)
    topo = Topography2DFactory(surface=surface,
                               name=topo_name,
                               description=topo_description)
    publication = surface.publish('cc0-1.0', 'Famous Scientist')

    # Alice filters for published surfaces - enters
    # "Select" tab and chooses "Only published surfaces"
    #
    base_url = browser.url
    goto_select_page(browser)

    assert num_items_in_result_table(
        browser) == 2  # both surfaces are visible by default

    select_sharing_status(browser, 'published')
    assert num_items_in_result_table(browser) == 1  # only published is visible

    data = data_of_item_by_name(browser, surface_name)
    assert data['version'] == "1 (2021-07-12)"
    assert data['authors'] == 'Famous Scientist'

    double_click_on_item_by_name(browser, surface_name)
    data = data_of_item_by_name(browser, topo_name)
    assert data['version'] == ""
    assert data['authors'] == ''
    assert data['description'] == topo_description

    # Alice opens the properties and sees
    # the "published by yo" badge.
    press_view_for_item_by_name(browser, surface_name)
    assert browser.is_text_present('published by you')

    #
    # Alice sees "How to cite" tab an chooses it
    #
    assert browser.is_text_present("How to cite")
    browser.links.find_by_partial_text("How to cite").click()

    # Now the page shows a citation in text format
    exp_pub_url = base_url.rstrip('/') + publication.get_absolute_url()
    exp_citation = f"Famous Scientist. ({publication.datetime.year}). contact.engineering. {surface_name} (Version 1). " + \
                   f"{exp_pub_url}"
    assert browser.is_text_present(exp_citation)
Exemplo n.º 2
0
def test_keep_current_page_in_session(user_alice_logged_in):

    browser, user_alice = user_alice_logged_in

    # create a lot of surfaces
    for i in range(11):
        SurfaceFactory(creator=user_alice)

    goto_select_page(browser)

    #
    # pagination should have 2 pages
    #
    pagination = browser.find_by_id("pagination")

    # there should be 4 items: previous, 1, 2, next
    assert browser.is_text_present("Next", wait_time=1)

    page_items = pagination.find_by_css(".page-item")

    assert len(page_items) == 4

    assert page_items[0].text == "Previous"
    assert page_items[1].text == "1"
    assert page_items[2].text == "2"
    assert page_items[3].text == "Next"

    assert active_page_number(browser) == 1

    # page size should show "10"
    page_size_select = browser.find_by_id("page-size-select")
    assert page_size_select.find_by_css(".selected").first.text == "10"

    # footer should show total number
    assert browser.is_text_present("Showing 10 surfaces out of 11")

    # press "Next"
    page_items[3].click()

    # now footer shows different text
    assert browser.is_text_present("Showing 1 surfaces out of 11", wait_time=1)
    assert active_page_number(browser) == 2

    # Goto to sharing page and back, should still be on page 2
    goto_sharing_page(browser)
    goto_select_page(browser)

    assert browser.is_text_present("Showing 1 surfaces out of 11")
    assert active_page_number(browser) == 2
Exemplo n.º 3
0
def test_deselect_all(user_alice_logged_in, items_for_selection):

    browser, user_alice = user_alice_logged_in

    #
    # navigate to select page and select sth.
    #
    goto_select_page(browser)
    assert browser.is_text_present('surface1', wait_time=1)

    cb = checkbox_for_item_by_name(browser, 'surface1')
    cb.check()

    # now we have a basket item
    assert is_in_basket(browser, 'surface1')

    # pressing unselect
    browser.click_link_by_id('unselect-all')

    # time.sleep(1)

    # now the basket item is no longer there
    assert not is_in_basket(browser, 'surface1')
def test_filter(user_alice_logged_in, items_for_filtering):
    browser, user_alice = user_alice_logged_in

    goto_select_page(browser)

    # Alice should see three surfaces
    #
    # There should be
    # - no search term,
    # - all categories shown
    # - own and shared surfaces shown
    # - tree should be in "surface list" mode
    # - page 1 shown
    # - page size = 10

    assert browser.is_text_present("Showing 3 surfaces out of 3.")
    assert browser.is_text_present("Not filtered for search term")
    assert selected_category(browser) == 'all'
    assert selected_sharing_status(browser) == 'all'
    assert selected_tree_mode(browser) == 'surface list'
    assert active_page_number(browser) == 1
    assert active_page_size(browser) == 10

    assert is_text_present_in_result_table(browser, "surface1")
    assert is_text_present_in_result_table(browser, "surface2")
    assert is_text_present_in_result_table(browser, "surface3")

    # Now she clicks on category "exp"
    # => only surface 1 should be shown
    browser.select('category', 'exp')

    assert browser.is_text_present("Showing 1 surfaces out of 1.")
    assert browser.is_text_present("Not filtered for search term")
    assert selected_category(browser) == 'exp'
    assert selected_sharing_status(browser) == 'all'
    assert selected_tree_mode(browser) == 'surface list'
    assert active_page_number(browser) == 1
    assert active_page_size(browser) == 10

    assert browser.is_text_present('surface1')
    assert not browser.is_text_present('surface2')
    assert not browser.is_text_present('surface3')

    # Now she clicks on category "sim"
    # => only surface 3 should be shown
    browser.select('category', 'sim')
    assert browser.is_text_present("Showing 1 surfaces out of 1.")
    assert selected_category(browser) == 'sim'

    assert not browser.is_text_present('surface1')
    assert not browser.is_text_present('surface2')
    assert browser.is_text_present('surface3')

    #
    # Now change to 'sharing' tab and back
    # => results should be the same
    goto_sharing_page(browser)
    goto_select_page(browser)

    assert browser.is_text_present("Showing 1 surfaces out of 1.")
    assert browser.is_text_present("Not filtered for search term")
    assert selected_category(browser) == 'sim'
    assert selected_sharing_status(browser) == 'all'
    assert selected_tree_mode(browser) == 'surface list'
    assert active_page_number(browser) == 1
    assert active_page_size(browser) == 10

    assert not browser.is_text_present('surface1')
    assert not browser.is_text_present('surface2')
    assert browser.is_text_present('surface3')

    # Now show only "own" surfaces. Since only surface 3 is shown
    # and this is shared, no surfaces should be visible
    browser.select('sharing_status', 'own')
    assert browser.is_text_present("Showing 0 surfaces out of 0.")

    # Showing again all categories, two surfaces should show up
    browser.select('category', 'all')
    assert browser.is_text_present("Showing 2 surfaces out of 2.")

    assert browser.is_text_present('surface1')
    assert browser.is_text_present('surface2')
    assert not browser.is_text_present('surface3')
def test_search(user_alice_logged_in, items_for_filtering):

    browser, user_alice = user_alice_logged_in

    # tag1, tag2 = items_for_filtering['tags']
    # surface1, surface2, surface3 = items_for_filtering['surfaces']
    # topo1a, topo1b, topo2a, topo3a = items_for_filtering['topographies']

    search_for(browser, "surface2")

    assert not is_text_present_in_result_table(browser, 'surface1')
    assert is_text_present_in_result_table(browser, 'surface2')
    assert not is_text_present_in_result_table(browser, 'surface3')

    assert browser.is_text_present("Showing 1 surfaces out of 1.")
    assert browser.is_text_present("Clear filter for")
    assert selected_category(browser) == 'all'
    assert selected_sharing_status(browser) == 'all'
    assert selected_tree_mode(browser) == 'surface list'
    assert active_page_number(browser) == 1
    assert active_page_size(browser) == 10

    # Change to tag tree
    # => only tag1 should be present
    select_tree_mode(browser, 'tag tree')

    def check_results_for_tag_tree():
        assert is_text_present_in_result_table(browser, 'tag1')
        assert not is_text_present_in_result_table(browser, 'tag2')

        assert browser.is_text_present("Showing 1 top level tags out of 1.")
        assert browser.is_text_present("Clear filter for")
        assert selected_category(browser) == 'all'
        assert selected_sharing_status(browser) == 'all'
        assert selected_tree_mode(browser) == 'tag tree'
        assert active_page_number(browser) == 1
        assert active_page_size(browser) == 10

    check_results_for_tag_tree()

    #
    # Switch to sharing page and back, search should still be present
    #
    goto_sharing_page(browser)
    goto_select_page(browser)

    check_results_for_tag_tree()

    #
    # Clear search term, should stay on tag tree
    #
    clear_search_term(browser)

    assert browser.is_text_present("Showing 2 top level tags out of 2.",
                                   wait_time=1)
    assert selected_category(browser) == 'all'
    assert selected_sharing_status(browser) == 'all'
    assert selected_tree_mode(browser) == 'tag tree'
    assert active_page_number(browser) == 1
    assert active_page_size(browser) == 10

    assert is_text_present_in_result_table(browser, 'tag1')
    assert is_text_present_in_result_table(browser, 'tag2')
Exemplo n.º 6
0
def test_select_page_size(user_alice_logged_in):

    browser, user_alice = user_alice_logged_in

    # create a lot of surfaces
    for i in range(11):
        SurfaceFactory(creator=user_alice)

    goto_select_page(browser)

    #
    # pagination should have 2 pages
    #
    pagination = browser.find_by_id("pagination")

    # there should be 4 items: previous, 1, 2, next
    assert browser.is_text_present("Next", wait_time=1)

    page_items = pagination.find_by_css(".page-item")

    assert len(page_items) == 4

    assert page_items[0].text == "Previous"
    assert page_items[1].text == "1"
    assert page_items[2].text == "2"
    assert page_items[3].text == "Next"

    assert active_page_number(browser) == 1

    # page size should show "10"
    page_size_select = browser.find_by_id("page-size-select")
    assert page_size_select.find_by_css(".selected").first.text == "10"

    # footer should show total number
    assert browser.is_text_present("Showing 10 surfaces out of 11")

    # press "Next"
    page_items[3].click()

    # now footer shows different text
    assert browser.is_text_present("Showing 1 surfaces out of 11", wait_time=1)

    assert active_page_number(browser) == 2

    # select page size 25
    page_size_25_option = page_size_select.find_by_css('option')[1]
    assert page_size_25_option.text == "25"
    page_size_25_option.click()

    # now there is only one page and it should be page 1
    assert browser.is_text_present("Next", wait_time=1)
    assert browser.is_text_present("Showing 11 surfaces out of 11",
                                   wait_time=1)

    pagination = browser.find_by_id("pagination")
    page_items = pagination.find_by_css(".page-item")

    assert len(page_items) == 3

    assert page_items[0].text == "Previous"
    assert page_items[1].text == "1"
    assert page_items[2].text == "Next"

    assert active_page_number(browser) == 1
Exemplo n.º 7
0
def test_publishing_form(user_alice_logged_in, handle_usage_statistics):
    browser, user_alice = user_alice_logged_in

    #
    # Generate surface with topography for Alice.
    #
    surface_name = "First published surface"

    surface = SurfaceFactory(creator=user_alice, name=surface_name)
    # a topography is added later

    #
    # When going to the "Published surfaces tab", nothing is listed
    #
    goto_publications_page(browser)
    assert browser.is_text_present("You haven't published any surfaces yet.")

    #
    # Alice opens properties for the surface
    #
    goto_select_page(browser)
    press_view_for_item_by_name(browser, surface_name)

    #
    # Alice presses "Publish" button. The extra "Publish surface ..." tab opens.
    #
    assert browser.is_text_present("Publish")
    publish_btn = browser.links.find_by_partial_text("Publish")
    publish_btn.click()

    #
    # Since no topography is available for the surface, a hint is shown
    #
    assert browser.is_text_present("This surface has no measurements yet")

    #
    # We add a topography and reload
    #
    Topography2DFactory(surface=surface)
    browser.reload()

    #
    # There are three licenses for selection. Alice chooses the "CC BY-SA"
    # license
    #
    # browser.choose('license', 'ccbysa-4.0')  # this only works with standard HTML radio btn
    # radio_btn = browser
    select_radio_btn(browser, 'id_id_license_0_2')  # 'ccbysa-4.0'
    #
    # Alice presses Publish. She didn't check the checkboxes, we are still on page
    #
    press_yes_publish(browser)

    assert len(browser.find_by_name("save")) > 0

    #
    # Alice checks one checkbox, the other is still needed and the authors
    #
    select_radio_btn(browser, 'id_copyright_hold')

    press_yes_publish(browser)
    assert len(browser.find_by_name("save")) > 0

    # Alice checks the second and tries again to publish.
    select_radio_btn(browser, 'id_agreed')
    assert len(browser.find_by_name("save")) > 0

    # Still now publishing: She hasn't entered an author yet.
    # She decides to enter herself as author by pressing the "user" button
    press_insert_me_btn(browser)

    # Now she tries again
    # The extra tab is closed and Alice is taken
    # to the list of published surfaces.
    press_yes_publish(browser)
    assert len(browser.find_by_name("save")) == 0
    assert browser.is_text_present("Surfaces published by you", wait_time=1)

    # Here the published surface is listed. Also the author names are listed, here just Alice' name.
    # Alice presses the link and enters the property page for the surface.
    assert browser.is_text_present(surface_name)
    assert browser.is_text_present(user_alice.name)
    browser.find_by_css('td').find_by_text(surface_name).click()

    #
    # Here a "published by you" badge is shown.
    #
    assert browser.is_text_present("published by you")

    # She opens the permissions and sees that Everyone has read permissions
    # and nothing else.
    # The individual names are NOT listed.
    assert_only_permissions_everyone(browser)
Exemplo n.º 8
0
def test_switch_between_wip_and_version(user_alice_logged_in,
                                        handle_usage_statistics):
    browser, user_alice = user_alice_logged_in

    #
    # Alice has a surface and publishes it
    #
    surface = SurfaceFactory(creator=user_alice, name="Alice's Surface")
    topo = Topography2DFactory(surface=surface)
    publication = surface.publish('cc0-1.0', 'Alice')

    #
    # When browsing to the surface, the current surface is shown as "Work in progress"
    #
    goto_select_page(browser)
    press_view_for_item_by_name(browser, surface.name)

    assert browser.is_text_present("Work in progress")
    assert not browser.is_text_present("Version 1")

    # She could edit, if she wanted
    assert browser.is_text_present("Edit meta data")

    #
    # Switching to version 1
    #
    versions_btn = browser.find_by_id('versions-btn')
    versions_btn.click()
    versions_dropdown = browser.find_by_id('versions-dropdown')
    version_links = versions_dropdown.find_by_tag('a')

    assert "Work in progress" in version_links[0].text
    assert "Version 1" in version_links[1].text

    version_links[1].click()

    assert browser.is_text_present(f"{publication.surface.label}", wait_time=1)

    #
    # Alice should be on the page of the new version
    #
    assert publication.surface.get_absolute_url() in browser.url

    # She cannot edit
    assert not browser.is_text_present("Edit meta data")

    #
    # Alice can switch back to editable version (work in progress)
    #
    versions_btn = browser.find_by_id('versions-btn')
    versions_btn.click()
    versions_dropdown = browser.find_by_id('versions-dropdown')
    version_links = versions_dropdown.find_by_tag('a')

    assert "Work in progress" in version_links[0].text
    assert "Version 1" in version_links[1].text

    version_links[0].click()

    assert browser.is_text_present(f"{publication.original_surface.label}",
                                   wait_time=1)
    assert publication.original_surface.get_absolute_url() in browser.url

    assert browser.is_text_present("Edit meta data")
Exemplo n.º 9
0
def test_see_published_by_others(user_alice_logged_in, user_bob,
                                 handle_usage_statistics, settings):
    browser, user_alice = user_alice_logged_in

    # switch off checks for too fast publication
    settings.MIN_SECONDS_BETWEEN_SAME_SURFACE_PUBLICATIONS = None

    #
    # Alice has a surface, which is not published
    #
    SurfaceFactory(creator=user_alice, name="Alice's Surface")

    #
    # User Bob publishes a surface (here in the background)
    #
    surface_name = "Bob has published this"
    surface_description = "Valuable results."
    surface = SurfaceFactory(creator=user_bob,
                             name=surface_name,
                             description=surface_description)
    Topography2DFactory(surface=surface)
    publication = surface.publish('cc0-1.0', 'Bob')

    # Alice filters for published surfaces - enters
    # "Select" tab and chooses "Only published surfaces"
    #
    goto_select_page(browser)

    assert num_items_in_result_table(
        browser) == 2  # both surfaces are visible by default

    select_sharing_status(browser, 'published')
    assert num_items_in_result_table(browser) == 1  # only published is visible

    # Bobs surface is visible as only surface.
    # The version number is "1".
    data = data_of_item_by_name(browser, surface_name)
    assert data['description'] == surface_description
    assert data['version'] == "1 (2021-07-12)"

    # Alice opens the properties and sees
    # the "published by Bob" badge.
    press_view_for_item_by_name(browser, surface_name)
    assert browser.is_text_present('published by Bob Marley')

    # She opens the permissions and sees that Everyone has read permissions
    # and nothing else.
    # The individual names are NOT listed.
    assert_only_permissions_everyone(browser)

    #
    # She sees a dropdown with only this version
    #
    assert browser.is_text_present('Version 1')
    assert not browser.is_text_present('Version 2')

    #
    # Bob publishes again, Alice reloads the page
    #
    publication = surface.publish('cc0-1.0', 'Bob')
    browser.reload()

    #
    # Now also the second version is visible
    #
    assert browser.is_text_present('Version 1')
    assert not browser.is_text_present('Version 2')

    #
    # Alice can switch to the new version
    #
    versions_btn = browser.find_by_id('versions-btn')
    versions_btn.click()
    versions_dropdown = browser.find_by_id('versions-dropdown')
    version_links = versions_dropdown.find_by_tag('a')

    assert "Version 1" in version_links[0].text
    assert "Version 2" in version_links[1].text

    version_links[1].click()

    assert browser.is_text_present(f"{publication.original_surface.label}",
                                   wait_time=1)

    #
    # Alice should be on the page of the new version
    #
    assert publication.surface.get_absolute_url() in browser.url
Exemplo n.º 10
0
def test_publishing_form_multiple_authors(user_alice_logged_in,
                                          handle_usage_statistics):
    """Test that multiple authors can be entered.
    """
    browser, user_alice = user_alice_logged_in

    #
    # Generate surface with topography for Alice.
    #
    surface_name = "First published surface"

    surface = SurfaceFactory(creator=user_alice, name=surface_name)
    Topography2DFactory(surface=surface)

    #
    # Alice opens properties for the surface
    #
    goto_select_page(browser)
    press_view_for_item_by_name(browser, surface_name)

    #
    # Alice presses "Publish" button. The extra "Publish surface ..." tab opens.
    #
    assert browser.is_text_present("Publish")
    publish_btn = browser.links.find_by_partial_text("Publish")
    publish_btn.click()

    #
    # Alice adds herself as first author
    #
    press_insert_me_btn(browser)

    #
    # Alice presses "One more author" button, adds one author
    #
    assert browser.is_text_present('One more author', wait_time=1)
    one_more_author_btn = browser.find_by_id('one_more_author_btn')
    one_more_author_btn.click()

    assert browser.is_text_present("2. Author")
    browser.fill('author_1', "Queen of Hearts")

    #
    # Alice chooses the "CC BY-SA" license
    #
    select_radio_btn(browser, 'id_id_license_0_2')  # 'ccbysa-4.0'

    #
    # Alice checks the checkboxes
    #
    select_radio_btn(browser, 'id_copyright_hold')
    select_radio_btn(browser, 'id_agreed')

    press_yes_publish(browser)
    assert len(browser.find_by_name("save")) == 0
    assert browser.is_text_present("Surfaces published by you", wait_time=1)

    # Here the published surface is listed. And both author names.
    assert browser.is_text_present(surface_name)
    assert browser.is_text_present(user_alice.name)
    assert browser.is_text_present("Queen of Hearts")