Exemplo n.º 1
0
def test_get_watched_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")
    project.add_watcher(fav_user)
    role = f.RoleFactory(project=project, permissions=["view_project", "view_us", "view_tasks", "view_issues"])
    membership = f.MembershipFactory(project=project, role=role, user=viewer_priviliged_user)

    user_story = f.UserStoryFactory(project=project, subject="Testing user story")
    user_story.add_watcher(fav_user)

    task = f.TaskFactory(project=project, subject="Testing task")
    task.add_watcher(fav_user)

    issue = f.IssueFactory(project=project, subject="Testing issue")
    issue.add_watcher(fav_user)

    #If the project is private a viewer user without any permission shouldn' see
    # any vote
    assert len(get_watched_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_watched_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_us", "view_tasks", "view_issues"]
    project.save()
    assert len(get_watched_list(fav_user, viewer_unpriviliged_user)) == 4
Exemplo n.º 2
0
def test_get_watched_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")
    project.add_watcher(fav_user)
    role = f.RoleFactory(project=project, permissions=["view_project", "view_us", "view_tasks", "view_issues"])
    membership = f.MembershipFactory(project=project, role=role, user=viewer_priviliged_user)

    user_story = f.UserStoryFactory(project=project, subject="Testing user story")
    user_story.add_watcher(fav_user)

    task = f.TaskFactory(project=project, subject="Testing task")
    task.add_watcher(fav_user)

    issue = f.IssueFactory(project=project, subject="Testing issue")
    issue.add_watcher(fav_user)

    #If the project is private a viewer user without any permission shouldn' see
    # any vote
    assert len(get_watched_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_watched_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_us", "view_tasks", "view_issues"]
    project.save()
    assert len(get_watched_list(fav_user, viewer_unpriviliged_user)) == 4
Exemplo n.º 3
0
def test_get_watched_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)
    project.add_watcher(fav_user)

    epic = f.EpicFactory(project=project, subject="Testing epic")
    epic.add_watcher(fav_user)

    user_story = f.UserStoryFactory(project=project,
                                    subject="Testing user story")
    user_story.add_watcher(fav_user)

    task = f.TaskFactory(project=project, subject="Testing task")
    task.add_watcher(fav_user)

    issue = f.IssueFactory(project=project, subject="Testing issue")
    issue.add_watcher(fav_user)

    assert len(get_watched_list(fav_user, viewer_user)) == 5
    assert len(get_watched_list(fav_user, viewer_user, type="project")) == 1
    assert len(get_watched_list(fav_user, viewer_user, type="userstory")) == 1
    assert len(get_watched_list(fav_user, viewer_user, type="task")) == 1
    assert len(get_watched_list(fav_user, viewer_user, type="issue")) == 1
    assert len(get_watched_list(fav_user, viewer_user, type="epic")) == 1
    assert len(get_watched_list(fav_user, viewer_user, type="unknown")) == 0

    assert len(get_watched_list(fav_user, viewer_user, q="issue")) == 1
    assert len(get_watched_list(fav_user, viewer_user,
                                q="unexisting text")) == 0
Exemplo n.º 4
0
def test_get_watched_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)
    project.add_watcher(fav_user)

    epic = f.EpicFactory(project=project, subject="Testing epic")
    epic.add_watcher(fav_user)

    user_story = f.UserStoryFactory(project=project, subject="Testing user story")
    user_story.add_watcher(fav_user)

    task = f.TaskFactory(project=project, subject="Testing task")
    task.add_watcher(fav_user)

    issue = f.IssueFactory(project=project, subject="Testing issue")
    issue.add_watcher(fav_user)

    assert len(get_watched_list(fav_user, viewer_user)) == 5
    assert len(get_watched_list(fav_user, viewer_user, type="project")) == 1
    assert len(get_watched_list(fav_user, viewer_user, type="userstory")) == 1
    assert len(get_watched_list(fav_user, viewer_user, type="task")) == 1
    assert len(get_watched_list(fav_user, viewer_user, type="issue")) == 1
    assert len(get_watched_list(fav_user, viewer_user, type="epic")) == 1
    assert len(get_watched_list(fav_user, viewer_user, type="unknown")) == 0

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

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

    factories = {
        "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)

        instance.add_watcher(fav_user)
        raw_instance_watch_info = get_watched_list(fav_user,
                                                   viewer_user,
                                                   type=object_type)[0]
        instance_watch_info = VotedObjectSerializer(
            raw_instance_watch_info).data

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

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

        assert instance_watch_info["is_private"] == None
        assert instance_watch_info["logo_small_url"] == None
        assert instance_watch_info["is_voter"] == False
        assert instance_watch_info["is_watcher"] == False
        assert instance_watch_info["total_watchers"] == 1
        assert instance_watch_info["total_voters"] == 0
        assert instance_watch_info["project"] == instance.project.id
        assert instance_watch_info["project_name"] == instance.project.name
        assert instance_watch_info["project_slug"] == instance.project.slug
        assert instance_watch_info[
            "project_is_private"] == instance.project.is_private
        assert instance_watch_info[
            "assigned_to_username"] == instance.assigned_to.username
        assert instance_watch_info[
            "assigned_to_full_name"] == instance.assigned_to.full_name
        assert instance_watch_info["assigned_to_photo"] != ""
Exemplo n.º 6
0
def test_get_watched_list_valid_info_for_project():
    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"])
    project.add_watcher(fav_user)

    raw_project_watch_info = get_watched_list(fav_user, viewer_user)[0]

    project_watch_info = LikedObjectSerializer(into_namedtuple(raw_project_watch_info)).data

    assert project_watch_info["type"] == "project"
    assert project_watch_info["id"] == project.id
    assert project_watch_info["ref"] == None
    assert project_watch_info["slug"] == project.slug
    assert project_watch_info["name"] == project.name
    assert project_watch_info["subject"] == None
    assert project_watch_info["description"] == project.description
    assert project_watch_info["assigned_to"] == None
    assert project_watch_info["status"] == None
    assert project_watch_info["status_color"] == None
    assert project_watch_info["is_private"] == project.is_private
    assert project_watch_info["logo_small_url"] ==  get_thumbnail_url(project.logo, settings.THN_LOGO_SMALL)
    assert project_watch_info["is_fan"] == False
    assert project_watch_info["is_watcher"] == False
    assert project_watch_info["total_watchers"] == 1
    assert project_watch_info["total_fans"] == 0
    assert project_watch_info["project"] == None
    assert project_watch_info["project_name"] == None
    assert project_watch_info["project_slug"] == None
    assert project_watch_info["project_is_private"] == None
    assert project_watch_info["project_blocked_code"] == None
    assert project_watch_info["assigned_to"] == None
    assert project_watch_info["assigned_to_extra_info"] == None
Exemplo n.º 7
0
    def watched(self, request, *args, **kwargs):
        for_user = get_object_or_404(models.User, **kwargs)
        from_user = request.user
        self.check_permissions(request, 'watched', for_user)
        filters = {
            "type": request.GET.get("type", None),
            "q": request.GET.get("q", None),
        }

        self.object_list = services.get_watched_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_liked = {
            "user_watching": services.get_watched_content_for_user(request.user),
            "user_likes": services.get_liked_content_for_user(request.user),
        }

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

        response_data = []
        for elem in elements:
            if elem["type"] == "project":
                # projects are liked objects
                response_data.append(serializers.LikedObjectSerializer(elem, **extra_args_liked).data )
            else:
                # stories, tasks and issues are voted objects
                response_data.append(serializers.VotedObjectSerializer(elem, **extra_args_voted).data )

        return response.Ok(response_data)
def test_get_watched_list_valid_info_for_project():
    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_epic", "view_us", "view_tasks", "view_issues"])
    project.add_watcher(fav_user)

    raw_project_watch_info = get_watched_list(fav_user, viewer_user)[0]

    project_watch_info = LikedObjectSerializer(into_namedtuple(raw_project_watch_info)).data

    assert project_watch_info["type"] == "project"
    assert project_watch_info["id"] == project.id
    assert project_watch_info["ref"] == None
    assert project_watch_info["slug"] == project.slug
    assert project_watch_info["name"] == project.name
    assert project_watch_info["subject"] == None
    assert project_watch_info["description"] == project.description
    assert project_watch_info["assigned_to"] == None
    assert project_watch_info["status"] == None
    assert project_watch_info["status_color"] == None
    assert project_watch_info["is_private"] == project.is_private
    assert project_watch_info["logo_small_url"] ==  get_thumbnail_url(project.logo, settings.THN_LOGO_SMALL)
    assert project_watch_info["is_fan"] == False
    assert project_watch_info["is_watcher"] == False
    assert project_watch_info["total_watchers"] == 1
    assert project_watch_info["total_fans"] == 0
    assert project_watch_info["project"] == None
    assert project_watch_info["project_name"] == None
    assert project_watch_info["project_slug"] == None
    assert project_watch_info["project_is_private"] == None
    assert project_watch_info["project_blocked_code"] == None
    assert project_watch_info["assigned_to"] == None
    assert project_watch_info["assigned_to_extra_info"] == None
Exemplo n.º 9
0
def test_get_watched_list_valid_info_for_not_project_types():
    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)

        instance.add_watcher(fav_user)
        raw_instance_watch_info = get_watched_list(fav_user, viewer_user, type=object_type)[0]
        instance_watch_info = VotedObjectSerializer(into_namedtuple(raw_instance_watch_info)).data

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

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

        assert instance_watch_info["is_private"] == None
        assert instance_watch_info["logo_small_url"] ==  None
        assert instance_watch_info["is_voter"] == False
        assert instance_watch_info["is_watcher"] == False
        assert instance_watch_info["total_watchers"] == 1
        assert instance_watch_info["total_voters"] == 0
        assert instance_watch_info["project"] == instance.project.id
        assert instance_watch_info["project_name"] == instance.project.name
        assert instance_watch_info["project_slug"] == instance.project.slug
        assert instance_watch_info["project_is_private"] == instance.project.is_private
        assert instance_watch_info["project_blocked_code"] == instance.project.blocked_code
        assert instance_watch_info["assigned_to"] != None
        assert instance_watch_info["assigned_to_extra_info"]["username"] == instance.assigned_to.username
        assert instance_watch_info["assigned_to_extra_info"]["full_name_display"] == instance.assigned_to.get_full_name()
        assert instance_watch_info["assigned_to_extra_info"]["photo"] == None
        assert instance_watch_info["assigned_to_extra_info"]["gravatar_id"] != None
