Exemplo n.º 1
0
    def test_get_products_after_badge_was_already_awarded(self):
        """
        Testing dashboard after badge has been awarded
        """
        #setup
        user_one = self._create_user('username_one')
        badge = self._create_badge(user_one['username'], 'Test Badge')
        badges = get_badges_by_user(username2uri(user_one['username']))

        user_two = self._create_user('username_two')
        submitted_project = self._create_project(badge['uri'], user_two['username'])

        award_badge(badge_uri=badge['uri'],
                    user_uri=username2uri(user_one['username']),
                    expert_uri=username2uri(user_one['username']),
                    evidence_url='http://evidence.test')

        submit_feedback(
            '/uri/project/%s' % submitted_project.id,
            user_one['uri'],
            'Good',
            'Bad',
            'Ugly',
            award_badge=True,
        )
        #run
        projects = list_projects_ready_for_feedback(badges)

        #verify
        self.assertEquals(len(projects), 0)
Exemplo n.º 2
0
 def _create_project(self, badge_uri, username):
     project = Project.objects.create(badge_uri=badge_uri,
                                      author_uri=username2uri(username),
                                      title='Test Projects',
                                      image_uri=self._get_image,
                                      work_url='http://testing.url',
                                      description='Vestibulum id pellentesque tortor, at rhoncus nisi',
                                      reflection='Vestibulum eleifend, dui nec congue elementum, diam purus sempe',
                                      date_created=datetime.utcnow(),
                                      date_updated=datetime.utcnow(), )
     return project
Exemplo n.º 3
0
def profile_feedback(request, username):
    user = user_api.get_user(user_api.username2uri(username))
    user = check_if_owner(request.session.get('user', default=None), username, user)

    projects = list_projects_that_user_gave_feedback(user['uri'])

    return render_to_response(
        'dashboard/dashboard_feedback.html', {
            'user': user,
            'projects': projects,
        },
        context_instance=RequestContext(request)
    )
Exemplo n.º 4
0
def profile(request, username ):

    context = {}
    user_uri = u'/uri/user/{0}'.format(username)
    context['draft_badges'] = badge_api.get_user_draft_badges(user_uri)
    context['earned_badges'] = badge_api.get_user_earned_badges(user_uri)
    context['created_badges'] = badge_api.get_user_created_badges(user_uri)
    context['awarded_badges'] = badge_api.get_user_awarded_badges(user_uri)
    map(fetch_badge_resources, context['draft_badges'])
    map(fetch_badge_resources, context['earned_badges'])
    map(fetch_badge_resources, context['created_badges'])
    map(fetch_badge_resources, context['awarded_badges'])

    context['feedback_your_projects'] = project_api.search_projects(author_uri=user_uri)
    map(fetch_resources, context['feedback_your_projects'])
    peer_projects = []
    feedback_latest = []
    for badge in context['earned_badges']:
        feedback_latest += project_api.get_projects_ready_for_feedback(badge['uri'])
        peer_projects += project_api.search_projects(badge_uri=badge['uri'])

    filter_func = lambda project: not project['author_uri'] == user_uri
    peer_projects = filter(filter_func, peer_projects)

    badges_under_revision = []
    context['badges_under_revision'] = None
    for project in context['feedback_your_projects']:
        badge_uri = project_api.get_badge_uri_from_project_under_revision(project['uri'])
        if badge_uri:
            badge = badge_api.get_badge(badge_uri)
            fetch_badge_resources(badge)
            badges_under_revision.append(badge)

    if badges_under_revision:
        context['badges_under_revision'] = badges_under_revision

    context['feedback_peer_projects'] = map(fetch_resources, peer_projects)
    context['feedback_latest'] = map(fetch_resources, feedback_latest)
    context['user'] = user_api.get_user(user_api.username2uri(username))
    context['can_delete'] = False

    if 'user' in request.session:
        if context['user']['username'] == request.session.get('user')['username']:
            context['can_delete'] = True

    return render_to_response(
        'dashboard/dashboard.html',
        context,
        context_instance=RequestContext(request)
    )
Exemplo n.º 5
0
    def test_user_has_no_badges(self):
        """
        Testing when user has no Badges
        """

        #setup
        user_one = self._create_user('username_one')
        badges = get_badges_by_user(username2uri(user_one['username']))

        #run
        projects = list_projects_ready_for_feedback(badges)

        #verify
        self.assertEquals(projects, [])
        self.assertEquals(len(badges), 0)
