|
10 | 10 | from api_tests.subjects.mixins import UpdateSubjectsMixin, SubjectsFilterMixin, SubjectsListMixin, \ |
11 | 11 | SubjectsRelationshipMixin |
12 | 12 | from api_tests.utils import disconnected_from_listeners |
| 13 | +from tests.utils import capture_notifications |
13 | 14 | from framework.auth.core import Auth |
14 | 15 | from osf import features |
15 | 16 | from osf.models import Collection, VersionedGuidMixin |
@@ -4450,16 +4451,70 @@ def test_switch_active_no_provider_submission_succeeds(self, app, user_one, proj |
4450 | 4451 | ) |
4451 | 4452 | assert res.status_code == 201 |
4452 | 4453 |
|
4453 | | - def test_switch_active_missing_cedar_record_submission_fails(self, app, user_one, project, url, payload): |
4454 | | - with override_switch(features.COLLECTION_SUBMISSION_WITH_CEDAR, active=True): |
4455 | | - res = app.post_json_api( |
4456 | | - url, |
4457 | | - payload(guid=project._id), |
4458 | | - auth=user_one.auth, |
4459 | | - expect_errors=True, |
4460 | | - ) |
| 4454 | + def test_switch_active_submission_without_cedar_record_fails( |
| 4455 | + self, app, user_one, project, url, payload, cedar_template): |
| 4456 | + with capture_notifications(expect_none=True): |
| 4457 | + with mock_update_share(): |
| 4458 | + with override_switch(features.COLLECTION_SUBMISSION_WITH_CEDAR, active=True): |
| 4459 | + res = app.post_json_api( |
| 4460 | + url, |
| 4461 | + payload(guid=project._id), |
| 4462 | + auth=user_one.auth, |
| 4463 | + expect_errors=True, |
| 4464 | + ) |
4461 | 4465 | assert res.status_code == 400 |
4462 | | - assert 'CEDAR metadata record' in res.json['errors'][0]['detail'] |
| 4466 | + |
| 4467 | + def test_switch_active_submission_with_cedar_record_succeeds( |
| 4468 | + self, app, user_one, project, url, payload, cedar_template): |
| 4469 | + from osf.models import CedarMetadataRecord |
| 4470 | + CedarMetadataRecord.objects.create( |
| 4471 | + guid=project.guids.first(), |
| 4472 | + template=cedar_template, |
| 4473 | + metadata={'title': 'Test'}, |
| 4474 | + is_published=True, |
| 4475 | + ) |
| 4476 | + with capture_notifications(): |
| 4477 | + with mock_update_share(): |
| 4478 | + with override_switch(features.COLLECTION_SUBMISSION_WITH_CEDAR, active=True): |
| 4479 | + res = app.post_json_api( |
| 4480 | + url, |
| 4481 | + payload(guid=project._id), |
| 4482 | + auth=user_one.auth, |
| 4483 | + ) |
| 4484 | + assert res.status_code == 201 |
| 4485 | + |
| 4486 | + def test_switch_inactive_submission_without_cedar_record_succeeds( |
| 4487 | + self, app, user_one, project, url, payload, cedar_template): |
| 4488 | + with capture_notifications(): |
| 4489 | + with mock_update_share(): |
| 4490 | + with override_switch(features.COLLECTION_SUBMISSION_WITH_CEDAR, active=False): |
| 4491 | + res = app.post_json_api(url, payload(guid=project._id), auth=user_one.auth) |
| 4492 | + assert res.status_code == 201 |
| 4493 | + |
| 4494 | + def test_switch_active_update_does_not_alter_cedar_record( |
| 4495 | + self, app, user_one, project, url, payload, cedar_template, collection): |
| 4496 | + from osf.models import CedarMetadataRecord |
| 4497 | + original_metadata = {'title': 'Original'} |
| 4498 | + CedarMetadataRecord.objects.create( |
| 4499 | + guid=project.guids.first(), |
| 4500 | + template=cedar_template, |
| 4501 | + metadata=original_metadata, |
| 4502 | + is_published=True, |
| 4503 | + ) |
| 4504 | + collection.status_choices = ['pending', 'approved'] |
| 4505 | + collection.save() |
| 4506 | + with capture_notifications(): |
| 4507 | + with mock_update_share(): |
| 4508 | + with override_switch(features.COLLECTION_SUBMISSION_WITH_CEDAR, active=True): |
| 4509 | + res = app.post_json_api(url, payload(guid=project._id, status='pending'), auth=user_one.auth) |
| 4510 | + assert res.status_code == 201 |
| 4511 | + |
| 4512 | + detail_url = f'/{API_BASE}collections/{collection._id}/collected_metadata/{project._id}/' |
| 4513 | + with override_switch(features.COLLECTION_SUBMISSION_WITH_CEDAR, active=True): |
| 4514 | + app.patch_json_api(detail_url, payload(status='approved'), auth=user_one.auth) |
| 4515 | + |
| 4516 | + record = CedarMetadataRecord.objects.get(guid__in=project.guids.all(), template=cedar_template) |
| 4517 | + assert record.metadata == original_metadata |
4463 | 4518 |
|
4464 | 4519 |
|
4465 | 4520 | class TestCollectedMetaSubjectFiltering(SubjectsFilterMixin): |
|
0 commit comments