Exemplo n.º 1
0
    def test_organization_filter_views(self, client, factory):
        org = OrganizationFactory()
        u = UserFactory()
        org.add_member(u)

        try:
            obj = factory(public=True)
        except TypeError:
            # TODO For challenges, hidden needs to be refactored to public
            obj = factory(hidden=False)

        obj.organizations.set([OrganizationFactory()])

        def _get_org_detail():
            return get_view_for_user(
                client=client,
                viewname="organizations:detail",
                reverse_kwargs={"slug": org.slug},
                user=u,
            )

        response = _get_org_detail()
        assert response.status_code == 200
        assert {*response.context[-1]["object_list"]} == set()

        obj.organizations.add(org)

        response = _get_org_detail()
        assert response.status_code == 200
        assert {*response.context[-1]["object_list"]} == {obj}
Exemplo n.º 2
0
    def test_organization_display(self, client):
        u1 = UserFactory()
        u2 = UserFactory()
        org1 = OrganizationFactory()
        org2 = OrganizationFactory()
        org1.add_member(u1)

        assert org1.is_member(u1)
        assert not org2.is_member(u1)
        assert not org1.is_member(u2)
        assert not org2.is_member(u2)

        response = get_view_for_user(
            viewname="profile-detail",
            client=client,
            user=u1,
            reverse_kwargs={"username": u1.username},
        )
        assert len(response.context[-1]["organizations"]) == 1
        assert org1.title in response.content.decode()
        assert org2.title not in response.content.decode()

        response = get_view_for_user(
            viewname="profile-detail",
            client=client,
            user=u2,
            reverse_kwargs={"username": u2.username},
        )
        assert len(response.context[-1]["organizations"]) == 0
        assert "Organizations" not in response.content.decode()
        u1.user_profile.display_organizations = False
        u1.user_profile.save()

        response = get_view_for_user(
            viewname="profile-detail",
            client=client,
            user=u1,
            reverse_kwargs={"username": u1.username},
        )

        assert org1.title not in response.content.decode()
Exemplo n.º 3
0
    def test_organization_update(self, client):
        u1 = UserFactory()
        org1 = OrganizationFactory()
        org1.add_member(u1)

        response = get_view_for_user(
            viewname="profile-detail",
            client=client,
            user=u1,
            reverse_kwargs={"username": u1.username},
        )

        assert org1.title in response.content.decode()

        _ = get_view_for_user(
            viewname="profile-update",
            client=client,
            method=client.post,
            user=u1,
            reverse_kwargs={"username": u1.username},
            data={
                "first_name": "Firstname",
                "last_name": "Lastname",
                "institution": "Institution",
                "department": "Department",
                "country": "NL",
                "display_organizations": False,
            },
        )

        u1.user_profile.refresh_from_db()

        response = get_view_for_user(
            viewname="profile-detail",
            client=client,
            user=u1,
            reverse_kwargs={"username": u1.username},
        )

        assert org1.title not in response.content.decode()