Exemplo n.º 6
0
 def _create_badge(self, username, title):
     """
     :param username:
     :param title:
     :rtype : dict
     """
     badge = Badge.objects.create(title=title,
                                  image_uri=self._get_image(),
                                  description='Lorem ipsum dolor sit amet, consectetur adipiscing elit. ',
                                  requirements='Ed sagittis aliquam tellus nec bibendum. ',
                                  author_uri=username2uri(username),
                                  date_created=datetime.utcnow(),
                                  date_updated=datetime.utcnow(),
                                  date_published=datetime.utcnow(), )
     return _badge2dict(badge)
Exemplo n.º 7
0
def profile_badges(request, username):
    user = user_api.get_user(user_api.username2uri(username))
    user = check_if_owner(request.session.get('user', default=None), username, user)
    badges = map(fetch_badge_resources, badge_api.get_user_earned_badges(user['uri']))
    draft_badges = map(fetch_badge_resources, badge_api.get_user_draft_badges(user['uri']))

    projects = list_projects_by_user(user['uri'])

    return render_to_response(
        'dashboard/dashboard_badges.html', {
            'user': user,
            'projects': projects,
            'badges': badges,
            'draft_badges': draft_badges,
        },
        context_instance=RequestContext(request)
    )
Exemplo n.º 8
0
    def test_user_has_badges_but_no_projects_that_need_feedback(self):
        """
        Testing when user has Badges, but has not had Project submitted for their Badge
        """

        #setup
        user_one = self._create_user('username_one')
        badge = self._create_badge(user_one['username'], 'Test badge')
        badges = get_badges_by_user(username2uri(user_one['username']))

        #run
        projects = list_projects_ready_for_feedback(badges)

        #verify
        self.assertEquals(len(badges), 1)
        self.assertEquals(badges[0]['title'], badge['title'])
        self.assertEquals(projects, [])
Exemplo n.º 9
0
    def test_user_has_multiple_badges_none_project(self):
        """
        Testing when user gets submitted Project for their Badge
        """

        #setup
        user_one = self._create_user('username_one')
        self._create_badge(user_one['username'], 'Test Badge 1')
        self._create_badge(user_one['username'], 'Test Badge 2')
        badges = get_badges_by_user(username2uri(user_one['username']))

        #run
        projects = list_projects_ready_for_feedback(badges)

        #verify
        self.assertEquals(len(projects), 0)
        self.assertEquals(len(badges), 2)
Exemplo n.º 10
0
def profile_dashboard(request, username):
    user = user_api.get_user(user_api.username2uri(username))
    user = check_if_owner(request.session.get('user', default=None), username, user)

    if not user.get('is_owner'):
        return redirect(to=reverse('profile_badges', args=[username]))

    badges = map(fetch_badge_resources, badge_api.get_user_earned_badges(user['uri']))

    projects = list_projects_ready_for_feedback(badges)

    return render_to_response(
        'dashboard/dashboard.html', {
            'user': user,
            'projects': projects,
            'badges': badges,
        },
        context_instance=RequestContext(request)
    )
Exemplo n.º 11
0
    def test_get_products_that_need_feedback_from_user(self):
        """
        Testing when user gets submitted Project for their Badge
        """

        #setup
        user_one = self._create_user('username_one')
        badge = self._create_badge(user_one['username'], 'Test Badge')
        badges = get_badges_by_user(username2uri(user_one['username']))

        user_two = self._create_user('username_two')
        submitted_project = self._create_project(badge['uri'], user_two['username'])

        #run
        #with patch('media.processors.get_image', new=lambda x: {}):
        projects = list_projects_ready_for_feedback(badges)

        #verify
        self.assertEquals(len(projects), 1)
        #self.assertEquals(projects[0]['badge']['title'], badge['title'])
        self.assertEquals(projects[0]['title'], submitted_project.title)
Exemplo n.º 12
0
def view_embedded(request, badge_id):
    # Get username from parameters or None
    username = request.GET.get('username', None)
    # Check if user is logged in
    if 'user' in request.session:
        username = request.session['user']['username']

    badge_uri = badge_api.id2uri(badge_id)
    badge = badge_api.get_badge(badge_uri)
    fetch_badge_resources(badge)
    projects = None
    user_has_badge = False
    template = 'badge/embed/embedded_large.html'

    if username:
        user_has_badge = badge_api.check_if_user_has_badge(badge['uri'],
                                                           p2pu_user_api.username2uri(username))
    if user_has_badge:
        projects = project_api.get_projects_ready_for_feedback(badge_uri)

    if projects:
        map(fetch_resources, projects)

    # Extract rendering preference -> default large
    rendering = request.GET.get('rendering', 'large')

    if rendering == 'normal':
        template = 'badge/embed/embedded_normal.html'

    return render_to_response(
        template,
        {
            'badge': badge,
            'projects': projects,
            'user_has_badge': user_has_badge,
            'rendering': rendering,
        },
        context_instance=RequestContext(request)
    )