Ejemplo n.º 1
0
    def upvote(self, request, pk=None):
        obj = self.get_object()
        self.check_permissions(request, "upvote", obj)
        self.pre_conditions_on_save(obj)

        services.add_vote(obj, user=request.user)
        return response.Ok()
Ejemplo n.º 2
0
def test_promote_task_to_us(client):
    user_1 = f.UserFactory.create()
    user_2 = f.UserFactory.create()
    project = f.ProjectFactory.create(owner=user_1)
    f.MembershipFactory.create(project=project, user=user_1, is_admin=True)
    f.MembershipFactory.create(project=project, user=user_2, is_admin=False)
    task = f.TaskFactory.create(project=project, owner=user_1, assigned_to=user_2)
    task.add_watcher(user_1)
    task.add_watcher(user_2)
    add_vote(task, user_1)
    add_vote(task, user_2)

    f.TaskAttachmentFactory(project=project, content_object=task, owner=user_1)

    f.HistoryEntryFactory.create(
        project=project,
        user={"pk": user_1.id},
        comment="Test comment",
        key="tasks.task:{}".format(task.id),
        is_hidden=False,
        diff=[],
    )

    f.HistoryEntryFactory.create(
        project=project,
        user={"pk": user_2.id},
        comment="Test comment 2",
        key="tasks.task:{}".format(task.id),
        is_hidden=False,
        diff=[]
    )

    client.login(user_1)

    url = reverse('tasks-promote-to-user-story', kwargs={"pk": task.pk})
    data = {"project_id": project.id}
    promote_response = client.json.post(url, json.dumps(data))

    us_ref = promote_response.data.pop()
    us = UserStory.objects.get(ref=us_ref)
    us_response = client.get(reverse("userstories-detail", args=[us.pk]),
                             {"include_attachments": True})

    assert promote_response.status_code == 200, promote_response.data
    assert us_response.data["subject"] == task.subject
    assert us_response.data["description"] == task.description
    assert us_response.data["owner"] == task.owner_id
    assert us_response.data["generated_from_task"] == None
    assert us_response.data["assigned_users"] == {user_2.id}
    assert us_response.data["total_watchers"] == 2
    assert us_response.data["total_attachments"] == 1
    assert us_response.data["total_comments"] == 2
    assert us_response.data["due_date"] == task.due_date
    assert us_response.data["is_blocked"] == task.is_blocked
    assert us_response.data["blocked_note"] == task.blocked_note
    assert us_response.data["total_voters"] == 2

    # check if task is deleted
    assert us_response.data["from_task_ref"] == us.from_task_ref
    assert not Task.objects.filter(pk=task.id).exists()
Ejemplo n.º 3
0
    def upvote(self, request, pk=None):
        issue = get_object_or_404(models.Issue, pk=pk)

        self.check_permissions(request, 'upvote', issue)

        votes_service.add_vote(issue, user=request.user)
        return response.Ok()
Ejemplo n.º 4
0
    def upvote(self, request, pk=None):
        issue = get_object_or_404(models.Issue, pk=pk)

        self.check_permissions(request, 'upvote', issue)

        votes_service.add_vote(issue, user=request.user)
        return Response(status=status.HTTP_200_OK)
Ejemplo n.º 5
0
    def upvote(self, request, pk=None):
        obj = self.get_object()
        self.check_permissions(request, "upvote", obj)
        self.pre_conditions_on_save(obj)

        services.add_vote(obj, user=request.user)
        return response.Ok()
Ejemplo n.º 6
0
def test_add_vote():
    project = f.ProjectFactory()
    project_type = ContentType.objects.get_for_model(project)
    user = f.UserFactory()
    votes_qs = models.Votes.objects.filter(content_type=project_type, object_id=project.id)

    votes.add_vote(project, user)

    assert votes_qs.get().count == 1

    votes.add_vote(project, user)  # add_vote must be idempotent

    assert votes_qs.get().count == 1
Ejemplo n.º 7
0
def test_add_vote():
    project = f.ProjectFactory()
    project_type = ContentType.objects.get_for_model(project)
    user = f.UserFactory()
    votes_qs = models.Votes.objects.filter(content_type=project_type, object_id=project.id)

    votes.add_vote(project, user)

    assert votes_qs.get().count == 1

    votes.add_vote(project, user)  # add_vote must be idempotent

    assert votes_qs.get().count == 1
