예제 #1
0
def test_import_downloaded_surface_archive(client):

    username = '******'
    surface_name = "Test Surface for Import"
    surface_category = 'dum'
    user = UserFactory(username=username)
    surface = SurfaceFactory(creator=user,
                             name=surface_name,
                             category=surface_category)
    topo1 = Topography2DFactory(surface=surface,
                                name='2D Measurement',
                                size_x=10,
                                size_y=10,
                                unit='mm')
    topo2 = Topography1DFactory(surface=surface,
                                name='1D Measurement',
                                size_x=10,
                                unit='µm')

    client.force_login(user)

    download_url = reverse('manager:surface-download',
                           kwargs=dict(surface_id=surface.id))
    response = client.get(download_url)

    # write downloaded data to temporary file and open
    with tempfile.NamedTemporaryFile(mode='wb') as zip_archive:
        zip_archive.write(response.content)
        zip_archive.seek(0)

        # reimport the surface
        call_command('import_surfaces', username, zip_archive.name)

    surface_copy = Surface.objects.get(
        description__icontains='imported from file')

    #
    # Check surface
    #
    assert surface_copy.name == surface.name
    assert surface_copy.category == surface.category
    assert surface.description in surface_copy.description
    assert surface_copy.tags == surface.tags

    #
    # Check imported topographies
    #
    assert surface_copy.num_topographies() == surface.num_topographies()

    for tc, t in zip(surface_copy.topography_set.order_by('name'),
                     surface.topography_set.order_by('name')):

        #
        # Compare individual topographies
        #
        for attrname in [
                'name', 'description', 'size_x', 'size_y', 'height_scale',
                'measurement_date', 'unit', 'creator', 'data_source', 'tags'
        ]:
            assert getattr(tc, attrname) == getattr(t, attrname)
def test_warnings_for_different_arguments(client, handle_usage_statistics):
    user = UserFactory()
    surf1 = SurfaceFactory(creator=user)
    surf2 = SurfaceFactory(creator=user)
    topo1a = Topography1DFactory(surface=surf1)
    topo1b = Topography1DFactory(surface=surf1)
    topo2a = Topography1DFactory(surface=surf2)

    func = AnalysisFunctionFactory()
    topo_impl = AnalysisFunctionImplementationFactory(function=func,
                                                      subject_type=topo1a.get_content_type(),
                                                      code_ref='topography_analysis_function_for_tests')
    surf_impl = AnalysisFunctionImplementationFactory(function=func,
                                                      subject_type=surf1.get_content_type(),
                                                      code_ref='surface_analysis_function_for_tests')

    #
    # Generate analyses for topographies with differing arguments
    #
    kwargs_1a = pickle.dumps(dict(a=1, b=2))
    kwargs_1b = pickle.dumps(dict(a=1, b=3))  # differing from kwargs_1a!
    ana1a = TopographyAnalysisFactory(subject=topo1a, function=func, kwargs=kwargs_1a)
    ana1b = TopographyAnalysisFactory(subject=topo1b, function=func, kwargs=kwargs_1b)
    ana2a = TopographyAnalysisFactory(subject=topo2a, function=func)  # default arguments

    #
    # Generate analyses for surfaces with differing arguments
    #
    kwargs_1 = pickle.dumps(dict(a=1, c=2))
    kwargs_2 = pickle.dumps(dict(a=1, c=3))  # differing from kwargs_1a!
    ana1 = SurfaceAnalysisFactory(subject=surf1, function=func, kwargs=kwargs_1)
    ana2 = SurfaceAnalysisFactory(subject=surf2, function=func, kwargs=kwargs_2)

    client.force_login(user)

    #
    # request card, there should be warnings, one for topographies and one for surfaces
    #
    response = client.post(reverse("analysis:card"),
                           data={
                               'subjects_ids_json': subjects_to_json([topo1a, topo1b, topo2a, surf1, surf2]),
                               'function_id': func.id,
                               'card_id': "card-1",
                               'template_flavor': 'list'
                           },
                           HTTP_X_REQUESTED_WITH='XMLHttpRequest',
                           follow=True)

    assert response.status_code == 200

    assert_in_content(response,
                      "Arguments for this analysis function differ among chosen "
                      "subjects of type 'manager | topography'")
    assert_in_content(response,
                      "Arguments for this analysis function differ among chosen "
                      "subjects of type 'manager | surface'")
예제 #3
0
def test_is_sharing_with():

    user1 = UserFactory()
    user2 = UserFactory()

    assert not user1.is_sharing_with(user2)

    surface = SurfaceFactory(creator=user1)
    surface.share(user2)

    assert user1.is_sharing_with(user2)
