当前位置: 首页>>代码示例>>Python>>正文


Python DraftRegistrationFactory.register方法代码示例

本文整理汇总了Python中osf_tests.factories.DraftRegistrationFactory.register方法的典型用法代码示例。如果您正苦于以下问题:Python DraftRegistrationFactory.register方法的具体用法?Python DraftRegistrationFactory.register怎么用?Python DraftRegistrationFactory.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在osf_tests.factories.DraftRegistrationFactory的用法示例。


在下文中一共展示了DraftRegistrationFactory.register方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestRegistrationCreate

# 需要导入模块: from osf_tests.factories import DraftRegistrationFactory [as 别名]
# 或者: from osf_tests.factories.DraftRegistrationFactory import register [as 别名]

#.........这里部分代码省略.........
                }
        }

        res = self.app.post_json_api(self.url, payload, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 400)
        assert_equal(res.json['errors'][0]['detail'], 'lift_embargo must be specified.')

    @mock.patch('framework.celery_tasks.handlers.enqueue_task')
    def test_embargo_must_be_less_than_four_years(self, mock_enqueue):
        today = timezone.now()
        five_years = (today + dateutil.relativedelta.relativedelta(years=5)).strftime('%Y-%m-%dT%H:%M:%S')
        payload = {
            "data": {
                "type": "registrations",
                "attributes": {
                    "draft_registration": self.draft_registration._id,
                    "registration_choice": "embargo",
                    "lift_embargo": five_years
                    }
                }
        }

        res = self.app.post_json_api(self.url, payload, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 400)
        assert_equal(res.json['errors'][0]['detail'], 'Registrations can only be embargoed for up to four years.')

    @mock.patch('framework.celery_tasks.handlers.enqueue_task')
    def test_embargo_registration(self, mock_enqueue):
        today = timezone.now()
        next_week = (today + dateutil.relativedelta.relativedelta(months=1)).strftime('%Y-%m-%dT%H:%M:%S')
        payload = {
            "data": {
                "type": "registrations",
                "attributes": {
                    "draft_registration": self.draft_registration._id,
                    "registration_choice": "embargo",
                    "lift_embargo": next_week
                    }
                }
        }

        res = self.app.post_json_api(self.url, payload, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 201)
        data = res.json['data']['attributes']
        assert_equal(data['registration'], True)
        assert_equal(data['pending_embargo_approval'], True)

    def test_embargo_end_date_must_be_in_the_future(self):
        today = timezone.now().strftime('%Y-%m-%dT%H:%M:%S')
        payload = {
            "data": {
                "type": "registrations",
                "attributes": {
                    "draft_registration": self.draft_registration._id,
                    "registration_choice": "embargo",
                    "lift_embargo": today
                    }
                }
        }

        res = self.app.post_json_api(self.url, payload, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 400)
        assert_equal(res.json['errors'][0]['detail'], 'Embargo end date must be at least three days in the future.')

    def test_invalid_embargo_end_date_format(self):
        today = timezone.now().isoformat()
        payload = {
            "data": {
                "type": "registrations",
                "attributes": {
                    "draft_registration": self.draft_registration._id,
                    "registration_choice": "embargo",
                    "lift_embargo": today
                    }
                }
        }

        res = self.app.post_json_api(self.url, payload, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 400)
        assert_equal(res.json['errors'][0]['detail'], 'Datetime has wrong format. Use one of these formats instead: YYYY-MM-DDThh:mm:ss.')

    @mock.patch('framework.celery_tasks.handlers.enqueue_task')
    def test_cannot_register_draft_that_has_already_been_registered(self, mock_enqueue):
        self.draft_registration.register(auth=Auth(self.user), save=True)
        res = self.app.post_json_api(self.url, self.payload, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)
        assert_equal(res.json['errors'][0]['detail'], 'This draft has already been registered and cannot be modified.')

    @mock.patch('framework.celery_tasks.handlers.enqueue_task')
    def test_cannot_register_draft_that_is_pending_review(self, mock_enqueue):
        with mock.patch.object(DraftRegistration, 'is_pending_review', mock.PropertyMock(return_value=True)):
            res = self.app.post_json_api(self.url, self.payload, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)
        assert_equal(res.json['errors'][0]['detail'], 'This draft is pending review and cannot be modified.')

    def test_cannot_register_draft_that_has_already_been_approved(self):
        with mock.patch.object(DraftRegistration, 'requires_approval', mock.PropertyMock(return_value=True)), mock.patch.object(DraftRegistration, 'is_approved', mock.PropertyMock(return_value=True)):
            res = self.app.post_json_api(self.url, self.payload, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 403)
        assert_equal(res.json['errors'][0]['detail'], 'This draft has already been approved and cannot be modified.')