Ejemplo n.º 8
0
def test_user_story_voters_retrieve(client, data):
    add_vote(data.public_user_story, data.project_owner)
    public_url = reverse('userstory-voters-detail', kwargs={"resource_id": data.public_user_story.pk,
                                                            "pk": data.project_owner.pk})
    add_vote(data.private_user_story1, data.project_owner)
    private_url1 = reverse('userstory-voters-detail', kwargs={"resource_id": data.private_user_story1.pk,
                                                              "pk": data.project_owner.pk})
    add_vote(data.private_user_story2, data.project_owner)
    private_url2 = reverse('userstory-voters-detail', kwargs={"resource_id": data.private_user_story2.pk,
                                                              "pk": data.project_owner.pk})

    add_vote(data.blocked_user_story, data.project_owner)
    blocked_url = reverse('userstory-voters-detail', kwargs={"resource_id": data.blocked_user_story.pk,
                                                              "pk": data.project_owner.pk})
    users = [
        None,
        data.registered_user,
        data.project_member_without_perms,
        data.project_member_with_perms,
        data.project_owner
    ]

    results = helper_test_http_method(client, 'get', public_url, None, users)
    assert results == [200, 200, 200, 200, 200]
    results = helper_test_http_method(client, 'get', private_url1, None, users)
    assert results == [200, 200, 200, 200, 200]
    results = helper_test_http_method(client, 'get', private_url2, None, users)
    assert results == [401, 403, 403, 200, 200]
    results = helper_test_http_method(client, 'get', blocked_url, None, users)
    assert results == [401, 403, 403, 200, 200]
Ejemplo n.º 9
0
def test_issue_voters_retrieve(client, data):
    add_vote(data.public_issue, data.project_owner)
    public_url = reverse('issue-voters-detail',
                         kwargs={
                             "issue_id": data.public_issue.pk,
                             "pk": data.project_owner.pk
                         })
    add_vote(data.private_issue1, data.project_owner)
    private_url1 = reverse('issue-voters-detail',
                           kwargs={
                               "issue_id": data.private_issue1.pk,
                               "pk": data.project_owner.pk
                           })
    add_vote(data.private_issue2, data.project_owner)
    private_url2 = reverse('issue-voters-detail',
                           kwargs={
                               "issue_id": data.private_issue2.pk,
                               "pk": data.project_owner.pk
                           })

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

    results = helper_test_http_method(client, 'get', public_url, None, users)
    assert results == [200, 200, 200, 200, 200]

    results = helper_test_http_method(client, 'get', private_url1, None, users)
    assert results == [200, 200, 200, 200, 200]

    results = helper_test_http_method(client, 'get', private_url2, None, users)
    assert results == [401, 403, 403, 200, 200]
Ejemplo n.º 10
0
def test_issue_voters_retrieve(client, data):
    add_vote(data.public_issue, data.project_owner)
    public_url = reverse('issue-voters-detail', kwargs={"issue_id": data.public_issue.pk, "pk": data.project_owner.pk})
    add_vote(data.private_issue1, data.project_owner)
    private_url1 = reverse('issue-voters-detail', kwargs={"issue_id": data.private_issue1.pk, "pk": data.project_owner.pk})
    add_vote(data.private_issue2, data.project_owner)
    private_url2 = reverse('issue-voters-detail', kwargs={"issue_id": data.private_issue2.pk, "pk": data.project_owner.pk})

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

    results = helper_test_http_method(client, 'get', public_url, None, users)
    assert results == [200, 200, 200, 200, 200]

    results = helper_test_http_method(client, 'get', private_url1, None, users)
    assert results == [200, 200, 200, 200, 200]

    results = helper_test_http_method(client, 'get', private_url2, None, users)
    assert results == [401, 403, 403, 200, 200]
Ejemplo n.º 11
0
    def _add_voter(self, permission, request, pk=None):
        obj = self.get_object()
        self.check_permissions(request, permission, obj)

        services.add_vote(obj, user=request.user)
        return response.Ok()
Ejemplo n.º 12
0
    def _add_voter(self, permission, request, pk=None):
        obj = self.get_object()
        self.check_permissions(request, permission, obj)

        services.add_vote(obj, user=request.user)
        return response.Ok()
Ejemplo n.º 13
0
 def create_votes(self, obj):
     for i in range(self.sd.int(*NUM_VOTES)):
         user=self.sd.db_object_from_queryset(User.objects.all())
         add_vote(obj, user)
Ejemplo n.º 14
0
 def create_votes(self, obj):
     for i in range(self.sd.int(*NUM_VOTES)):
         user = self.sd.db_object_from_queryset(User.objects.all())
         add_vote(obj, user)
Ejemplo n.º 15
0
 def create_votes(self, obj, project):
     for i in range(self.sd.int(*NUM_VOTES)):
         voting_user=self.sd.db_object_from_queryset(project.members.all())
         add_vote(obj, voting_user)
Ejemplo n.º 16
0
 def create_votes(self, obj, project):
     for i in range(self.sd.int(*NUM_VOTES)):
         voting_user=self.sd.db_object_from_queryset(project.members.all())
         add_vote(obj, voting_user)
Ejemplo n.º 17
0
 def upvote(self, request, pk=None):
     issue = self.get_object()
     votes_service.add_vote(issue, user=request.user)
     return Response(status=status.HTTP_200_OK)