Beispiel #1
0
def test_contact_set_is_active(rf, admin_user):
    get_default_shop()
    contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
    assert contact.is_active

    request = apply_request_middleware(rf.post("/", {"set_is_active": "0"}), user=admin_user)
    view_func = ContactDetailView.as_view()
    response = view_func(request, pk=contact.pk)
    assert response.status_code < 500 and not Contact.objects.get(pk=contact.pk).is_active

    request = apply_request_middleware(rf.post("/", {"set_is_active": "1"}), user=admin_user)
    view_func = ContactDetailView.as_view()
    response = view_func(request, pk=contact.pk)
    assert response.status_code < 500 and Contact.objects.get(pk=contact.pk).is_active
Beispiel #2
0
def test_contact_set_is_active(rf, admin_user):
    get_default_shop()
    contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
    assert contact.is_active

    request = apply_request_middleware(rf.post("/", {"set_is_active": "0"}), user=admin_user)
    view_func = ContactDetailView.as_view()
    response = view_func(request, pk=contact.pk)
    assert response.status_code < 500 and not Contact.objects.get(pk=contact.pk).is_active

    request = apply_request_middleware(rf.post("/", {"set_is_active": "1"}), user=admin_user)
    view_func = ContactDetailView.as_view()
    response = view_func(request, pk=contact.pk)
    assert response.status_code < 500 and Contact.objects.get(pk=contact.pk).is_active
Beispiel #3
0
def test_contact_details_view_with_many_groups(rf, admin_user):
    get_default_shop()
    person = create_random_person()
    person.groups.add(
        ContactGroup.objects.create(name="Czz Group"),
        ContactGroup.objects.create(name="Azz Group"),
        ContactGroup.objects.create(name="Bzz Group"),
        ContactGroup.objects.language('fi').create(name="Dzz ryhmä"),
    )

    # Group with name in two languages
    grp_e = ContactGroup.objects.language('en').create(name="Ezz Group")
    grp_e.set_current_language('fi')
    grp_e.name = "Ezz ryhmä"
    grp_e.save()
    person.groups.add(grp_e)

    request = apply_request_middleware(rf.get("/"), user=admin_user)
    with translation.override('en'):
        view_func = ContactDetailView.as_view()
        response = view_func(request, pk=person.pk)
    content = response.render().content.decode('utf-8')
    assert "Azz Group" in content
    assert "Bzz Group" in content
    assert "Czz Group" in content
    assert "Dzz ryhmä" in content, "no name in active language, still present"
    assert "Ezz Group" in content, "rendered with active language"
    positions = [content.index(x + "zz ") for x in 'ABCDE']
    assert positions == sorted(positions), "Groups are sorted"
    assert response.status_code == 200
Beispiel #4
0
def test_contact_details_view_with_many_groups(rf, admin_user):
    get_default_shop()
    person = create_random_person()
    person.groups.add(
        ContactGroup.objects.create(name="Czz Group"),
        ContactGroup.objects.create(name="Azz Group"),
        ContactGroup.objects.create(name="Bzz Group"),
        ContactGroup.objects.language('fi').create(name="Dzz ryhmä"),
    )

    # Group with name in two languages
    grp_e = ContactGroup.objects.language('en').create(name="Ezz Group")
    grp_e.set_current_language('fi')
    grp_e.name = "Ezz ryhmä"
    grp_e.save()
    person.groups.add(grp_e)

    request = apply_request_middleware(rf.get("/"), user=admin_user)
    with translation.override('en'):
        view_func = ContactDetailView.as_view()
        response = view_func(request, pk=person.pk)
    content = response.render().content.decode('utf-8')
    assert "Azz Group" in content
    assert "Bzz Group" in content
    assert "Czz Group" in content
    assert "Dzz ryhmä" in content, "no name in active language, still present"
    assert "Ezz Group" in content, "rendered with active language"
    positions = [content.index(x + "zz ") for x in 'ABCDE']
    assert positions == sorted(positions), "Groups are sorted"
    assert response.status_code == 200
def test_contact_detail_has_custom_toolbar_button(rf, admin_user):
    get_default_shop()
    contact = create_random_person(locale="en_US", minimum_name_comp_len=5)

    request = apply_request_middleware(rf.get("/"), user=admin_user)
    view_func = ContactDetailView.as_view()
    response = view_func(request, pk=contact.pk)
    content = force_text(response.render().content)
    assert "#mocktoolbarbutton" in content, 'custom toolbar button not found on detail page'
def test_contact_detail_has_custom_section(rf, admin_user):
    get_default_shop()
    contact = create_random_person(locale="en_US", minimum_name_comp_len=5)

    request = apply_request_middleware(rf.get("/"), user=admin_user)
    view_func = ContactDetailView.as_view()
    response = view_func(request, pk=contact.pk)
    content = force_text(response.render().content)

    assert "mock section title" in content, "custom section title not found on detail page"
    assert "mock section content" in content, "custom section content not found on detail page"
    assert "mock section context data" in content, "custom section context data not found on detail page"
def test_contact_detail_has_custom_section(rf, admin_user):
    get_default_shop()
    contact = create_random_person(locale="en_US", minimum_name_comp_len=5)

    request = apply_request_middleware(rf.get("/"), user=admin_user)
    view_func = ContactDetailView.as_view()
    response = view_func(request, pk=contact.pk)
    content = force_text(response.render().content)

    assert "mock section title" in content, "custom section title not found on detail page"
    assert "mock section content" in content, "custom section content not found on detail page"
    assert "mock section context data" in content, "custom section context data not found on detail page"
def test_contact_detail_has_mocked_toolbar_action_items(rf, admin_user):
    get_default_shop()
    contact = create_random_person(locale="en_US", minimum_name_comp_len=5)

    request = apply_request_middleware(rf.get("/"), user=admin_user)
    view_func = ContactDetailView.as_view()
    with override_provides("admin_contact_toolbar_action_item", [
        "shuup.testing.admin_module.toolbar:MockContactToolbarActionItem"
    ]):
        assert _check_if_mock_action_item_exists(view_func, request, contact)

    with override_provides("admin_contact_toolbar_action_item", []):
        assert not _check_if_mock_action_item_exists(view_func, request, contact)
Beispiel #9
0
def test_admin_contact_edit(rf, admin_user):
    shop = get_default_shop()
    admin_contact = get_person_contact(admin_user)

    staff = create_random_user(is_staff=True)
    shop.staff_members.add(staff)
    view_func = ContactDetailView.as_view()

    # non superuser can't edit superuser's contacts
    with pytest.raises(Http404):
        request = apply_request_middleware(rf.get("/"), user=staff)
        response = view_func(request, pk=admin_contact.pk)

    # superuser can
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = view_func(request, pk=admin_contact.pk)
    assert response.status_code == 200
Beispiel #10
0
def test_admin_contact_edit(rf, admin_user):
    shop = get_default_shop()
    admin_contact = get_person_contact(admin_user)

    staff = create_random_user(is_staff=True)
    shop.staff_members.add(staff)
    view_func = ContactDetailView.as_view()

    # non superuser can't edit superuser's contacts
    with pytest.raises(Http404):
        request = apply_request_middleware(rf.get("/"), user=staff)
        response = view_func(request, pk=admin_contact.pk)

    # superuser can
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = view_func(request, pk=admin_contact.pk)
    assert response.status_code == 200