Exemplo n.º 10
0
def test_get_watched_list_for_project_with_ignored_notify_level():
    #If the notify policy level is ignore the project shouldn't be in the watched results
    fav_user = f.UserFactory()
    viewer_user = f.UserFactory()

    project = f.ProjectFactory(is_private=False, name="Testing project", tags=['test', 'tag'])
    role = f.RoleFactory(project=project, permissions=["view_project", "view_us", "view_tasks", "view_issues"])
    membership = f.MembershipFactory(project=project, role=role, user=fav_user)
    notify_policy = NotifyPolicy.objects.get(user=fav_user, project=project)
    notify_policy.notify_level=NotifyLevel.none
    notify_policy.save()

    watched_list = get_watched_list(fav_user, viewer_user)
    assert len(watched_list) == 0
Exemplo n.º 11
0
def test_get_watched_list_for_project_with_ignored_notify_level():
    #If the notify policy level is ignore the project shouldn't be in the watched results
    fav_user = f.UserFactory()
    viewer_user = f.UserFactory()

    project = f.ProjectFactory(is_private=False, name="Testing project", tags=['test', 'tag'])
    role = f.RoleFactory(project=project, permissions=["view_project", "view_us", "view_tasks", "view_issues"])
    membership = f.MembershipFactory(project=project, role=role, user=fav_user)
    notify_policy = NotifyPolicy.objects.get(user=fav_user, project=project)
    notify_policy.notify_level=NotifyLevel.none
    notify_policy.save()

    watched_list = get_watched_list(fav_user, viewer_user)
    assert len(watched_list) == 0
