|
1 | | -import pytest |
2 | 1 | from urllib.parse import urlparse |
3 | 2 |
|
| 3 | +import pytest |
4 | 4 | from django.utils.timezone import now |
| 5 | +from waffle.testutils import override_switch |
5 | 6 |
|
6 | 7 | from api.base.settings.defaults import API_BASE |
7 | 8 | from api.taxonomies.serializers import subjects_as_relationships_version |
8 | | -from api_tests.subjects.mixins import UpdateSubjectsMixin, SubjectsFilterMixin, SubjectsListMixin, SubjectsRelationshipMixin |
| 9 | +from api_tests.share._utils import mock_update_share |
| 10 | +from api_tests.subjects.mixins import UpdateSubjectsMixin, SubjectsFilterMixin, SubjectsListMixin, \ |
| 11 | + SubjectsRelationshipMixin |
| 12 | +from api_tests.utils import disconnected_from_listeners |
9 | 13 | from framework.auth.core import Auth |
| 14 | +from osf import features |
| 15 | +from osf.models import Collection, VersionedGuidMixin |
| 16 | +from osf.utils.permissions import ADMIN, WRITE, READ |
| 17 | +from osf.utils.sanitize import strip_html |
10 | 18 | from osf_tests.factories import ( |
| 19 | + CedarMetadataTemplateFactory, |
11 | 20 | CollectionFactory, |
| 21 | + CollectionProviderFactory, |
12 | 22 | NodeFactory, |
13 | 23 | RegistrationFactory, |
14 | 24 | PreprintFactory, |
15 | 25 | ProjectFactory, |
16 | 26 | AuthUserFactory, |
17 | 27 | SubjectFactory, |
18 | 28 | ) |
19 | | -from osf.models import Collection, VersionedGuidMixin |
20 | | -from osf.utils.sanitize import strip_html |
21 | | -from osf.utils.permissions import ADMIN, WRITE, READ |
22 | 29 | from website.project.signals import contributor_removed |
23 | | -from api_tests.utils import disconnected_from_listeners |
24 | | -from api_tests.share._utils import mock_update_share |
25 | 30 | from website.views import find_bookmark_collection |
26 | 31 |
|
27 | | - |
28 | 32 | url_collection_list = f'/{API_BASE}collections/' |
29 | 33 |
|
30 | 34 |
|
@@ -4384,6 +4388,80 @@ def test_filters(self, app, collection_with_one_collection_submission, collectio |
4384 | 4388 | assert len(res.json['data']) == 1 |
4385 | 4389 |
|
4386 | 4390 |
|
| 4391 | +@pytest.mark.django_db |
| 4392 | +class TestCollectionSubmissionWithCedarSwitch: |
| 4393 | + |
| 4394 | + @pytest.fixture() |
| 4395 | + def cedar_template(self): |
| 4396 | + return CedarMetadataTemplateFactory( |
| 4397 | + schema_name='Test Schema', |
| 4398 | + cedar_id='https://cedar.example.com/template/1', |
| 4399 | + template_version=1, |
| 4400 | + ) |
| 4401 | + |
| 4402 | + @pytest.fixture() |
| 4403 | + def provider(self, cedar_template): |
| 4404 | + provider = CollectionProviderFactory() |
| 4405 | + provider.required_metadata_template = cedar_template |
| 4406 | + provider.save() |
| 4407 | + return provider |
| 4408 | + |
| 4409 | + @pytest.fixture() |
| 4410 | + def collection(self, user_one, provider): |
| 4411 | + c = CollectionFactory(creator=user_one) |
| 4412 | + c.provider = provider |
| 4413 | + c.save() |
| 4414 | + return c |
| 4415 | + |
| 4416 | + @pytest.fixture() |
| 4417 | + def collection_no_provider(self, user_one): |
| 4418 | + return CollectionFactory(creator=user_one) |
| 4419 | + |
| 4420 | + @pytest.fixture() |
| 4421 | + def project(self, user_one): |
| 4422 | + return ProjectFactory(creator=user_one) |
| 4423 | + |
| 4424 | + @pytest.fixture() |
| 4425 | + def url(self, collection): |
| 4426 | + return f'/{API_BASE}collections/{collection._id}/collected_metadata/' |
| 4427 | + |
| 4428 | + @pytest.fixture() |
| 4429 | + def url_no_provider(self, collection_no_provider): |
| 4430 | + return f'/{API_BASE}collections/{collection_no_provider._id}/collected_metadata/' |
| 4431 | + |
| 4432 | + @pytest.fixture() |
| 4433 | + def payload(self): |
| 4434 | + def make_collection_payload(**attributes): |
| 4435 | + return { |
| 4436 | + 'data': { |
| 4437 | + 'type': 'collected-metadata', |
| 4438 | + 'attributes': attributes, |
| 4439 | + } |
| 4440 | + } |
| 4441 | + return make_collection_payload |
| 4442 | + |
| 4443 | + def test_switch_active_no_provider_submission_succeeds(self, app, user_one, project, url_no_provider, payload): |
| 4444 | + with mock_update_share(): |
| 4445 | + with override_switch(features.COLLECTION_SUBMISSION_WITH_CEDAR, active=True): |
| 4446 | + res = app.post_json_api( |
| 4447 | + url_no_provider, |
| 4448 | + payload(guid=project._id), |
| 4449 | + auth=user_one.auth, |
| 4450 | + ) |
| 4451 | + assert res.status_code == 201 |
| 4452 | + |
| 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 | + ) |
| 4461 | + assert res.status_code == 400 |
| 4462 | + assert 'CEDAR metadata record' in res.json['errors'][0]['detail'] |
| 4463 | + |
| 4464 | + |
4387 | 4465 | class TestCollectedMetaSubjectFiltering(SubjectsFilterMixin): |
4388 | 4466 | @pytest.fixture() |
4389 | 4467 | def project_one(self, user): |
|
0 commit comments