开发者ID:adlius,项目名称:osf.io,代码行数:104,代码来源:test_registration_list.py

示例2: TestDraftListView

# 需要导入模块: from osf_tests.factories import DraftRegistrationFactory [as 别名]
# 或者: from osf_tests.factories.DraftRegistrationFactory import register [as 别名]
class TestDraftListView(AdminTestCase):
    @mock.patch('website.archiver.tasks.archive')
    def setUp(self, mock_archive):
        super(TestDraftListView, self).setUp()
        self.user = AuthUserFactory()
        self.schema = utils.draft_reg_util()
        self.dr1 = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=self.schema,
            registration_metadata=utils.SCHEMA_DATA
        )
        self.dr1.submit_for_review(self.user, {}, save=True)
        self.dr2 = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=self.schema,
            registration_metadata=utils.SCHEMA_DATA
        )
        self.dr2.submit_for_review(self.user, {}, save=True)
        # Simply here to NOT be returned when get_queryset is called
        self.unsubmitted_prereg = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=self.schema,
            registration_metadata=utils.SCHEMA_DATA
        )
        self.unsubmitted_prereg.register(Auth(self.user), save=True)
        self.request = RequestFactory().get('/fake_path')
        self.plain_view = DraftListView
        self.view = setup_view(self.plain_view(), self.request)

        self.url = reverse('pre_reg:prereg')

    def test_get_queryset(self):
        res = list(self.view.get_queryset())
        nt.assert_equal(len(res), 2)
        nt.assert_false(self.unsubmitted_prereg in res)
        nt.assert_is_instance(res[0], DraftRegistration)

    def test_queryset_returns_in_order_date_submitted(self):
        created_first_submitted_second = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=self.schema,
            registration_metadata=utils.SCHEMA_DATA
        )

        created_second_submitted_first = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=self.schema,
            registration_metadata=utils.SCHEMA_DATA
        )

        nt.assert_greater(created_second_submitted_first.datetime_initiated, created_first_submitted_second.datetime_initiated)

        created_second_submitted_first.submit_for_review(self.user, {}, save=True)
        created_first_submitted_second.submit_for_review(self.user, {}, save=True)
        created_second_submitted_first.datetime_updated = created_first_submitted_second.datetime_updated + datetime.timedelta(1)

        assert created_second_submitted_first.datetime_updated > created_first_submitted_second.datetime_updated
        res = list(self.view.get_queryset())
        nt.assert_true(res[0] == created_first_submitted_second)

    def test_get_context_data(self):
        self.view.object_list = self.view.get_queryset()
        res = self.view.get_context_data()
        nt.assert_is_instance(res, dict)
        nt.assert_is_instance(res['drafts'], list)
        nt.assert_equal(len(res['drafts']), 2)

    def test_no_user_permissions_raises_error(self):
        request = RequestFactory().get(self.url)
        request.user = self.user

        with nt.assert_raises(PermissionDenied):
            self.plain_view.as_view()(request)

    def test_correct_view_permissions(self):
        view_permission = Permission.objects.get(codename='view_prereg')
        self.user.user_permissions.add(view_permission)
        self.user.save()

        request = RequestFactory().get(self.url)
        request.user = self.user

        response = self.plain_view.as_view()(request)
        nt.assert_equal(response.status_code, 200)
开发者ID:erinspace,项目名称:osf.io,代码行数:86,代码来源:test_views.py


注:本文中的osf_tests.factories.DraftRegistrationFactory.register方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。