Skip to content

Commit

Permalink
Merge pull request #835 from DH-IT-Portal-Development/temp/embargo_an…
Browse files Browse the repository at this point in the history
…d_tests_wip

Temp/embargo and tests wip
  • Loading branch information
EdoStorm96 authored Jan 8, 2025
2 parents c4ef888 + 790b5d0 commit 300591d
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 81 deletions.
121 changes: 69 additions & 52 deletions proposals/fixtures/testing/test_proposals.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
"model": "proposals.proposal",
"pk": 1,
"fields": {
"reference_number": "23-003-01",
"reference_number": "24-009-01",
"reviewing_committee": 3,
"institution": 2,
"date_start": "2025-01-01",
"title": "Fixture proposal",
"summary": "asdf",
"institution": 4,
"date_start": "2024-12-27",
"title": "Normal test proposal",
"summary": "fsefsdfes",
"other_applicants": false,
"other_stakeholders": false,
"stakeholders": "",
"translated_forms": true,
"translated_forms_languages": "asdf",
"funding_details": "",
"funding_name": "",
"comments": "asdf",
"inform_local_staff": true,
"embargo": true,
"embargo_end_date": "2024-09-01",
"translated_forms": false,
"translated_forms_languages": null,
"funding_details": "fsefdsf",
"funding_name": "esfdegf",
"comments": "aaaaa",
"inform_local_staff": null,
"embargo": false,
"embargo_end_date": null,
"in_archive": false,
"is_pre_assessment": false,
"pre_assessment_pdf": "",
Expand All @@ -28,23 +28,28 @@
"pre_approval_pdf": "",
"in_course": false,
"is_exploration": false,
"pdf": "FETC-AK-23-003-01-Proposal.pdf",
"studies_similar": false,
"studies_number": 3,
"pdf": "",
"studies_similar": true,
"studies_number": 1,
"status": 1,
"status_review": null,
"dmp_file": "FETC-AK-23-003-01-DMP.pdf",
"privacy_officer": false,
"dmp_file": "",
"confirmation_comments": "",
"date_created": "2023-11-28T12:59:17.670Z",
"date_modified": "2023-11-28T13:36:55.297Z",
"date_created": "2024-12-19T14:52:13.624Z",
"date_modified": "2024-12-23T10:29:26.363Z",
"date_submitted_supervisor": null,
"date_reviewed_supervisor": null,
"date_submitted": "2023-11-28T13:36:55.296Z",
"date_submitted": null,
"date_reviewed": null,
"date_confirmed": null,
"has_minor_revision": false,
"minor_revision_description": null,
"self_assessment": "asdf",
"self_assessment": "gsdfges",
"knowledge_security": "N",
"knowledge_security_details": "",
"researcher_risk": "N",
"researcher_risk_details": "",
"relation": 5,
"student_program": "",
"student_context": null,
Expand All @@ -55,7 +60,7 @@
"parent": null,
"is_revision": false,
"funding": [
1
3
],
"applicants": [
5
Expand All @@ -66,23 +71,23 @@
"model": "proposals.proposal",
"pk": 2,
"fields": {
"reference_number": "23-004-01",
"reference_number": "24-010-01",
"reviewing_committee": 3,
"institution": 2,
"date_start": "2024-08-01",
"title": "Fixture Preassessment",
"institution": 4,
"date_start": "2042-12-25",
"title": "Preassessment test proposal",
"summary": "",
"other_applicants": false,
"other_stakeholders": true,
"stakeholders": "asdf",
"other_stakeholders": false,
"stakeholders": "",
"translated_forms": null,
"translated_forms_languages": null,
"funding_details": "",
"funding_name": "",
"comments": "asdf",
"funding_name": "aaaaa",
"comments": "asdfda",
"inform_local_staff": null,
"embargo": true,
"embargo_end_date": "2024-11-01",
"embargo": null,
"embargo_end_date": null,
"in_archive": false,
"is_pre_assessment": true,
"pre_assessment_pdf": "test_pdf.pdf",
Expand All @@ -91,23 +96,28 @@
"pre_approval_pdf": "",
"in_course": false,
"is_exploration": false,
"pdf": "FETC-AK-23-004-01-Proposal.pdf",
"pdf": "",
"studies_similar": null,
"studies_number": 1,
"status": 1,
"status_review": null,
"privacy_officer": null,
"dmp_file": "",
"confirmation_comments": "",
"date_created": "2023-11-28T14:10:12.708Z",
"date_modified": "2023-11-28T14:10:40.554Z",
"date_created": "2024-12-23T10:30:40.272Z",
"date_modified": "2024-12-23T10:35:22.000Z",
"date_submitted_supervisor": null,
"date_reviewed_supervisor": null,
"date_submitted": "2023-11-28T14:10:40.554Z",
"date_submitted": null,
"date_reviewed": null,
"date_confirmed": null,
"has_minor_revision": false,
"minor_revision_description": null,
"self_assessment": "asdf",
"knowledge_security": "",
"knowledge_security_details": "",
"researcher_risk": "",
"researcher_risk_details": "",
"relation": 5,
"student_program": "",
"student_context": null,
Expand All @@ -117,7 +127,9 @@
"supervisor": null,
"parent": null,
"is_revision": false,
"funding": [],
"funding": [
2
],
"applicants": [
5
]
Expand All @@ -127,48 +139,53 @@
"model": "proposals.proposal",
"pk": 3,
"fields": {
"reference_number": "23-005-01",
"reference_number": "24-011-01",
"reviewing_committee": 3,
"institution": 2,
"date_start": "2024-08-01",
"title": "Fixture Preapproval",
"summary": "asdf",
"institution": 4,
"date_start": "2046-12-21",
"title": "Preapproved test pdf",
"summary": "asd",
"other_applicants": false,
"other_stakeholders": false,
"stakeholders": "",
"translated_forms": null,
"translated_forms": false,
"translated_forms_languages": null,
"funding_details": "",
"funding_name": "",
"comments": "asdf",
"comments": "asd",
"inform_local_staff": null,
"embargo": true,
"embargo_end_date": "2025-01-10",
"embargo": false,
"embargo_end_date": null,
"in_archive": false,
"is_pre_assessment": false,
"pre_assessment_pdf": "",
"is_pre_approved": true,
"pre_approval_institute": "asdf",
"pre_approval_institute": "asd",
"pre_approval_pdf": "test_pdf.pdf",
"in_course": false,
"is_exploration": false,
"pdf": "FETC-AK-23-005-01-Proposal.pdf",
"pdf": "",
"studies_similar": null,
"studies_number": 1,
"status": 1,
"status_review": null,
"privacy_officer": true,
"dmp_file": "",
"confirmation_comments": "",
"date_created": "2023-11-28T14:28:19.045Z",
"date_modified": "2023-11-28T14:28:31.971Z",
"date_created": "2024-12-23T11:15:55.495Z",
"date_modified": "2024-12-23T11:17:02.358Z",
"date_submitted_supervisor": null,
"date_reviewed_supervisor": null,
"date_submitted": "2023-11-28T14:28:31.971Z",
"date_submitted": null,
"date_reviewed": null,
"date_confirmed": null,
"has_minor_revision": false,
"minor_revision_description": null,
"self_assessment": "asdf",
"self_assessment": "asd",
"knowledge_security": "",
"knowledge_security_details": "",
"researcher_risk": "",
"researcher_risk_details": "",
"relation": 5,
"student_program": "",
"student_context": null,
Expand Down
76 changes: 48 additions & 28 deletions proposals/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,10 @@ def __init__(self, *args, **kwargs):
# Needed for POST data
self.request = kwargs.pop("request", None)

# Needed for validation
self.final_validation = kwargs.pop("final_validation", None)
# we save this variable for later, but want it
# set for None for this part of the validation.
final_validation = kwargs.pop("final_validation", None)
self.final_validation = None

super(ProposalSubmitForm, self).__init__(*args, **kwargs)

Expand All @@ -847,6 +849,13 @@ def __init__(self, *args, **kwargs):
del self.fields["embargo"]
del self.fields["embargo_end_date"]

self.final_validation = final_validation

# If we have an existing instance and we're not POSTing,
# run an initial clean
if self.instance.pk and "data" not in kwargs:
self.initial_clean()

def clean(self):
"""
Check if the Proposal is complete:
Expand All @@ -857,53 +866,64 @@ def clean(self):

cleaned_data = super(ProposalSubmitForm, self).clean()

if (
check_local_facilities(self.proposal)
and cleaned_data["inform_local_staff"] is None
):
self.add_error("inform_local_staff", _("Dit veld is verplicht."))

if (
not self.instance.is_practice()
and not "js-redirect-submit" in self.request.POST
and not "save_back" in self.request.POST
):
if (
check_local_facilities(self.proposal)
and cleaned_data["inform_local_staff"] is None
):
self.add_error("inform_local_staff", _("Dit veld is verplicht."))

if cleaned_data["embargo"] is None:
self.add_error("embargo", _("Dit veld is verplicht."))
self.validate_embargo(cleaned_data)

embargo_end_date = cleaned_data["embargo_end_date"]
two_years_from_now = timezone.now().date() + timezone.timedelta(days=730)

if "embargo" in cleaned_data:
if cleaned_data["embargo"] is True and not embargo_end_date:
self.add_error(
"embargo_end_date",
_("Vul een datum in waarop de embargo afloopt."),
)

if embargo_end_date is not None and embargo_end_date > two_years_from_now:
self.add_error(
"embargo_end_date",
_(
"De embargo-periode kan maximaal 2 jaar zijn. Kies een datum binnen 2 jaar van vandaag."
),
)
# final_validation is a kwarg that should only be given by the
# actual submit view, not the stepper.
if not self.final_validation:
return
# For final validation, i.e. if a user is actually submitting,we
# For final validation, i.e. if a user is actually submitting, we
# instantiate a new stepper to reflect changes
# made to the current instance, which may not yet be saved.
from proposals.utils.stepper import Stepper

validator = Stepper(self.instance, request=self.request)
# And then we append stepper errors to show them to the user
# on the submit page
if validator.get_form_errors():
self.add_error(
None,
_("Aanvraag bevat nog foutmeldingen"),
)

def validate_embargo(self, cleaned_data):

# Only check embargo and end date if form was initialized with it.
if "embargo" not in self.fields:
return

self.mark_soft_required(cleaned_data, "embargo")

if "embargo" in cleaned_data:
self.check_dependency(
cleaned_data,
"embargo",
"embargo_end_date",
error_message=_("Vul een datum in waarop de embargo afloopt."),
)
embargo_end_date = cleaned_data.get("embargo_end_date", None)
if embargo_end_date:
two_years_from_now = timezone.now().date() + timezone.timedelta(days=730)
if embargo_end_date > two_years_from_now:
self.add_error(
"embargo_end_date",
_(
"De embargo-periode kan maximaal 2 jaar zijn. "
"Kies een datum binnen 2 jaar van vandaag."
),
)


class KnowledgeSecurityForm(SoftValidationMixin, ConditionalModelForm):

Expand Down
17 changes: 16 additions & 1 deletion proposals/tests/proposal_submission_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.test import TestCase

from main.tests import BaseViewTestCase
from proposals.models import Proposal, Relation
from proposals.models import Proposal, Relation, Wmo
from reviews.models import Review

from proposals.views.proposal_views import (
Expand Down Expand Up @@ -77,8 +77,15 @@ def setup_proposal(self):
Please note, this currently uses a mish-mash of both fixtures
and programmatically created users and objects.
"""
self.wmo = Wmo(
status=0,
metc="N",
is_medical="N",
)
self.wmo.save()
self.proposal = Proposal.objects.get(pk=1)
self.proposal.applicants.add(self.user)
self.proposal.wmo = self.wmo
self.proposal.save()
self.pre_assessment = Proposal.objects.get(pk=2)
self.pre_assessment.applicants.add(self.user)
Expand Down Expand Up @@ -156,6 +163,7 @@ def test_submission_unsupervised(self):
self.get_post_data(),
user=self.user,
)

self.assertIn(page.status_code, [302, 200])
self.refresh()
# Post-submission tests
Expand Down Expand Up @@ -225,6 +233,13 @@ class PreassessmentSubmitTestCase(
def setUp(self):
super().setUp()
self.proposal = self.pre_assessment
wmo = Wmo(
status=0,
metc="N",
is_medical="N",
)
wmo.save()
self.proposal.wmo = wmo


class PreapprovedSubmitTestCase(
Expand Down
Loading

0 comments on commit 300591d

Please sign in to comment.