From 02f50eeccdc0d4af4fba342761e6ebf61b612eae Mon Sep 17 00:00:00 2001 From: Steven Eardley Date: Thu, 3 Oct 2024 16:10:54 +0100 Subject: [PATCH] Correct the method for skipping tests --- .../test_readonly_journal.py | 61 +++++++++++++++++-- ...ion_forms.py => test_application_forms.py} | 1 + 2 files changed, 56 insertions(+), 6 deletions(-) rename doajtest/unit/{_disabled_test_application_forms.py => test_application_forms.py} (95%) diff --git a/doajtest/unit/application_processors/test_readonly_journal.py b/doajtest/unit/application_processors/test_readonly_journal.py index 9e4bc4c42a..3a98d69805 100644 --- a/doajtest/unit/application_processors/test_readonly_journal.py +++ b/doajtest/unit/application_processors/test_readonly_journal.py @@ -39,14 +39,63 @@ def tearDown(self): super(TestReadOnlyJournal, self).tearDown() lcc.lookup_code = self.old_lookup_code - ########################################################### - # Tests on the publisher's re-journal form - ########################################################### - def test_01_readonly_journal_success(self): - """Give the read-only journal form a full workout""" + def test_01_unknown_context(self): + """ Pulling the wrong context gives an exception """ + + with self.assertRaises(AttributeError): + formulaic_context = JournalFormFactory.context("readonly") + fc = formulaic_context.processor(source=models.Journal(**JOURNAL_SOURCE)) + + def test_02_editor_readonly_journal(self): + """ Tests on the editor's read-only journal form """ + + # we start by constructing it from source + formulaic_context = JournalFormFactory.context("editor_readonly") + fc = formulaic_context.processor(source=models.Journal(**JOURNAL_SOURCE)) + assert isinstance(fc, ReadOnlyJournal) + assert fc.form is not None + assert fc.source is not None + assert fc.form_data is None + + # now construct it from form data (with a known source) + journal_obj = models.Journal(**JOURNAL_SOURCE) + journal_bibjson_obj = journal_obj.bibjson() + fc = formulaic_context.processor( + formdata=JOURNAL_FORM, + source=journal_obj + ) + + assert isinstance(fc, ReadOnlyJournal) + assert fc.form is not None + assert fc.source is not None + assert fc.form_data is not None + + # see that form has the correct info from an object (after all, that's the only point of having the form) + assert fc.form.title.data == journal_bibjson_obj.title + assert fc.form.pissn.data == journal_bibjson_obj.pissn + assert fc.form.eissn.data == journal_bibjson_obj.eissn + + # test each of the workflow components individually ... + + # run the validation + assert fc.validate(), fc.form.errors + + # run the crosswalk (no need to look in detail, xwalks are tested elsewhere) + fc.form2target() + assert fc.target is None # can't edit data using this form + + # patch the target with data from the source + fc.patch_target() + assert fc.target is None # can't edit data using this form + + # shouldn't be able to finalise, can't edit data using this form + self.assertRaises(Exception, fc.finalise) + + def test_03_maned_readonly_journal(self): + """ Tests on the managing editor's read-only journal form """ # we start by constructing it from source - formulaic_context = JournalFormFactory.context("readonly") + formulaic_context = JournalFormFactory.context("admin_readonly") fc = formulaic_context.processor(source=models.Journal(**JOURNAL_SOURCE)) assert isinstance(fc, ReadOnlyJournal) assert fc.form is not None diff --git a/doajtest/unit/_disabled_test_application_forms.py b/doajtest/unit/test_application_forms.py similarity index 95% rename from doajtest/unit/_disabled_test_application_forms.py rename to doajtest/unit/test_application_forms.py index 41a46cfb5b..7e0fd9e47e 100644 --- a/doajtest/unit/_disabled_test_application_forms.py +++ b/doajtest/unit/test_application_forms.py @@ -42,6 +42,7 @@ def test_disable_edit_note_except_editing_user(user_id, expected_result): class TestEditableNote(DoajTestCase): + @pytest.mark.skip(reason="Untestable: we don't have the editor.journal_page route enabled") # FIXME: permanently? def test_note_textarea_disabled_correctly(self): pwd = 'password123' acc = models.Account(**AccountFixtureFactory.make_editor_source())