Skip to content

Commit

Permalink
Add testcase for reviewer vote and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kracekumar committed Jan 10, 2016
1 parent 2448bbf commit a58c035
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 16 deletions.
15 changes: 10 additions & 5 deletions junction/proposals/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ class ProposalReviewerVoteForm(forms.Form):
help_text="Leave a comment justifying your vote.",
)

def __init_(self):
def __init__(self, *args, **kwargs):
super(ProposalReviewerVoteForm, self).__init__(*args, **kwargs)
choices = _get_proposal_section_reviewer_vote_choices()
self.fields['vote_value'].choices = choices

Expand All @@ -163,13 +164,17 @@ class ProposalTypesChoices(forms.Form):
"""
Base proposal form with proposal sections & types.
"""
proposal_section = forms.ChoiceField(widget=forms.Select(attrs={'class': 'dropdown'}))
proposal_type = forms.ChoiceField(widget=forms.Select(attrs={'class': 'dropdown'}))
proposal_section = forms.ChoiceField(widget=forms.Select(
attrs={'class': 'dropdown'}))
proposal_type = forms.ChoiceField(widget=forms.Select(
attrs={'class': 'dropdown'}))

def __init__(self, conference, *args, **kwargs):
super(ProposalTypesChoices, self).__init__(*args, **kwargs)
self.fields['proposal_section'].choices = _get_proposal_section_choices(conference)
self.fields['proposal_type'].choices = _get_proposal_type_choices(conference)
self.fields['proposal_section'].choices = _get_proposal_section_choices(
conference)
self.fields['proposal_type'].choices = _get_proposal_type_choices(
conference)


class ProposalsToReviewForm(ProposalTypesChoices):
Expand Down
9 changes: 6 additions & 3 deletions junction/proposals/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
url(r'^comment/', include(comment_urls)),

# Voting
url(r'^(?P<proposal_slug>[\w-]+)/vote/$', votes_views.proposal_reviewer_vote, name='proposal-reviewer-vote'),
url(r'^(?P<proposal_slug>[\w-]+)/down-vote/$', votes_views.proposal_vote_down, name='proposal-vote-down'),
url(r'^(?P<proposal_slug>[\w-]+)/up-vote/$', votes_views.proposal_vote_up, name='proposal-vote-up'),
url(r'^(?P<proposal_slug>[\w-]+)/vote/$',
votes_views.proposal_reviewer_vote, name='proposal-reviewer-vote'),
url(r'^(?P<proposal_slug>[\w-]+)/down-vote/$',
votes_views.proposal_vote_down, name='proposal-vote-down'),
url(r'^(?P<proposal_slug>[\w-]+)/up-vote/$',
votes_views.proposal_vote_up, name='proposal-vote-up'),
)
2 changes: 1 addition & 1 deletion junction/proposals/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def review_proposal(request, conference_slug, slug):
return render(request, 'proposals/review.html', ctx)

