SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit cec55902 authored by Geert Kapteijns's avatar Geert Kapteijns
Browse files

fix error in commentary browse test

parent a82c726d
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,8 @@ from django import forms ...@@ -4,7 +4,8 @@ from django import forms
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.urls import reverse from django.urls import reverse
from .models import Commentary, COMMENTARY_PUBLISHED, COMMENTARY_PREPRINT from .models import Commentary
from .constants import COMMENTARY_PUBLISHED, COMMENTARY_PREPRINT
from scipost.services import DOICaller, ArxivCaller from scipost.services import DOICaller, ArxivCaller
from scipost.models import Contributor from scipost.models import Contributor
......
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
{% else %} {% else %}
<h2>Search results:</h3> <h2>Search results:</h3>
{% endif %} {% endif %}
{% if object_list %} {% if commentary_list %}
{% if is_paginated %} {% if is_paginated %}
<p> <p>
{% if page_obj.has_previous %} {% if page_obj.has_previous %}
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
<div class="col-12"> <div class="col-12">
<ul class="list-group list-group-flush"> <ul class="list-group list-group-flush">
{% for object in object_list %} {% for object in commentary_list %}
<li class="list-group-item"> <li class="list-group-item">
{% include 'commentaries/_commentary_card_content.html' with commentary=object %} {% include 'commentaries/_commentary_card_content.html' with commentary=object %}
</li> </li>
......
...@@ -2,6 +2,7 @@ from django.core.urlresolvers import reverse ...@@ -2,6 +2,7 @@ from django.core.urlresolvers import reverse
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.test import TestCase, Client, RequestFactory from django.test import TestCase, Client, RequestFactory
from scipost.models import Contributor
from scipost.factories import ContributorFactory, UserFactory from scipost.factories import ContributorFactory, UserFactory
from .factories import UnvettedCommentaryFactory, VettedCommentaryFactory, UnpublishedVettedCommentaryFactory, \ from .factories import UnvettedCommentaryFactory, VettedCommentaryFactory, UnpublishedVettedCommentaryFactory, \
...@@ -32,7 +33,7 @@ class RequestPublishedArticleTest(TestCase): ...@@ -32,7 +33,7 @@ class RequestPublishedArticleTest(TestCase):
def setUp(self): def setUp(self):
add_groups_and_permissions() add_groups_and_permissions()
self.target = reverse('commentaries:request_published_article') self.target = reverse('commentaries:request_published_article')
self.commentary_instance = UnvettedCommentaryFactory.build() self.commentary_instance = UnvettedCommentaryFactory.build(requested_by=ContributorFactory())
self.valid_form_data = model_form_data(self.commentary_instance, RequestPublishedArticleForm) self.valid_form_data = model_form_data(self.commentary_instance, RequestPublishedArticleForm)
def test_commentary_gets_created_with_correct_type(self): def test_commentary_gets_created_with_correct_type(self):
...@@ -51,7 +52,7 @@ class RequestArxivPreprintTest(TestCase): ...@@ -51,7 +52,7 @@ class RequestArxivPreprintTest(TestCase):
def setUp(self): def setUp(self):
add_groups_and_permissions() add_groups_and_permissions()
self.target = reverse('commentaries:request_arxiv_preprint') self.target = reverse('commentaries:request_arxiv_preprint')
self.commentary_instance = UnvettedArxivPreprintCommentaryFactory.build() self.commentary_instance = UnvettedArxivPreprintCommentaryFactory.build(requested_by=ContributorFactory())
self.valid_form_data = model_form_data(self.commentary_instance, RequestPublishedArticleForm) self.valid_form_data = model_form_data(self.commentary_instance, RequestPublishedArticleForm)
# The form field is called 'identifier', while the model field is called 'arxiv_identifier', # The form field is called 'identifier', while the model field is called 'arxiv_identifier',
# so model_form_data doesn't include it. # so model_form_data doesn't include it.
...@@ -110,12 +111,13 @@ class VetCommentaryRequestsTest(TestCase): ...@@ -110,12 +111,13 @@ class VetCommentaryRequestsTest(TestCase):
self.assertEquals(response.context['commentary_to_vet'], None) self.assertEquals(response.context['commentary_to_vet'], None)
# Only vetted Commentaries exist! # Only vetted Commentaries exist!
VettedCommentaryFactory() # ContributorFactory.create_batch(5)
VettedCommentaryFactory(requested_by=ContributorFactory())
response = self.client.get(self.view_url) response = self.client.get(self.view_url)
self.assertEquals(response.context['commentary_to_vet'], None) self.assertEquals(response.context['commentary_to_vet'], None)
# Unvetted Commentaries do exist! # Unvetted Commentaries do exist!
UnvettedCommentaryFactory() UnvettedCommentaryFactory(requested_by=ContributorFactory())
response = self.client.get(self.view_url) response = self.client.get(self.view_url)
self.assertTrue(type(response.context['commentary_to_vet']) is Commentary) self.assertTrue(type(response.context['commentary_to_vet']) is Commentary)
...@@ -125,7 +127,7 @@ class BrowseCommentariesTest(TestCase): ...@@ -125,7 +127,7 @@ class BrowseCommentariesTest(TestCase):
def setUp(self): def setUp(self):
add_groups_and_permissions() add_groups_and_permissions()
VettedCommentaryFactory(discipline='physics') VettedCommentaryFactory(discipline='physics', requested_by=ContributorFactory())
self.view_url = reverse('commentaries:browse', kwargs={ self.view_url = reverse('commentaries:browse', kwargs={
'discipline': 'physics', 'discipline': 'physics',
'nrweeksback': '1' 'nrweeksback': '1'
...@@ -137,7 +139,7 @@ class BrowseCommentariesTest(TestCase): ...@@ -137,7 +139,7 @@ class BrowseCommentariesTest(TestCase):
self.assertEquals(response.status_code, 200) self.assertEquals(response.status_code, 200)
# The created vetted Commentary is found! # The created vetted Commentary is found!
self.assertTrue(response.context['commentary_browse_list'].count() >= 1) self.assertTrue(response.context['commentary_list'].count() >= 1)
# The search form is passed trough the view... # The search form is passed trough the view...
self.assertTrue(type(response.context['form']) is CommentarySearchForm) self.assertTrue(type(response.context['form']) is CommentarySearchForm)
...@@ -146,6 +148,7 @@ class CommentaryDetailTest(TestCase): ...@@ -146,6 +148,7 @@ class CommentaryDetailTest(TestCase):
def setUp(self): def setUp(self):
add_groups_and_permissions() add_groups_and_permissions()
self.client = Client() self.client = Client()
ContributorFactory()
self.commentary = UnpublishedVettedCommentaryFactory() self.commentary = UnpublishedVettedCommentaryFactory()
self.target = reverse( self.target = reverse(
'commentaries:commentary', 'commentaries:commentary',
......
...@@ -33,37 +33,37 @@ def request_commentary(request): ...@@ -33,37 +33,37 @@ def request_commentary(request):
@method_decorator(permission_required( @method_decorator(permission_required(
'scipost.can_request_commentary_pages', raise_exception=True), name='dispatch') 'scipost.can_request_commentary_pages', raise_exception=True), name='dispatch')
class RequestPublishedArticle(CreateView): class RequestCommentary(CreateView):
success_url = reverse_lazy('scipost:personal_page')
def form_valid(self, form):
messages.success(self.request, strings.acknowledge_request_commentary, fail_silently=True)
return super().form_valid(form)
@method_decorator(permission_required(
'scipost.can_request_commentary_pages', raise_exception=True), name='dispatch')
class RequestPublishedArticle(RequestCommentary):
form_class = RequestPublishedArticleForm form_class = RequestPublishedArticleForm
template_name = 'commentaries/request_published_article.html' template_name = 'commentaries/request_published_article.html'
success_url = reverse_lazy('scipost:personal_page')
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(RequestPublishedArticle, self).get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['doi_query_form'] = DOIToQueryForm() context['query_form'] = DOIToQueryForm()
return context return context
def form_valid(self, form):
messages.success(self.request, strings.acknowledge_request_commentary)
return super(RequestPublishedArticle, self).form_valid(form)
@method_decorator(permission_required( @method_decorator(permission_required(
'scipost.can_request_commentary_pages', raise_exception=True), name='dispatch') 'scipost.can_request_commentary_pages', raise_exception=True), name='dispatch')
class RequestArxivPreprint(CreateView): class RequestArxivPreprint(RequestCommentary):
form_class = RequestArxivPreprintForm form_class = RequestArxivPreprintForm
template_name = 'commentaries/request_arxiv_preprint.html' template_name = 'commentaries/request_arxiv_preprint.html'
success_url = reverse_lazy('scipost:personal_page')
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(RequestArxivPreprint, self).get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['arxiv_query_form'] = ArxivQueryForm() context['query_form'] = ArxivQueryForm()
return context return context
def form_valid(self, form):
messages.success(self.request, strings.acknowledge_request_commentary)
return super(RequestArxivPreprint, self).form_valid(form)
@permission_required('scipost.can_request_commentary_pages', raise_exception=True) @permission_required('scipost.can_request_commentary_pages', raise_exception=True)
def prefill_using_DOI(request): def prefill_using_DOI(request):
...@@ -73,7 +73,7 @@ def prefill_using_DOI(request): ...@@ -73,7 +73,7 @@ def prefill_using_DOI(request):
if doi_query_form.is_valid(): if doi_query_form.is_valid():
prefill_data = doi_query_form.request_published_article_form_prefill_data() prefill_data = doi_query_form.request_published_article_form_prefill_data()
form = RequestPublishedArticleForm(initial=prefill_data) form = RequestPublishedArticleForm(initial=prefill_data)
messages.success(request, strings.acknowledge_doi_query) messages.success(request, strings.acknowledge_doi_query, fail_silently=True)
else: else:
form = RequestPublishedArticleForm() form = RequestPublishedArticleForm()
...@@ -93,7 +93,7 @@ def prefill_using_arxiv_identifier(request): ...@@ -93,7 +93,7 @@ def prefill_using_arxiv_identifier(request):
if arxiv_query_form.is_valid(): if arxiv_query_form.is_valid():
prefill_data = arxiv_query_form.request_arxiv_preprint_form_prefill_data() prefill_data = arxiv_query_form.request_arxiv_preprint_form_prefill_data()
form = RequestArxivPreprintForm(initial=prefill_data) form = RequestArxivPreprintForm(initial=prefill_data)
messages.success(request, strings.acknowledge_arxiv_query) messages.success(request, strings.acknowledge_arxiv_query, fail_silently=True)
else: else:
form = RequestArxivPreprintForm() form = RequestArxivPreprintForm()
...@@ -173,6 +173,7 @@ class CommentaryListView(ListView): ...@@ -173,6 +173,7 @@ class CommentaryListView(ListView):
model = Commentary model = Commentary
form = CommentarySearchForm form = CommentarySearchForm
paginate_by = 10 paginate_by = 10
context_object_name = 'commentary_list'
def get_queryset(self): def get_queryset(self):
'''Perform search form here already to get the right pagination numbers.''' '''Perform search form here already to get the right pagination numbers.'''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment