Пример #1
0
    def test_required_third_level_questions_must_be_answered_on_draft(
            self, mock_enqueue, app, user, project_public,
            prereg_metadata, url_registrations):
        prereg_schema = MetaSchema.objects.get(
            name='Prereg Challenge',
            schema_version=LATEST_SCHEMA_VERSION)

        prereg_draft_registration = DraftRegistrationFactory(
            initiator=user,
            registration_schema=prereg_schema,
            branched_from=project_public
        )

        registration_metadata = prereg_metadata(prereg_draft_registration)
        registration_metadata['q11'] = {'value': {"question": {}}}

        prereg_draft_registration.registration_metadata = registration_metadata
        prereg_draft_registration.save()

        payload = {
            'data': {
                'type': 'registrations',
                'attributes': {
                    'registration_choice': 'immediate',
                    'draft_registration': prereg_draft_registration._id,
                }
            }
        }

        res = app.post_json_api(
            url_registrations, payload,
            auth=user.auth,
            expect_errors=True)
        assert res.status_code == 400
        assert res.json['errors'][0]['detail'] == '\'value\' is a required property'
Пример #2
0
    def test_required_third_level_questions_must_be_answered_on_draft(self, mock_enqueue):
        prereg_schema = MetaSchema.find_one(
            Q('name', 'eq', 'Prereg Challenge') &
            Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
        )

        prereg_draft_registration = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=prereg_schema,
            branched_from=self.public_project
        )

        registration_metadata = self.prereg_metadata(prereg_draft_registration)
        registration_metadata['q11'] = {'value': {"question": {}}}

        prereg_draft_registration.registration_metadata = registration_metadata
        prereg_draft_registration.save()

        payload = {
            "data": {
                "type": "registrations",
                "attributes": {
                    "registration_choice": "immediate",
                    "draft_registration": prereg_draft_registration._id,
                    }
                }
        }

        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'], "'value' is a required property")
Пример #3
0
    def test_required_third_level_questions_must_be_answered_on_draft(self, mock_enqueue, app, user, project_public, prereg_metadata, url_registrations):
        prereg_schema = MetaSchema.objects.get(name='Prereg Challenge', schema_version=LATEST_SCHEMA_VERSION)

        prereg_draft_registration = DraftRegistrationFactory(
            initiator=user,
            registration_schema=prereg_schema,
            branched_from=project_public
        )

        registration_metadata = prereg_metadata(prereg_draft_registration)
        registration_metadata['q11'] = {'value': {"question": {}}}

        prereg_draft_registration.registration_metadata = registration_metadata
        prereg_draft_registration.save()

        payload = {
            'data': {
                'type': 'registrations',
                'attributes': {
                    'registration_choice': 'immediate',
                    'draft_registration': prereg_draft_registration._id,
                    }
                }
        }

        res = app.post_json_api(url_registrations, payload, auth=user.auth, expect_errors=True)
        assert res.status_code == 400
        assert res.json['errors'][0]['detail'] == '\'value\' is a required property'
Пример #4
0
    def test_required_third_level_questions_must_be_answered_on_draft(
            self, mock_enqueue):
        prereg_schema = MetaSchema.find_one(
            Q('name', 'eq', 'Prereg Challenge')
            & Q('schema_version', 'eq', LATEST_SCHEMA_VERSION))

        prereg_draft_registration = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=prereg_schema,
            branched_from=self.public_project)

        registration_metadata = self.prereg_metadata(prereg_draft_registration)
        registration_metadata['q11'] = {'value': {"question": {}}}

        prereg_draft_registration.registration_metadata = registration_metadata
        prereg_draft_registration.save()

        payload = {
            "data": {
                "type": "registrations",
                "attributes": {
                    "registration_choice": "immediate",
                    "draft_registration": prereg_draft_registration._id,
                }
            }
        }

        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'],
                     "'value' is a required property")
    def test_required_metaschema_questions_not_required_on_post(self):
        prereg_schema = MetaSchema.find_one(
            Q('name', 'eq', 'Prereg Challenge') &
            Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
        )

        prereg_draft_registration = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=prereg_schema,
            branched_from=self.public_project
        )

        url = '/{}nodes/{}/draft_registrations/?embed=initiator&embed=branched_from'.format(API_BASE, self.public_project._id)

        registration_metadata = self.prereg_metadata(prereg_draft_registration)
        del registration_metadata['q1']
        prereg_draft_registration.registration_metadata = registration_metadata
        prereg_draft_registration.save()

        payload = {
            "data": {
                "type": "draft_registrations",
                "attributes": {
                    "registration_supplement": prereg_schema._id,
                    "registration_metadata": registration_metadata
                }
            }
        }
        res = self.app.post_json_api(url, payload, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, 201)
        data = res.json['data']
        assert_equal(res.json['data']['attributes']['registration_metadata']['q2']['value'], 'Test response')
        assert_equal(data['attributes']['registration_supplement'], prereg_schema._id)
        assert_equal(data['embeds']['branched_from']['data']['id'], self.public_project._id)
        assert_equal(data['embeds']['initiator']['data']['id'], self.user._id)