# POST Workflow
form = ProposalReviewForm(request.POST)
form = ProposalReviewForm(data=request.POST)
if not form.is_valid():
context = {'form': form,
'proposal': proposal,
Expand Down
14 changes: 7 additions & 7 deletions junction/proposals/votes_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def proposal_reviewer_vote(request, conference_slug, proposal_slug):
return render(request, 'proposals/vote.html', ctx)

# POST Workflow
form = ProposalReviewerVoteForm(request.POST)
form = ProposalReviewerVoteForm(data=request.POST)
if not form.is_valid():
return render(request, 'proposals/vote.html',
{'form': form,
Expand All @@ -153,16 +153,16 @@ def proposal_reviewer_vote(request, conference_slug, proposal_slug):
if not vote:
vote = ProposalSectionReviewerVote.objects.create(
proposal=proposal,
voter=ProposalSectionReviewer.objects.get(
voter=ProposalSectionReviewer.objects.filter(
conference_reviewer__reviewer=request.user,
conference_reviewer__conference=conference,
proposal_section=proposal.proposal_section),
vote_value=ProposalSectionReviewerVoteValue.objects.get(
vote_value=vote_value),
proposal_section=proposal.proposal_section)[0],
vote_value=ProposalSectionReviewerVoteValue.objects.filter(
vote_value=vote_value)[0],
)
else:
vote.vote_value = ProposalSectionReviewerVoteValue.objects.get(
vote_value=vote_value)
vote.vote_value = ProposalSectionReviewerVoteValue.objects.filter(
vote_value=vote_value)[0]
vote.save()
if not vote_comment:
vote_comment = ProposalComment.objects.create(
Expand Down
2 changes: 2 additions & 0 deletions tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def create_conference(**kwargs):
""" Create a conference """
ProposalSectionReviewerVoteValueFactory.create(vote_value=1,
description="Good")
ProposalSectionReviewerVoteValueFactory.create(vote_value=2,
description="Good")
conference = ConferenceFactory.create(**kwargs)
start_date = kwargs.pop('start_date', None)
end_date = kwargs.pop('end_date', None)
Expand Down
119 changes: 119 additions & 0 deletions tests/integrations/test_reviewer_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,122 @@ def test_review_proposal_by_non_reviewer(self, settings, client,
response = client.get(url)

assert response.status_code == 403

def test_proposal_reviewer_vote_by_non_reviewer(self, settings, client,
conferences,
create_proposal):
username, password = "temp", "temp"
f.create_user(password=password, username=username)
conference = conferences['future']
client.login(username=username, password=password)
proposal = create_proposal

kwargs = {'conference_slug': conference.slug,
'proposal_slug': proposal.slug}
url = reverse('proposal-reviewer-vote', kwargs=kwargs)

response = client.post(url)

assert response.status_code == 403

def test_get_proposal_reviewer_vote(self, settings, login,
conferences,
create_proposal,
create_reviewer):
client = login[0]
conference = conferences['future']

proposal = create_proposal

kwargs = {'conference_slug': conference.slug,
'proposal_slug': proposal.slug}
url = reverse('proposal-reviewer-vote', kwargs=kwargs)

response = client.get(url)
context = response.context

assert response.status_code == 200
assert context['proposal'] == proposal
assert context['vote'] is None
helpers.assert_template_used(response, 'proposals/vote.html')

def test_post_proposal_reviewer_vote(self, settings, login,
conferences,
create_proposal,
create_reviewer):
client = login[0]
conference = conferences['future']

proposal = create_proposal

kwargs = {'conference_slug': conference.slug,
'proposal_slug': proposal.slug}
url = reverse('proposal-reviewer-vote', kwargs=kwargs)
data = {'vote_value': 1, 'comment': 'Must Have'}

response = client.post(url, data)

assert response.status_code == 302
assert response.url.endswith('review/') is True

def test_update_proposal_reviewer_vote(self, settings, login,
conferences,
create_proposal,
create_reviewer):
client = login[0]
conference = conferences['future']

proposal = create_proposal

kwargs = {'conference_slug': conference.slug,
'proposal_slug': proposal.slug}
url = reverse('proposal-reviewer-vote', kwargs=kwargs)
data = {'vote_value': 1, 'comment': 'Must Have'}
client.post(url, data)

update_data = {'vote_value': 2, 'comment': 'Must Have'}
response = client.post(url, update_data)

assert response.status_code == 302
assert response.url.endswith('review/') is True

def test_get_proposal_reviewer_vote_after_create(self, settings, login,
conferences,
create_proposal,
create_reviewer):
client = login[0]
conference = conferences['future']

proposal = create_proposal

kwargs = {'conference_slug': conference.slug,
'proposal_slug': proposal.slug}
url = reverse('proposal-reviewer-vote', kwargs=kwargs)
comment, vote_value = 'Must Have', 1
data = {'vote_value': vote_value, 'comment': comment}
client.post(url, data)

response = client.get(url)
context = response.context

assert response.status_code == 200
assert context['proposal_vote_form'].initial['vote_value'] == vote_value
assert context['proposal_vote_form'].initial['comment'] == comment

# def test_post_review_proposal_vote_with_invalid_data(self, settings, login,
# conferences,
# create_proposal,
# create_reviewer):
# client = login[0]
# conference = conferences['future']

# proposal = create_proposal

# kwargs = {'conference_slug': conference.slug,
# 'proposal_slug': proposal.slug}
# url = reverse('proposal-reviewer-vote', kwargs=kwargs)
# data = {'vote_value': 12}
# response = client.post(url, data)

# assert response.status_code == 200
# assert 'vote_value' in response.context['form_errors']

0 comments on commit a58c035

Please sign in to comment.