예제 #4
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)
def test_instances():

    users = [UserFactory(username='******'), UserFactory(username='******')]

    surfaces = [
        SurfaceFactory(creator=users[0]),
        SurfaceFactory(creator=users[0]),
    ]

    topographies = [Topography1DFactory(surface=surfaces[0])]

    impl = AnalysisFunctionImplementationFactory()
    TopographyAnalysisFactory(function=impl.function, subject=topographies[0])

    return users, surfaces, topographies
예제 #6
0
def test_recalculate(client):

    user = UserFactory()
    surface = SurfaceFactory(creator=user)
    topo1 = Topography1DFactory(surface=surface)
    topo2 = Topography1DFactory(surface=surface)

    func = AnalysisFunctionFactory(name="test function")
    impl = AnalysisFunctionImplementationFactory(function=func)

    client.force_login(user)

    with transaction.atomic():
        # trigger "recalculate" for two topographies
        response = client.post(
            reverse('analysis:card-submit'), {
                'function_id': func.id,
                'subjects_ids_json': subjects_to_json([topo1, topo2]),
                'function_kwargs_json': '{}'
            },
            HTTP_X_REQUESTED_WITH='XMLHttpRequest')  # we need an AJAX request
        assert response.status_code == 200

    #
    # Analysis objects should be there and marked for the user
    #
    analysis1 = Analysis.objects.get(function=func, topography=topo1)
    analysis2 = Analysis.objects.get(function=func, topography=topo2)

    assert user in analysis1.users.all()
    assert user in analysis2.users.all()
예제 #7
0
def example_pub():
    """Fixture returning a publication which can be used as test example"""

    user = UserFactory()

    authors = "Alice, Bob"
    publication_date = datetime.date(2020, 1, 1)
    description = "This is a nice surface for testing."
    name = "Diamond Structure"

    surface = SurfaceFactory(name=name, creator=user, description=description)
    surface.tags = ['diamond']

    with freeze_time(publication_date):
        pub = surface.publish('cc0-1.0', authors)

    return pub
예제 #8
0
def stats_instances(db):
    user_1 = UserFactory()
    user_2 = UserFactory()
    surf_1A = SurfaceFactory(creator=user_1)
    surf_1B = SurfaceFactory(creator=user_1)
    surf_2A = SurfaceFactory(creator=user_2)
    topo_1Aa = Topography1DFactory(surface=surf_1A)
    topo_1Ab = Topography1DFactory(surface=surf_1A)
    topo_1Ba = Topography1DFactory(surface=surf_1B)
    topo_2Aa = Topography1DFactory(surface=surf_2A)
    func = AnalysisFunctionFactory()
    AnalysisFunctionImplementationFactory(function=func)
    TopographyAnalysisFactory(subject=topo_1Aa, function=func)
    TopographyAnalysisFactory(subject=topo_1Ab, function=func)
    TopographyAnalysisFactory(subject=topo_2Aa, function=func)

    return user_1, user_2, surf_1A
예제 #9
0
def items_for_selection(db, user_alice):

    tag1 = TagModelFactory(name="tag1")
    tag2 = TagModelFactory(name="tag2")

    surface1 = SurfaceFactory(creator=user_alice, name='surface1')
    topo1a = Topography1DFactory(surface=surface1, name='topo1a')
    topo1b = Topography1DFactory(surface=surface1,
                                 tags=[tag1, tag2],
                                 name='topo1b')

    surface2 = SurfaceFactory(creator=user_alice, tags=[tag1], name="surface2")
    topo2a = Topography1DFactory(surface=surface2, name='topo2a')

    return dict(tags=[tag1, tag2],
                surfaces=[surface1, surface2],
                topographies=[topo1a, topo1b, topo2a])
def items_for_filtering(db, user_alice, user_bob):

    tag1 = TagModelFactory(name='tag1')
    tag2 = TagModelFactory(name='tag2')

    surface1 = SurfaceFactory(name='surface1',
                              creator=user_alice,
                              category='exp',
                              description='apple')
    topo1a = Topography1DFactory(name='topo1a', surface=surface1)
    topo1b = Topography1DFactory(name='topo1b',
                                 surface=surface1,
                                 tags=[tag1, tag2])

    surface2 = SurfaceFactory(name='surface2',
                              creator=user_alice,
                              category='dum',
                              tags=[tag1],
                              description='banana')
    topo2a = Topography1DFactory(name='topo2a', surface=surface2)

    surface3 = SurfaceFactory(name='surface3',
                              creator=user_bob,
                              category='sim',
                              description='cherry')
    topo3a = Topography1DFactory(name='topo3a', surface=surface3)

    surface3.share(user_alice)

    return dict(tags=[tag1, tag2],
                surfaces=[surface1, surface2, surface3],
                topographies=[topo1a, topo1b, topo2a, topo3a])