Пример #6
0
    def test_required_metaschema_questions_not_required_on_post(
            self, app, user, provider, project_public, metadata,
            url_draft_registrations):
        prereg_schema = RegistrationSchema.objects.get(
            name='Prereg Challenge', schema_version=SCHEMA_VERSION)

        prereg_draft_registration = DraftRegistrationFactory(
            initiator=user,
            registration_schema=prereg_schema,
            branched_from=project_public)

        url = '{}&embed=initiator&embed=branched_from'.format(
            url_draft_registrations)

        registration_metadata = metadata(prereg_draft_registration)
        del registration_metadata['q1']
        prereg_draft_registration.registration_metadata = registration_metadata
        prereg_draft_registration.save()

        payload = {
            'data': {
                'type': 'draft_registrations',
                'attributes': {
                    'registration_metadata': registration_metadata
                },
                'relationships': {
                    'branched_from': {
                        'data': {
                            'type': 'nodes',
                            'id': project_public._id,
                        }
                    },
                    'registration_schema': {
                        'data': {
                            'type': 'registration_schema',
                            'id': prereg_schema._id
                        }
                    },
                    'provider': {
                        'data': {
                            'type': 'registration-providers',
                            'id': provider._id,
                        }
                    }
                }
            }
        }
        res = app.post_json_api(url,
                                payload,
                                auth=user.auth,
                                expect_errors=True)
        assert res.status_code == 201
        data = res.json['data']
        assert prereg_schema._id in data['relationships'][
            'registration_schema']['links']['related']['href']
        assert data['embeds']['branched_from']['data'][
            'id'] == project_public._id
        assert data['embeds']['initiator']['data']['id'] == user._id
    def test_required_metaschema_questions_not_required_on_post(
            self, app, user, provider, project_public, prereg_metadata):
        prereg_schema = RegistrationSchema.objects.get(
            name='Prereg Challenge',
            schema_version=LATEST_SCHEMA_VERSION)

        prereg_draft_registration = DraftRegistrationFactory(
            initiator=user,
            registration_schema=prereg_schema,
            branched_from=project_public
        )

        url = '/{}nodes/{}/draft_registrations/?embed=initiator&embed=branched_from'.format(
            API_BASE, project_public._id)

        registration_metadata = prereg_metadata(prereg_draft_registration)
        del registration_metadata['q1']
        prereg_draft_registration.registration_metadata = registration_metadata
        prereg_draft_registration.save()

        payload = {
            'data': {
                'type': 'draft_registrations',
                'attributes': {
                    'registration_metadata': registration_metadata
                },
                'relationships': {
                    'registration_schema': {
                        'data': {
                            'type': 'registration_schema',
                            'id': prereg_schema._id
                        }
                    },
                    'provider': {
                        'data': {
                            'type': 'registration-providers',
                            'id': provider._id,
                        }
                    }
                }
            }
        }
        res = app.post_json_api(
            url, payload, auth=user.auth,
            expect_errors=True)
        assert res.status_code == 201
        data = res.json['data']
        assert res.json['data']['attributes']['registration_metadata']['q2']['value'] == 'Test response'
        assert prereg_schema._id in data['relationships']['registration_schema']['links']['related']['href']
        assert data['embeds']['branched_from']['data']['id'] == project_public._id
        assert data['embeds']['initiator']['data']['id'] == user._id
    def test_required_metaschema_questions_not_required_on_post(self):
        prereg_schema = MetaSchema.find_one(
            Q('name', 'eq', 'Prereg Challenge')
            & Q('schema_version', 'eq', LATEST_SCHEMA_VERSION))

        prereg_draft_registration = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=prereg_schema,
            branched_from=self.public_project)

        url = '/{}nodes/{}/draft_registrations/?embed=initiator&embed=branched_from'.format(
            API_BASE, self.public_project._id)

        registration_metadata = self.prereg_metadata(prereg_draft_registration)
        del registration_metadata['q1']
        prereg_draft_registration.registration_metadata = registration_metadata
        prereg_draft_registration.save()

        payload = {
            "data": {
                "type": "draft_registrations",
                "attributes": {
                    "registration_supplement": prereg_schema._id,
                    "registration_metadata": registration_metadata
                }
            }
        }
        res = self.app.post_json_api(url,
                                     payload,
                                     auth=self.user.auth,
                                     expect_errors=True)
        assert_equal(res.status_code, 201)
        data = res.json['data']
        assert_equal(
            res.json['data']['attributes']['registration_metadata']['q2']
            ['value'], 'Test response')
        assert_equal(data['attributes']['registration_supplement'],
                     prereg_schema._id)
        assert_equal(data['embeds']['branched_from']['data']['id'],
                     self.public_project._id)
        assert_equal(data['embeds']['initiator']['data']['id'], self.user._id)
    def test_required_metaschema_questions_not_required_on_post(
            self, app, user, project_public, prereg_metadata):
        prereg_schema = MetaSchema.objects.get(
            name='Prereg Challenge', schema_version=LATEST_SCHEMA_VERSION)

        prereg_draft_registration = DraftRegistrationFactory(
            initiator=user,
            registration_schema=prereg_schema,
            branched_from=project_public)

        url = '/{}nodes/{}/draft_registrations/?embed=initiator&embed=branched_from'.format(
            API_BASE, project_public._id)

        registration_metadata = prereg_metadata(prereg_draft_registration)
        del registration_metadata['q1']
        prereg_draft_registration.registration_metadata = registration_metadata
        prereg_draft_registration.save()

        payload = {
            'data': {
                'type': 'draft_registrations',
                'attributes': {
                    'registration_supplement': prereg_schema._id,
                    'registration_metadata': registration_metadata
                }
            }
        }
        res = app.post_json_api(url,
                                payload,
                                auth=user.auth,
                                expect_errors=True)
        assert res.status_code == 201
        data = res.json['data']
        assert res.json['data']['attributes']['registration_metadata']['q2'][
            'value'] == 'Test response'
        assert data['attributes'][
            'registration_supplement'] == prereg_schema._id
        assert data['embeds']['branched_from']['data'][
            'id'] == project_public._id
        assert data['embeds']['initiator']['data']['id'] == user._id