Esempio n. 1
0
def test_wiki_page_update(client, data):
    public_url = reverse('wiki-detail',
                         kwargs={"pk": data.public_wiki_page.pk})
    private_url1 = reverse('wiki-detail',
                           kwargs={"pk": data.private_wiki_page1.pk})
    private_url2 = reverse('wiki-detail',
                           kwargs={"pk": data.private_wiki_page2.pk})

    users = [
        None, data.registered_user, data.project_member_without_perms,
        data.project_member_with_perms, data.project_owner
    ]

    with mock.patch.object(OCCResourceMixin, "_validate_and_update_version"):
        wiki_page_data = WikiPageSerializer(data.public_wiki_page).data
        wiki_page_data["content"] = "test"
        wiki_page_data = json.dumps(wiki_page_data)
        results = helper_test_http_method(client, 'put', public_url,
                                          wiki_page_data, users)
        assert results == [401, 200, 200, 200, 200]

        wiki_page_data = WikiPageSerializer(data.private_wiki_page1).data
        wiki_page_data["content"] = "test"
        wiki_page_data = json.dumps(wiki_page_data)
        results = helper_test_http_method(client, 'put', private_url1,
                                          wiki_page_data, users)
        assert results == [401, 200, 200, 200, 200]

        wiki_page_data = WikiPageSerializer(data.private_wiki_page2).data
        wiki_page_data["content"] = "test"
        wiki_page_data = json.dumps(wiki_page_data)
        results = helper_test_http_method(client, 'put', private_url2,
                                          wiki_page_data, users)
        assert results == [401, 403, 403, 200, 200]
Esempio n. 2
0
    def _search_wiki_pages(self, project, text, get_all):
        where_clause = (
            "to_tsvector(wiki_wikipage.slug || wiki_wikipage.content) "
            "@@ plainto_tsquery(%s)")

        model_cls = get_model("wiki", "WikiPage")
        if get_all != "false" and text == '':
            queryset = model_cls.objects.filter(project_id=project.pk)
        else:
            queryset = (model_cls.objects.extra(
                where=[where_clause],
                params=[text]).filter(project_id=project.pk)[:50])

        serializer = WikiPageSerializer(queryset, many=True)
        return serializer.data
Esempio n. 3
0
def test_wiki_page_put_update_with_project_change(client):
    user1 = f.UserFactory.create()
    user2 = f.UserFactory.create()
    user3 = f.UserFactory.create()
    user4 = f.UserFactory.create()
    project1 = f.ProjectFactory()
    project2 = f.ProjectFactory()

    membership1 = f.MembershipFactory(project=project1,
                                      user=user1,
                                      role__project=project1,
                                      role__permissions=list(
                                          map(lambda x: x[0],
                                              MEMBERS_PERMISSIONS)))
    membership2 = f.MembershipFactory(project=project2,
                                      user=user1,
                                      role__project=project2,
                                      role__permissions=list(
                                          map(lambda x: x[0],
                                              MEMBERS_PERMISSIONS)))
    membership3 = f.MembershipFactory(project=project1,
                                      user=user2,
                                      role__project=project1,
                                      role__permissions=list(
                                          map(lambda x: x[0],
                                              MEMBERS_PERMISSIONS)))
    membership4 = f.MembershipFactory(project=project2,
                                      user=user3,
                                      role__project=project2,
                                      role__permissions=list(
                                          map(lambda x: x[0],
                                              MEMBERS_PERMISSIONS)))

    wiki_page = f.WikiPageFactory.create(project=project1)

    url = reverse('wiki-detail', kwargs={"pk": wiki_page.pk})

    # Test user with permissions in both projects
    client.login(user1)

    wiki_page_data = WikiPageSerializer(wiki_page).data
    wiki_page_data["project"] = project2.id
    wiki_page_data = json.dumps(wiki_page_data)

    response = client.put(url,
                          data=wiki_page_data,
                          content_type="application/json")

    assert response.status_code == 200

    wiki_page.project = project1
    wiki_page.save()

    # Test user with permissions in only origin project
    client.login(user2)

    wiki_page_data = WikiPageSerializer(wiki_page).data
    wiki_page_data["project"] = project2.id
    wiki_page_data = json.dumps(wiki_page_data)

    response = client.put(url,
                          data=wiki_page_data,
                          content_type="application/json")

    assert response.status_code == 403

    wiki_page.project = project1
    wiki_page.save()

    # Test user with permissions in only destionation project
    client.login(user3)

    wiki_page_data = WikiPageSerializer(wiki_page).data
    wiki_page_data["project"] = project2.id
    wiki_page_data = json.dumps(wiki_page_data)

    response = client.put(url,
                          data=wiki_page_data,
                          content_type="application/json")

    assert response.status_code == 403

    wiki_page.project = project1
    wiki_page.save()

    # Test user without permissions in the projects
    client.login(user4)

    wiki_page_data = WikiPageSerializer(wiki_page).data
    wiki_page_data["project"] = project2.id
    wiki_page_data = json.dumps(wiki_page_data)

    response = client.put(url,
                          data=wiki_page_data,
                          content_type="application/json")

    assert response.status_code == 403

    wiki_page.project = project1
    wiki_page.save()
Esempio n. 4
0
 def _search_wiki_pages(self, project, text):
     queryset = services.search_wiki_pages(project, text)
     serializer = WikiPageSerializer(queryset, many=True)
     return serializer.data