Exemplo n.º 1
0
def test_get_voted_list_permissions():
    fav_user = f.UserFactory()
    viewer_unpriviliged_user = f.UserFactory()
    viewer_priviliged_user = f.UserFactory()

    project = f.ProjectFactory(is_private=True, name="Testing project")
    role = f.RoleFactory(project=project,
                         permissions=[
                             "view_project", "view_epic", "view_us",
                             "view_tasks", "view_issues"
                         ])
    membership = f.MembershipFactory(project=project,
                                     role=role,
                                     user=viewer_priviliged_user)

    epic = f.EpicFactory(project=project, subject="Testing epic")
    content_type = ContentType.objects.get_for_model(epic)
    f.VoteFactory(content_type=content_type, object_id=epic.id, user=fav_user)
    f.VotesFactory(content_type=content_type, object_id=epic.id, count=1)

    user_story = f.UserStoryFactory(project=project,
                                    subject="Testing user story")
    content_type = ContentType.objects.get_for_model(user_story)
    f.VoteFactory(content_type=content_type,
                  object_id=user_story.id,
                  user=fav_user)
    f.VotesFactory(content_type=content_type, object_id=user_story.id, count=1)

    task = f.TaskFactory(project=project, subject="Testing task")
    content_type = ContentType.objects.get_for_model(task)
    f.VoteFactory(content_type=content_type, object_id=task.id, user=fav_user)
    f.VotesFactory(content_type=content_type, object_id=task.id, count=1)

    issue = f.IssueFactory(project=project, subject="Testing issue")
    content_type = ContentType.objects.get_for_model(issue)
    f.VoteFactory(content_type=content_type, object_id=issue.id, user=fav_user)
    f.VotesFactory(content_type=content_type, object_id=issue.id, count=1)

    #If the project is private a viewer user without any permission shouldn' see
    # any vote
    assert len(get_voted_list(fav_user, viewer_unpriviliged_user)) == 0

    #If the project is private but the viewer user has permissions the votes should
    # be accessible
    assert len(get_voted_list(fav_user, viewer_priviliged_user)) == 4

    #If the project is private but has the required anon permissions the votes should
    # be accessible by any user too
    project.anon_permissions = [
        "view_project", "view_epic", "view_us", "view_tasks", "view_issues"
    ]
    project.save()
    assert len(get_voted_list(fav_user, viewer_unpriviliged_user)) == 4
Exemplo n.º 2
0
def test_get_voted_list():
    fav_user = f.UserFactory()
    viewer_user = f.UserFactory()

    project = f.ProjectFactory(is_private=False, name="Testing project")
    role = f.RoleFactory(project=project, permissions=["view_project", "view_us", "view_tasks", "view_issues"])
    membership = f.MembershipFactory(project=project, role=role, user=fav_user)
    content_type = ContentType.objects.get_for_model(project)
    f.VoteFactory(content_type=content_type, object_id=project.id, user=fav_user)
    f.VotesFactory(content_type=content_type, object_id=project.id, count=1)

    user_story = f.UserStoryFactory(project=project, subject="Testing user story")
    content_type = ContentType.objects.get_for_model(user_story)
    f.VoteFactory(content_type=content_type, object_id=user_story.id, user=fav_user)
    f.VotesFactory(content_type=content_type, object_id=user_story.id, count=1)

    task = f.TaskFactory(project=project, subject="Testing task")
    content_type = ContentType.objects.get_for_model(task)
    f.VoteFactory(content_type=content_type, object_id=task.id, user=fav_user)
    f.VotesFactory(content_type=content_type, object_id=task.id, count=1)

    issue = f.IssueFactory(project=project, subject="Testing issue")
    content_type = ContentType.objects.get_for_model(issue)
    f.VoteFactory(content_type=content_type, object_id=issue.id, user=fav_user)
    f.VotesFactory(content_type=content_type, object_id=issue.id, count=1)

    assert len(get_voted_list(fav_user, viewer_user)) == 4
    assert len(get_voted_list(fav_user, viewer_user, type="project")) == 1
    assert len(get_voted_list(fav_user, viewer_user, type="userstory")) == 1
    assert len(get_voted_list(fav_user, viewer_user, type="task")) == 1
    assert len(get_voted_list(fav_user, viewer_user, type="issue")) == 1
    assert len(get_voted_list(fav_user, viewer_user, type="unknown")) == 0

    assert len(get_voted_list(fav_user, viewer_user, q="issue")) == 1
    assert len(get_voted_list(fav_user, viewer_user, q="unexisting text")) == 0