예제 #11
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
예제 #12
0
def test_renewal_on_topography_detrend_mode_change(client, mocker, django_capture_on_commit_callbacks):
    """Check whether thumbnail is renewed if detrend mode changes for a topography
    """

    from ..models import Topography
    renew_squeezed_mock = mocker.patch('topobank.manager.views.renew_squeezed_datafile.si')
    renew_topo_analyses_mock = mocker.patch('topobank.manager.views.renew_analyses_related_to_topography.si')
    renew_topo_images_mock = mocker.patch('topobank.manager.views.renew_topography_images.si')

    user = UserFactory()
    surface = SurfaceFactory(creator=user)
    topo = Topography1DFactory(surface=surface, size_y=1, detrend_mode='center')

    client.force_login(user)

    with django_capture_on_commit_callbacks(execute=True) as callbacks:
        response = client.post(reverse('manager:topography-update', kwargs=dict(pk=topo.pk)),
                               data={
                                   'save-stay': 1,  # we want to save, but stay on page
                                   'surface': surface.pk,
                                   'data_source': 0,
                                   'name': topo.name,
                                   'measurement_date': topo.measurement_date,
                                   'description': "something",
                                   'size_x': 1,
                                   'size_y': 1,
                                   'unit': 'nm',
                                   'height_scale': 1,
                                   'detrend_mode': 'height',
                                   'instrument_type': Topography.INSTRUMENT_TYPE_UNDEFINED,
                                   'has_undefined_data': False,
                                   'fill_undefined_data_mode': Topography.FILL_UNDEFINED_DATA_MODE_NOFILLING,
                               }, follow=True)

    # we just check here that the form is filled completely, otherwise the thumbnail would not be recreated too
    assert_no_form_errors(response)
    assert response.status_code == 200
    assert len(callbacks) == 1  # single chain for squeezed file, thumbnail and for analyses
    assert renew_topo_images_mock.called
    assert renew_topo_analyses_mock.called
    assert renew_squeezed_mock.called  # was directly called, not as callback from commit
def two_analyses_two_publications():
    surface1 = SurfaceFactory()
    Topography1DFactory(surface=surface1)
    surface2 = SurfaceFactory()
    Topography1DFactory(surface=surface2)
    pub1 = surface1.publish('cc0-1.0', surface1.creator.name)
    pub2 = surface2.publish('cc0-1.0', surface1.creator.name + ", " + surface2.creator.name)
    pub_topo1 = pub1.surface.topography_set.first()
    pub_topo2 = pub2.surface.topography_set.first()

    func = AnalysisFunctionFactory()
    AnalysisFunctionImplementationFactory(function=func)
    analysis1 = TopographyAnalysisFactory(subject=pub_topo1, function=func)
    analysis2 = TopographyAnalysisFactory(subject=pub_topo2, function=func)

    return analysis1, analysis2, pub1, pub2
예제 #14
0
def test_sheets(client, handle_usage_statistics):

    user = UserFactory()
    surface = SurfaceFactory(creator=user)
    topo1 = Topography2DFactory(surface=surface)
    topo2 = Topography2DFactory(surface=surface)

    save_landing_page_statistics(
    )  # save current state for users, surfaces, ..

    client.force_login(user)  # not counted as login here

    client.get(reverse('manager:surface-detail', kwargs=dict(pk=surface.pk)))
    # Now there is one surface view

    # tried to use freezegun.freeze_time here,
    # but openpyxl had problems with FakeDate class
    call_command('export_usage_statistics')

    df = pd.read_excel("usage_statistics.xlsx",
                       sheet_name="summary",
                       engine='openpyxl')
    assert df.columns[0] == 'month'
    assert df.iloc[0, 1:].tolist() == [0, 1, 0, 0, 1, 1, 2, 0]
