diff --git a/commentaries/factories.py b/commentaries/factories.py new file mode 100644 index 0000000000000000000000000000000000000000..f0bae1a0912e9a18ceb0c6f079918c595534948b --- /dev/null +++ b/commentaries/factories.py @@ -0,0 +1,33 @@ +import factory + +from .models import Commentary, COMMENTARY_TYPES + +from scipost.constants import SCIPOST_DISCIPLINES, SCIPOST_SUBJECT_AREAS +from scipost.factories import ContributorFactory +from journals.models import SCIPOST_JOURNALS_DOMAINS + + +class CommentaryFactory(factory.django.DjangoModelFactory): + class Meta: + model = Commentary + abstract = True + + requested_by = factory.SubFactory(ContributorFactory) + vetted_by = factory.SubFactory(ContributorFactory) + type = COMMENTARY_TYPES[0][0] + discipline = SCIPOST_DISCIPLINES[0][0] + domain = SCIPOST_JOURNALS_DOMAINS[0][0] + subject_area = SCIPOST_SUBJECT_AREAS[0][1][0][0] + pub_title = factory.Sequence(lambda n: "Commentary %d" % n) + pub_DOI = '10.1103/PhysRevB.92.214427' + arxiv_identifier = '1610.06911v1' + author_list = factory.Faker('name') + pub_abstract = factory.Faker('text') + + +class EmptyCommentaryFactory(CommentaryFactory): + pub_DOI = None + arxiv_identifier = None + +class VettedCommentaryFactory(CommentaryFactory): + vetted = True diff --git a/commentaries/test_forms.py b/commentaries/test_forms.py index 2e9cb5f6ba351402af656aec1be5d9ac257bc5c0..694ce19ec56c93503b879a51038f068b06947f7c 100644 --- a/commentaries/test_forms.py +++ b/commentaries/test_forms.py @@ -1 +1,42 @@ +import factory + from django.test import TestCase + +from scipost.factories import UserFactory + +from .factories import VettedCommentaryFactory +from .forms import RequestCommentaryForm +from common.helpers import model_form_data + + +class TestRequestCommentaryForm(TestCase): + fixtures = ['permissions', 'groups'] + + def setUp(self): + factory_instance = VettedCommentaryFactory.build() + self.user = UserFactory() + self.valid_form_data = model_form_data(factory_instance, RequestCommentaryForm) + + def test_valid_data_is_valid_for_arxiv(self): + """Test valid form for Arxiv identifier""" + form_data = self.valid_form_data + form_data['pub_DOI'] = '' + form = RequestCommentaryForm(form_data, user=self.user) + self.assertTrue(form.is_valid()) + + def test_valid_data_is_valid_for_DOI(self): + """Test valid form for DOI""" + form_data = self.valid_form_data + form_data['arxiv_identifier'] = '' + form = RequestCommentaryForm(form_data, user=self.user) + self.assertTrue(form.is_valid()) + + # def test_form_has_no_identifiers(self): + # """Test invalid form has no DOI nor Arxiv ID""" + # form_data = self.valid_form_data + # form_data['pub_DOI'] = '' + # form_data['arxiv_identifier'] = '' + # form = RequestCommentaryForm(form_data, user=self.user) + # form_response = form.is_valid() + # print(form_response) + # self.assertFormError(form_response, form, 'arxiv_identifier', None)