Example #1
0
def test_issue_update(client, data):
    public_url = reverse('issues-detail', kwargs={"pk": data.public_issue.pk})
    private_url1 = reverse('issues-detail',
                           kwargs={"pk": data.private_issue1.pk})
    private_url2 = reverse('issues-detail',
                           kwargs={"pk": data.private_issue2.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"):
        issue_data = IssueSerializer(data.public_issue).data
        issue_data["subject"] = "test"
        issue_data = json.dumps(issue_data)
        results = helper_test_http_method(client, 'put', public_url,
                                          issue_data, users)
        assert results == [401, 403, 403, 200, 200]

        issue_data = IssueSerializer(data.private_issue1).data
        issue_data["subject"] = "test"
        issue_data = json.dumps(issue_data)
        results = helper_test_http_method(client, 'put', private_url1,
                                          issue_data, users)
        assert results == [401, 403, 403, 200, 200]

        issue_data = IssueSerializer(data.private_issue2).data
        issue_data["subject"] = "test"
        issue_data = json.dumps(issue_data)
        results = helper_test_http_method(client, 'put', private_url2,
                                          issue_data, users)
        assert results == [401, 403, 403, 200, 200]
Example #2
0
def test_watchers_assignation_for_issue(client):
    user1 = f.UserFactory.create()
    user2 = f.UserFactory.create()
    project1 = f.ProjectFactory.create(owner=user1)
    project2 = f.ProjectFactory.create(owner=user2)
    role1 = f.RoleFactory.create(project=project1)
    role2 = f.RoleFactory.create(project=project2)
    member1 = f.MembershipFactory.create(project=project1,
                                         user=user1,
                                         role=role1,
                                         is_owner=True)
    member2 = f.MembershipFactory.create(project=project2,
                                         user=user2,
                                         role=role2)

    client.login(user1)

    issue = f.create_issue(project=project1, owner=user1)
    data = {"version": issue.version, "watchers": [user1.pk]}

    url = reverse("issues-detail", args=[issue.pk])
    response = client.json.patch(url, json.dumps(data))
    assert response.status_code == 200, response.content

    issue = f.create_issue(project=project1, owner=user1)
    data = {"version": issue.version, "watchers": [user1.pk, user2.pk]}

    url = reverse("issues-detail", args=[issue.pk])
    response = client.json.patch(url, json.dumps(data))
    assert response.status_code == 400

    issue = f.create_issue(project=project1, owner=user1)
    data = dict(IssueSerializer(issue).data)
    data["id"] = None
    data["version"] = None
    data["watchers"] = [user1.pk, user2.pk]

    url = reverse("issues-list")
    response = client.json.post(url, json.dumps(data))
    assert response.status_code == 400

    # Test the impossible case when project is not
    # exists in create request, and validator works as expected
    issue = f.create_issue(project=project1, owner=user1)
    data = dict(IssueSerializer(issue).data)

    data["id"] = None
    data["watchers"] = [user1.pk, user2.pk]
    data["project"] = None

    url = reverse("issues-list")
    response = client.json.post(url, json.dumps(data))
    assert response.status_code == 400
Example #3
0
    def _search_issues(self, project, text, get_all):
        where_clause = (
            "to_tsvector(issues_issue.subject || issues_issue.description) "
            "@@ plainto_tsquery(%s)")

        model_cls = get_model("issues", "Issue")
        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 = IssueSerializer(queryset, many=True)
        return serializer.data
Example #4
0
 def _search_issues(self, project, text):
     queryset = services.search_issues(project, text)
     serializer = IssueSerializer(queryset, many=True)
     return serializer.data
def test_issue_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()

    issue_status1 = f.IssueStatusFactory.create(project=project1)
    issue_status2 = f.IssueStatusFactory.create(project=project2)

    priority1 = f.PriorityFactory.create(project=project1)
    priority2 = f.PriorityFactory.create(project=project2)

    severity1 = f.SeverityFactory.create(project=project1)
    severity2 = f.SeverityFactory.create(project=project2)

    issue_type1 = f.IssueTypeFactory.create(project=project1)
    issue_type2 = f.IssueTypeFactory.create(project=project2)

    project1.default_issue_status = issue_status1
    project2.default_issue_status = issue_status2

    project1.default_priority = priority1
    project2.default_priority = priority2

    project1.default_severity = severity1
    project2.default_severity = severity2

    project1.default_issue_type = issue_type1
    project2.default_issue_type = issue_type2

    project1.save()
    project2.save()

    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)))

    issue = f.IssueFactory.create(project=project1)

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

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

    issue_data = IssueSerializer(issue).data
    issue_data["project"] = project2.id
    issue_data = json.dumps(issue_data)

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

    assert response.status_code == 200

    issue.project = project1
    issue.save()

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

    issue_data = IssueSerializer(issue).data
    issue_data["project"] = project2.id
    issue_data = json.dumps(issue_data)

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

    assert response.status_code == 403

    issue.project = project1
    issue.save()

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

    issue_data = IssueSerializer(issue).data
    issue_data["project"] = project2.id
    issue_data = json.dumps(issue_data)

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

    assert response.status_code == 403

    issue.project = project1
    issue.save()

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

    issue_data = IssueSerializer(issue).data
    issue_data["project"] = project2.id
    issue_data = json.dumps(issue_data)

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

    assert response.status_code == 403

    issue.project = project1
    issue.save()