def test_small_cohort(self):
        cohort_upload = CohortUpload()
        cohort_upload.name.data = 'small_cohort'
        cohort_upload.project.data = mediawiki_project
        cohort_upload.records = [
            # two existing users
            {'raw_id_or_name': 'Editor test-specific-0', 'project': mediawiki_project},
            {'raw_id_or_name': 'Editor test-specific-1', 'project': mediawiki_project},
            # one invalid username
            {'raw_id_or_name': 'Nonexisting', 'project': mediawiki_project},
            # one user with invalid project
            {'raw_id_or_name': 'Nonexisting2', 'project': 'Nonexisting'},
        ]

        v = ValidateCohort.from_upload(cohort_upload, self.owner_user_id)
        v.task.delay(v).get()
        self.session.commit()

        assert_equal(self.session.query(WikiUserStore).filter(
            WikiUserStore.raw_id_or_name == 'Editor test-specific-0').one().valid,
            True
        )
        assert_equal(self.session.query(WikiUserStore).filter(
            WikiUserStore.raw_id_or_name == 'Editor test-specific-1').one().valid,
            True
        )
        assert_equal(self.session.query(WikiUserStore).filter(
            WikiUserStore.raw_id_or_name == 'Nonexisting').one().valid, False)
        assert_equal(self.session.query(WikiUserStore).filter(
            WikiUserStore.raw_id_or_name == 'Nonexisting2').one().valid, False)
    def test_from_upload_exception(self):
        cohort_upload = CohortUpload()
        cohort_upload.name.data = 'small_cohort'
        cohort_upload.project.data = 'wiki'
        cohort_upload.records = [{'fake': 'dict'}]

        v = ValidateCohort.from_upload(cohort_upload, self.owner_user_id)
        assert_equal(v, None)
Exemplo n.º 3
0
    def test_from_upload_exception(self):
        cohort_upload = CohortUpload()
        cohort_upload.name.data = 'small_cohort'
        cohort_upload.project.data = 'wiki'
        cohort_upload.records = [{'fake': 'dict'}]

        v = ValidateCohort.from_upload(cohort_upload, self.owner_user_id)
        assert_equal(v, None)
Exemplo n.º 4
0
    def test_small_cohort(self):
        cohort_upload = CohortUpload()
        cohort_upload.name.data = 'small_cohort'
        cohort_upload.project.data = mediawiki_project
        cohort_upload.records = [
            # two existing users
            {
                'raw_id_or_name': 'Editor test-specific-0',
                'project': mediawiki_project
            },
            {
                'raw_id_or_name': 'Editor test-specific-1',
                'project': mediawiki_project
            },
            # one invalid username
            {
                'raw_id_or_name': 'Nonexisting',
                'project': mediawiki_project
            },
            # one user with invalid project
            {
                'raw_id_or_name': 'Nonexisting2',
                'project': 'Nonexisting'
            },
        ]

        v = ValidateCohort.from_upload(cohort_upload, self.owner_user_id)
        v.task.delay(v).get()
        self.session.commit()

        assert_equal(
            self.session.query(WikiUserStore).filter(
                WikiUserStore.raw_id_or_name ==
                'Editor test-specific-0').one().valid, True)
        assert_equal(
            self.session.query(WikiUserStore).filter(
                WikiUserStore.raw_id_or_name ==
                'Editor test-specific-1').one().valid, True)
        assert_equal(
            self.session.query(WikiUserStore).filter(
                WikiUserStore.raw_id_or_name == 'Nonexisting').one().valid,
            False)
        assert_equal(
            self.session.query(WikiUserStore).filter(
                WikiUserStore.raw_id_or_name == 'Nonexisting2').one().valid,
            False)
def cohort_upload():
    """ View for uploading and validating a new cohort via CSV """
    form = CohortUpload()

    if request.method == 'POST':
        form = CohortUpload.from_request(request)
        try:
            if not form.validate():
                flash('Please fix validation problems.', 'warning')

            else:
                form.parse_records()
                vc = ValidateCohort.from_upload(form, current_user.id)
                vc.task.delay(vc)
                return redirect('{0}#{1}'.format(
                    url_for('cohorts_index'),
                    vc.cohort_id
                ))
        except Exception, e:
            app.logger.exception(str(e))
            flash('Server error while processing your upload', 'error')