コード例 #1
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
            {'username': '******', 'project': mediawiki_project},
            {'username': '******', 'project': mediawiki_project},
            # one invalid username
            {'username': '******', 'project': mediawiki_project},
            # one user with invalid project
            {'username': '******', '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(WikiUser).filter(
            WikiUser.mediawiki_username == 'Editor test-specific-0').one().valid, True)
        assert_equal(self.session.query(WikiUser).filter(
            WikiUser.mediawiki_username == 'Editor test-specific-1').one().valid, True)
        assert_equal(self.session.query(WikiUser).filter(
            WikiUser.mediawiki_username == 'Nonexisting').one().valid, False)
        assert_equal(self.session.query(WikiUser).filter(
            WikiUser.mediawiki_username == 'Nonexisting2').one().valid, False)
コード例 #2
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)
コード例 #3
0
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')
            elif get_cohort_by_name(form.name.data):
                flash('That Cohort name is already taken.', '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')