Exemplo n.º 3
0
def test_get_voted_list_valid_info():
    fav_user = f.UserFactory()
    viewer_user = f.UserFactory()
    assigned_to_user = f.UserFactory()

    project = f.ProjectFactory(is_private=False, name="Testing project")

    factories = {
        "epic": f.EpicFactory,
        "userstory": f.UserStoryFactory,
        "task": f.TaskFactory,
        "issue": f.IssueFactory
    }

    for object_type in factories:
        instance = factories[object_type](project=project,
            subject="Testing",
            tags=["test1", "test2"],
            assigned_to=assigned_to_user)

        content_type = ContentType.objects.get_for_model(instance)
        vote = f.VoteFactory(content_type=content_type, object_id=instance.id, user=fav_user)
        f.VotesFactory(content_type=content_type, object_id=instance.id, count=3)

        raw_instance_vote_info = get_voted_list(fav_user, viewer_user, type=object_type)[0]
        instance_vote_info = VotedObjectSerializer(into_namedtuple(raw_instance_vote_info)).data

        assert instance_vote_info["type"] == object_type
        assert instance_vote_info["id"] == instance.id
        assert instance_vote_info["ref"] == instance.ref
        assert instance_vote_info["slug"] == None
        assert instance_vote_info["name"] == None
        assert instance_vote_info["subject"] == instance.subject
        assert instance_vote_info["description"] == None
        assert instance_vote_info["assigned_to"] == instance.assigned_to.id
        assert instance_vote_info["status"] == instance.status.name
        assert instance_vote_info["status_color"] == instance.status.color

        tags_colors = {tc["name"]:tc["color"] for tc in instance_vote_info["tags_colors"]}
        assert "test1" in tags_colors
        assert "test2" in tags_colors

        assert instance_vote_info["is_private"] == None
        assert instance_vote_info["logo_small_url"] ==  None
        assert instance_vote_info["is_voter"] == False
        assert instance_vote_info["is_watcher"] == False
        assert instance_vote_info["total_watchers"] == 0
        assert instance_vote_info["total_voters"] == 3
        assert instance_vote_info["project"] == instance.project.id
        assert instance_vote_info["project_name"] == instance.project.name
        assert instance_vote_info["project_slug"] == instance.project.slug
        assert instance_vote_info["project_is_private"] == instance.project.is_private
        assert instance_vote_info["project_blocked_code"] == instance.project.blocked_code
        assert instance_vote_info["assigned_to"] != None
        assert instance_vote_info["assigned_to_extra_info"]["username"] == instance.assigned_to.username
        assert instance_vote_info["assigned_to_extra_info"]["full_name_display"] == instance.assigned_to.get_full_name()
        assert instance_vote_info["assigned_to_extra_info"]["photo"] == None
        assert instance_vote_info["assigned_to_extra_info"]["gravatar_id"] != None
def test_get_voted_list_valid_info():
    fav_user = f.UserFactory()
    viewer_user = f.UserFactory()
    assigned_to_user = f.UserFactory()

    project = f.ProjectFactory(is_private=False, name="Testing project")

    factories = {
        "epic": f.EpicFactory,
        "userstory": f.UserStoryFactory,
        "task": f.TaskFactory,
        "issue": f.IssueFactory
    }

    for object_type in factories:
        instance = factories[object_type](project=project,
            subject="Testing",
            tags=["test1", "test2"],
            assigned_to=assigned_to_user)

        content_type = ContentType.objects.get_for_model(instance)
        vote = f.VoteFactory(content_type=content_type, object_id=instance.id, user=fav_user)
        f.VotesFactory(content_type=content_type, object_id=instance.id, count=3)

        raw_instance_vote_info = get_voted_list(fav_user, viewer_user, type=object_type)[0]
        instance_vote_info = VotedObjectSerializer(into_namedtuple(raw_instance_vote_info)).data

        assert instance_vote_info["type"] == object_type
        assert instance_vote_info["id"] == instance.id
        assert instance_vote_info["ref"] == instance.ref
        assert instance_vote_info["slug"] == None
        assert instance_vote_info["name"] == None
        assert instance_vote_info["subject"] == instance.subject
        assert instance_vote_info["description"] == None
        assert instance_vote_info["assigned_to"] == instance.assigned_to.id
        assert instance_vote_info["status"] == instance.status.name
        assert instance_vote_info["status_color"] == instance.status.color

        tags_colors = {tc["name"]:tc["color"] for tc in instance_vote_info["tags_colors"]}
        assert "test1" in tags_colors
        assert "test2" in tags_colors

        assert instance_vote_info["is_private"] == None
        assert instance_vote_info["logo_small_url"] ==  None
        assert instance_vote_info["is_voter"] == False
        assert instance_vote_info["is_watcher"] == False
        assert instance_vote_info["total_watchers"] == 0
        assert instance_vote_info["total_voters"] == 3
        assert instance_vote_info["project"] == instance.project.id
        assert instance_vote_info["project_name"] == instance.project.name
        assert instance_vote_info["project_slug"] == instance.project.slug
        assert instance_vote_info["project_is_private"] == instance.project.is_private
        assert instance_vote_info["project_blocked_code"] == instance.project.blocked_code
        assert instance_vote_info["assigned_to"] != None
        assert instance_vote_info["assigned_to_extra_info"]["username"] == instance.assigned_to.username
        assert instance_vote_info["assigned_to_extra_info"]["full_name_display"] == instance.assigned_to.get_full_name()
        assert instance_vote_info["assigned_to_extra_info"]["photo"] == None
        assert instance_vote_info["assigned_to_extra_info"]["gravatar_id"] != None
