From e3723b45c395549f623eb153a1e77f486b077021 Mon Sep 17 00:00:00 2001
From: Geert Kapteijns <ghkapteijns@gmail.com>
Date: Sat, 13 May 2017 22:38:51 +0200
Subject: [PATCH] add RequestArxivPreprintForm tests

---
 commentaries/test_forms.py | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/commentaries/test_forms.py b/commentaries/test_forms.py
index b894b0cd1..75d5a21df 100644
--- a/commentaries/test_forms.py
+++ b/commentaries/test_forms.py
@@ -5,8 +5,9 @@ from django.test import TestCase
 from common.helpers import model_form_data
 from scipost.factories import UserFactory
 
-from .factories import VettedCommentaryFactory, UnvettedCommentaryFactory
-from .forms import RequestCommentaryForm, RequestPublishedArticleForm, VetCommentaryForm, DOIToQueryForm, ArxivQueryForm
+from .factories import VettedCommentaryFactory, UnvettedCommentaryFactory, UnvettedArxivPreprintCommentaryFactory
+from .forms import RequestCommentaryForm, RequestPublishedArticleForm, VetCommentaryForm, DOIToQueryForm, \
+    ArxivQueryForm, RequestArxivPreprintForm
 from .models import Commentary
 from common.helpers.test import add_groups_and_permissions
 
@@ -178,3 +179,29 @@ class TestRequestPublishedArticleForm(TestCase):
         invalid_data = {**self.valid_form_data, **{'pub_DOI': ''}}
         form = RequestPublishedArticleForm(invalid_data)
         self.assertEqual(form.is_valid(), False)
+
+
+class TestRequestArxivPreprintForm(TestCase):
+    def setUp(self):
+        add_groups_and_permissions()
+        factory_instance = UnvettedArxivPreprintCommentaryFactory.build()
+        self.user = UserFactory()
+        self.valid_form_data = model_form_data(factory_instance, RequestPublishedArticleForm)
+        self.valid_form_data['arxiv_identifier'] = factory_instance.arxiv_identifier
+
+    def test_valid_data_is_valid(self):
+        form = RequestArxivPreprintForm(self.valid_form_data)
+        self.assertTrue(form.is_valid())
+
+    def test_identifier_that_already_has_commentary_page_is_invalid(self):
+        commentary = UnvettedArxivPreprintCommentaryFactory()
+        invalid_data = {**self.valid_form_data, **{'arxiv_identifier': commentary.arxiv_identifier}}
+        form = RequestArxivPreprintForm(invalid_data)
+        self.assertEqual(form.is_valid(), False)
+        error_message = form.errors['arxiv_identifier'][0]
+        self.assertRegexpMatches(error_message, re.compile('already exist'))
+
+    def test_commentary_without_arxiv_identifier_is_invalid(self):
+        invalid_data = {**self.valid_form_data, **{'arxiv_identifier': ''}}
+        form = RequestArxivPreprintForm(invalid_data)
+        self.assertEqual(form.is_valid(), False)
-- 
GitLab