Exemplo n.º 12
0
def test_get_watched_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'])
    role = f.RoleFactory(
        project=project,
        permissions=["view_project", "view_us", "view_tasks", "view_issues"])
    project.add_watcher(fav_user)

    raw_project_watch_info = get_watched_list(fav_user, viewer_user)[0]

    project_watch_info = LikedObjectSerializer(raw_project_watch_info).data

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

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

    assert project_watch_info["is_private"] == project.is_private
    assert project_watch_info["logo_small_url"] == get_thumbnail_url(
        project.logo, settings.THN_LOGO_SMALL)
    assert project_watch_info["is_fan"] == False
    assert project_watch_info["is_watcher"] == False
    assert project_watch_info["total_watchers"] == 1
    assert project_watch_info["total_fans"] == 0
    assert project_watch_info["project"] == None
    assert project_watch_info["project_name"] == None
    assert project_watch_info["project_slug"] == None
    assert project_watch_info["project_is_private"] == None
    assert project_watch_info["assigned_to_username"] == None
    assert project_watch_info["assigned_to_full_name"] == None
    assert project_watch_info["assigned_to_photo"] == None
Exemplo n.º 13
0
def test_get_watched_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'])
    role = f.RoleFactory(project=project, permissions=["view_project", "view_us", "view_tasks", "view_issues"])
    project.add_watcher(fav_user)

    raw_project_watch_info = get_watched_list(fav_user, viewer_user)[0]

    project_watch_info = LikedObjectSerializer(raw_project_watch_info).data

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

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

    assert project_watch_info["is_private"] == project.is_private
    assert project_watch_info["is_fan"] == False
    assert project_watch_info["is_watcher"] == False
    assert project_watch_info["total_watchers"] == 1
    assert project_watch_info["total_fans"] == 0
    assert project_watch_info["project"] == None
    assert project_watch_info["project_name"] == None
    assert project_watch_info["project_slug"] == None
    assert project_watch_info["project_is_private"] == None
    assert project_watch_info["assigned_to_username"] == None
    assert project_watch_info["assigned_to_full_name"] == None
    assert project_watch_info["assigned_to_photo"] == None