Exemplo n.º 5
0
def test_get_voted_list_permissions():
    fav_user = f.UserFactory()
    viewer_unpriviliged_user = f.UserFactory()
    viewer_priviliged_user = f.UserFactory()

    project = f.ProjectFactory(is_private=True, name="Testing project")
    role = f.RoleFactory(project=project, permissions=["view_project", "view_epic", "view_us", "view_tasks", "view_issues"])
    membership = f.MembershipFactory(project=project, role=role, user=viewer_priviliged_user)

    epic = f.EpicFactory(project=project, subject="Testing epic")
    content_type = ContentType.objects.get_for_model(epic)
    f.VoteFactory(content_type=content_type, object_id=epic.id, user=fav_user)
    f.VotesFactory(content_type=content_type, object_id=epic.id, count=1)

    user_story = f.UserStoryFactory(project=project, subject="Testing user story")
    content_type = ContentType.objects.get_for_model(user_story)
    f.VoteFactory(content_type=content_type, object_id=user_story.id, user=fav_user)
    f.VotesFactory(content_type=content_type, object_id=user_story.id, count=1)

    task = f.TaskFactory(project=project, subject="Testing task")
    content_type = ContentType.objects.get_for_model(task)
    f.VoteFactory(content_type=content_type, object_id=task.id, user=fav_user)
    f.VotesFactory(content_type=content_type, object_id=task.id, count=1)

    issue = f.IssueFactory(project=project, subject="Testing issue")
    content_type = ContentType.objects.get_for_model(issue)
    f.VoteFactory(content_type=content_type, object_id=issue.id, user=fav_user)
    f.VotesFactory(content_type=content_type, object_id=issue.id, count=1)

    #If the project is private a viewer user without any permission shouldn' see
    # any vote
    assert len(get_voted_list(fav_user, viewer_unpriviliged_user)) == 0

    #If the project is private but the viewer user has permissions the votes should
    # be accesible
    assert len(get_voted_list(fav_user, viewer_priviliged_user)) == 4

    #If the project is private but has the required anon permissions the votes should
    # be accesible by any user too
    project.anon_permissions = ["view_project", "view_epic", "view_us", "view_tasks", "view_issues"]
    project.save()
    assert len(get_voted_list(fav_user, viewer_unpriviliged_user)) == 4
Exemplo n.º 6
0
def test_get_voted_list_valid_info_for_project():
    fav_user = f.UserFactory()
    viewer_user = f.UserFactory()

    project = f.ProjectFactory(is_private=False, name="Testing project", tags=['test', 'tag'])
    content_type = ContentType.objects.get_for_model(project)
    vote = f.VoteFactory(content_type=content_type, object_id=project.id, user=fav_user)
    f.VotesFactory(content_type=content_type, object_id=project.id, count=1)

    raw_project_vote_info = get_voted_list(fav_user, viewer_user)[0]
    project_vote_info = FanSerializer(raw_project_vote_info).data

    assert project_vote_info["type"] == "project"
    assert project_vote_info["id"] == project.id
    assert project_vote_info["ref"] == None
    assert project_vote_info["slug"] == project.slug
    assert project_vote_info["name"] == project.name
    assert project_vote_info["subject"] == None
    assert project_vote_info["description"] == project.description
    assert project_vote_info["assigned_to"] == None
    assert project_vote_info["status"] == None
    assert project_vote_info["status_color"] == None

    tags_colors = {tc["name"]:tc["color"] for tc in project_vote_info["tags_colors"]}
    assert "test" in tags_colors
    assert "tag" in tags_colors

    assert project_vote_info["is_private"] == project.is_private

    import pprint
    pprint.pprint(project_vote_info)

    assert project_vote_info["is_fan"] == False
    assert project_vote_info["is_watcher"] == False
    assert project_vote_info["total_watchers"] == 0
    assert project_vote_info["total_fans"] == 1
    assert project_vote_info["project"] == None
    assert project_vote_info["project_name"] == None
    assert project_vote_info["project_slug"] == None
    assert project_vote_info["project_is_private"] == None
    assert project_vote_info["assigned_to_username"] == None
    assert project_vote_info["assigned_to_full_name"] == None
    assert project_vote_info["assigned_to_photo"] == None
Exemplo n.º 7
0
    def voted(self, request, *args, **kwargs):
        for_user = get_object_or_404(models.User, **kwargs)
        from_user = request.user
        self.check_permissions(request, 'liked', for_user)
        filters = {
            "type": request.GET.get("type", None),
            "q": request.GET.get("q", None),
        }

        self.object_list = services.get_voted_list(for_user, from_user, **filters)
        page = self.paginate_queryset(self.object_list)
        elements = page.object_list if page is not None else self.object_list

        extra_args = {
            "user_watching": services.get_watched_content_for_user(request.user),
            "user_votes": services.get_voted_content_for_user(request.user),
        }

        response_data = [serializers.VotedObjectSerializer(elem, **extra_args).data for elem in elements]

        return response.Ok(response_data)