예제 #15
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")
예제 #16
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
예제 #17
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")
예제 #18
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)
예제 #19
0
def test_plot_card_if_no_successful_topo_analysis(client,
                                                  handle_usage_statistics):
    #
    # Create database objects
    #
    password = "******"
    user = UserFactory(password=password)
    topography_ct = ContentType.objects.get_for_model(Topography)
    surface_ct = ContentType.objects.get_for_model(Surface)
    func1 = AnalysisFunctionFactory(card_view_flavor='power spectrum')
    AnalysisFunctionImplementationFactory(function=func1,
                                          subject_type=topography_ct)
    AnalysisFunctionImplementationFactory(function=func1,
                                          subject_type=surface_ct)

    surf = SurfaceFactory(creator=user)
    topo = Topography1DFactory(surface=surf)  # also generates the surface

    # There is a successful surface analysis, but no successful topography analysis
    SurfaceAnalysisFactory(task_state='su',
                           subject_id=topo.surface.id,
                           subject_type_id=surface_ct.id,
                           function=func1,
                           users=[user])

    # add a failed analysis for the topography
    TopographyAnalysisFactory(task_state='fa',
                              subject_id=topo.id,
                              subject_type_id=topography_ct.id,
                              function=func1,
                              users=[user])

    assert Analysis.objects.filter(function=func1,
                                   subject_id=topo.id,
                                   subject_type_id=topography_ct.id,
                                   task_state='su').count() == 0
    assert Analysis.objects.filter(function=func1,
                                   subject_id=topo.id,
                                   subject_type_id=topography_ct.id,
                                   task_state='fa').count() == 1
    assert Analysis.objects.filter(function=func1,
                                   subject_id=topo.surface.id,
                                   subject_type_id=surface_ct.id,
                                   task_state='su').count() == 1

    # login and request plot card view
    assert client.login(username=user.username, password=password)

    response = client.post(
        reverse('analysis:card'),
        data={
            'function_id': func1.id,
            'card_id': 'card',
            'template_flavor': 'list',
            'subjects_ids_json':
            subjects_to_json([topo, topo.surface
                              ]),  # also request results for surface here
        },
        HTTP_X_REQUESTED_WITH='XMLHttpRequest')  # we need an AJAX request

    # should return without errors
    assert response.status_code == 200
def test_view_shared_analysis_results(client, handle_usage_statistics):
    password = '******'

    #
    # create database objects
    #
    user1 = UserFactory(password=password)
    user2 = UserFactory(password=password)

    surface1 = SurfaceFactory(creator=user1)
    surface2 = SurfaceFactory(creator=user2)

    # create topographies + functions + analyses
    func1 = AnalysisFunctionFactory()
    impl1 = AnalysisFunctionImplementationFactory(function=func1)
    # func2 = AnalysisFunctionFactory()

    # Two topographies for surface1
    topo1a = Topography1DFactory(surface=surface1, name='topo1a')
    topo1b = Topography1DFactory(surface=surface1, name='topo1b')

    # One topography for surface2
    topo2a = Topography1DFactory(surface=surface2, name='topo2a')

    # analyses, differentiate by start time
    analysis1a_1 = TopographyAnalysisFactory(subject=topo1a, function=func1,
                                             start_time=datetime.datetime(2019, 1, 1, 12))
    analysis1b_1 = TopographyAnalysisFactory(subject=topo1b, function=func1,
                                             start_time=datetime.datetime(2019, 1, 1, 13))
    analysis2a_1 = TopographyAnalysisFactory(subject=topo2a, function=func1,
                                             start_time=datetime.datetime(2019, 1, 1, 14))

    # Function should have three analyses, all successful (the default when using the factory)
    assert func1.analysis_set.count() == 3
    assert all(a.task_state == 'su' for a in func1.analysis_set.all())

    # user2 shares surfaces, so user 1 should see surface1+surface2
    surface2.share(user1)

    #
    # Now we change to the analysis card view and look what we get
    #
    assert client.login(username=user1.username, password=password)

    response = client.post(reverse("analysis:card"),
                           data={
                               'subjects_ids_json': subjects_to_json([topo1a, topo1b, topo2a]),
                               'function_id': func1.id,
                               'card_id': 1,
                               'template_flavor': 'list'
                           },
                           HTTP_X_REQUESTED_WITH='XMLHttpRequest',
                           follow=True)

    # Function should still have three analyses, all successful (the default when using the factory)
    assert func1.analysis_set.count() == 3
    assert all(a.task_state == 'su' for a in func1.analysis_set.all())

    assert response.status_code == 200

    # We should see start times of all three topographies
    assert_in_content(response, '2019-01-01 12:00:00')  # topo1a
    assert_in_content(response, '2019-01-01 13:00:00')  # topo1b
    assert_in_content(response, '2019-01-01 14:00:00')  # topo2a

    client.logout()

    #
    # user 2 cannot access results from topo1, it is not shared
    #
    assert client.login(username=user2.username, password=password)

    response = client.post(reverse("analysis:card"),
                           data={
                               'subjects_ids_json': subjects_to_json([topo1a, topo1b, topo2a]),
                               'function_id': func1.id,
                               'card_id': 1,
                               'template_flavor': 'list'
                           },
                           HTTP_X_REQUESTED_WITH='XMLHttpRequest',
                           follow=True)

    assert response.status_code == 200

    assert_not_in_content(response, '2019-01-01 12:00:00')  # topo1a
    assert_not_in_content(response, '2019-01-01 13:00:00')  # topo1b
    assert_in_content(response, '2019-01-01 14:00:00')  # topo2a

    client.logout()
예제 #21
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