|
5 | 5 |
|
6 | 6 | from urllib.parse import urljoin, urlparse |
7 | 7 |
|
| 8 | +from waffle import testutils |
| 9 | + |
8 | 10 | from api.base.settings.defaults import API_BASE |
9 | 11 | from api.base.versioning import CREATE_REGISTRATION_FIELD_CHANGE_VERSION |
10 | 12 | from api_tests.nodes.views.test_node_draft_registration_list import AbstractDraftRegistrationTestCase |
11 | 13 | from api_tests.subjects.mixins import SubjectsFilterMixin |
12 | 14 | from api_tests.registrations.filters.test_filters import RegistrationListFilteringMixin |
13 | 15 | from api_tests.utils import create_test_file |
14 | 16 | from framework.auth.core import Auth |
| 17 | +from osf import features |
15 | 18 | from osf.models import RegistrationSchema, Registration |
16 | 19 | from osf_tests.factories import ( |
17 | 20 | EmbargoFactory, |
@@ -1559,6 +1562,41 @@ def test_registration_draft_must_be_draft_of_current_node( |
1559 | 1562 | self, mock_enqueue, app, user, schema, url_registrations_ver): |
1560 | 1563 | # Overrides TestNodeRegistrationCreate - node is not in URL in this workflow |
1561 | 1564 | return |
| 1565 | + @pytest.fixture |
| 1566 | + def manual_guid(self): |
| 1567 | + return 'abcde' |
| 1568 | + |
| 1569 | + @pytest.fixture |
| 1570 | + def manual_doi(self): |
| 1571 | + return '10.70102/FK2osf.io/abcde' |
| 1572 | + |
| 1573 | + @pytest.fixture |
| 1574 | + def enable_flag(self): |
| 1575 | + with testutils.override_flag(features.MANUAL_DOI_AND_GUID, True): |
| 1576 | + yield |
| 1577 | + |
| 1578 | + @pytest.fixture |
| 1579 | + def manual_guid_payload(self, payload, manual_guid, manual_doi): |
| 1580 | + payload['data']['attributes'] |= { |
| 1581 | + 'manual_doi': manual_doi, |
| 1582 | + 'manual_guid': manual_guid, |
| 1583 | + } |
| 1584 | + |
| 1585 | + return payload |
| 1586 | + |
| 1587 | + def test_fail_create_registration_with_manual_guid(self, app, user, schema, url_registrations, manual_guid_payload, manual_guid, manual_doi): |
| 1588 | + res = app.post_json_api(url_registrations, manual_guid_payload, auth=user.auth, expect_errors=True) |
| 1589 | + assert res.status_code == 400 |
| 1590 | + print(res.status_code) |
| 1591 | + |
| 1592 | + def test_create_registration_with_manual_guid(self, app, user, schema, url_registrations, manual_guid_payload, manual_guid, manual_doi, enable_flag): |
| 1593 | + res = app.post_json_api(url_registrations, manual_guid_payload, auth=user.auth) |
| 1594 | + data = res.json['data'] |
| 1595 | + assert res.status_code == 201 |
| 1596 | + assert data['id'] == manual_guid, 'manual guid was not assigned' |
| 1597 | + identifiers_response = app.get(data['relationships']['identifiers']['links']['related']['href'], auth=user.auth) |
| 1598 | + assert identifiers_response.status_code == 200 |
| 1599 | + assert identifiers_response.json['data'][0]['attributes']['value'] == manual_doi |
1562 | 1600 |
|
1563 | 1601 | @mock.patch('framework.celery_tasks.handlers.enqueue_task') |
1564 | 1602 | def test_need_admin_perms_on_draft( |
|
0 commit comments