diff --git a/comments/factories.py b/comments/factories.py new file mode 100644 index 0000000000000000000000000000000000000000..aaf4cc9698021923b66ba04444a4e612d0650240 --- /dev/null +++ b/comments/factories.py @@ -0,0 +1,14 @@ +import factory + +from django.utils import timezone + +from scipost.factories import ContributorFactory +from .models import Comment + + +class CommentFactory(factory.django.DjangoModelFactory): + class Meta: + model = Comment + + comment_text = factory.Faker('text') + date_submitted = timezone.now() diff --git a/theses/factories.py b/theses/factories.py index bc57863b350e82579b8725bd27884bdeb1382c24..dd00356dfde523e224b0c141a54c9aa581a6c0c5 100644 --- a/theses/factories.py +++ b/theses/factories.py @@ -28,4 +28,3 @@ class VetThesisLinkFormFactory(FormFactory): model = VetThesisLinkForm action_option = VetThesisLinkForm.ACCEPT - # justification = factory.Faker('lorem') diff --git a/theses/test_views.py b/theses/test_views.py index f87971e805c99a08a5d75d2c588d88331829f284..e0ffeeb35c5e5c80aa8a469e51da3f88134e9ec7 100644 --- a/theses/test_views.py +++ b/theses/test_views.py @@ -7,22 +7,40 @@ from django.contrib.auth.models import Group from django.urls import reverse, reverse_lazy from django.contrib.messages.storage.fallback import FallbackStorage -from .views import RequestThesisLink, VetThesisLinkRequests from scipost.factories import UserFactory, ContributorFactory +from comments.factories import CommentFactory +from comments.forms import CommentForm +from .views import RequestThesisLink, VetThesisLinkRequests, thesis_detail from .factories import ThesisLinkFactory, VetThesisLinkFormFactory from .models import ThesisLink +from common.helpers import model_form_data class TestThesisDetail(TestCase): fixtures = ['groups', 'permissions'] def test_visits_valid_thesis_detail(self): + """ A visitor does not have to be logged in to view a thesis link. """ thesis_link = ThesisLinkFactory() client = Client() target = reverse('theses:thesis', kwargs={'thesislink_id': thesis_link.id}) response = client.post(target) self.assertEqual(response.status_code, 200) + def test_submitting_comment_creates_comment(self): + """ Valid Comment gets saved """ + contributor = ContributorFactory() + thesislink = ThesisLinkFactory() + valid_comment_data = model_form_data(CommentFactory(), CommentForm) + target = reverse('theses:thesis', kwargs={'thesislink_id': thesislink.id}) + + request = RequestFactory().post(target, valid_comment_data) + request.user = contributor.user + + response = thesis_detail(request, thesislink_id=thesislink.id) + print(response) + self.assertTrue(False) + class TestRequestThesisLink(TestCase): fixtures = ['groups', 'permissions'] diff --git a/theses/views.py b/theses/views.py index 80ecb69520bc9bbc385e74391fe2c9e6f577b887..f5646202c51eba354f847cccb375301b0cb9a159 100644 --- a/theses/views.py +++ b/theses/views.py @@ -215,13 +215,13 @@ def thesis_detail(request, thesislink_id): new_comment.save() author.nr_comments = Comment.objects.filter(author=author).count() author.save() - request.session['thesislink_id'] = thesislink_id + # request.session['thesislink_id'] = thesislink_id context = {'ack_header': 'Thank you for contributing a Comment.', 'ack_message': 'It will soon be vetted by an Editor.', 'followup_message': 'Back to the ', 'followup_link': reverse( 'theses:thesis', - kwargs={'thesislink_id': newcomment.thesislink.id} + kwargs={'thesislink_id': new_comment.thesislink.id} ), 'followup_link_label': ' Thesis Link page you came from' }