コード例 #1
0
 def test_validate_cohorts_when_invalid_project_causes_exception(self, mock):
     '''
     Mocks normalize_project to force an exception when accessing
     an unexisting project database. This exception should not be
     forwarded.
     '''
     self.helper_reset_validation()
     self.cohort.validate_as_user_ids = False
     wikiusers = self.session.query(WikiUserStore).all()
     wikiusers[0].project = 'blah'
     v = ValidateCohort(self.cohort)
     try:
         v.validate_records(self.session, self.cohort)
     except Exception:
         assert_true(False, 'validate_records should not raise an exception')
     else:
         assert_equal(self.cohort.validated, True)
         assert_equal(len(
             self.session.query(WikiUserStore)
                 .filter(WikiUserStore.validating_cohort == self.cohort.id)
                 .filter(WikiUserStore.valid)
                 .all()
         ), 3)
         records = (self.session.query(WikiUserStore)
                    .filter(WikiUserStore.validating_cohort == self.cohort.id)
                    .filter(WikiUserStore.valid.in_([False]))
                    .all())
         assert_equal(len(records), 1)
         assert_equal(records[0].reason_invalid, 'invalid project')
コード例 #2
0
 def test_validate_cohorts_when_invalid_project_causes_exception(
         self, mock):
     '''
     Mocks normalize_project to force an exception when accessing
     an unexisting project database. This exception should not be
     forwarded.
     '''
     self.helper_reset_validation()
     self.cohort.validate_as_user_ids = False
     wikiusers = self.session.query(WikiUserStore).all()
     wikiusers[0].project = 'blah'
     v = ValidateCohort(self.cohort)
     try:
         v.validate_records(self.session, self.cohort)
     except:
         assert_true(False,
                     'validate_records should not raise an exception')
     else:
         assert_equal(self.cohort.validated, True)
         assert_equal(
             len(
                 self.session.query(WikiUserStore).filter(
                     WikiUserStore.validating_cohort ==
                     self.cohort.id).filter(WikiUserStore.valid).all()), 3)
         records = (self.session.query(WikiUserStore).filter(
             WikiUserStore.validating_cohort == self.cohort.id).filter(
                 WikiUserStore.valid.in_([False])).all())
         assert_equal(len(records), 1)
         assert_equal(records[0].reason_invalid, 'invalid project')
コード例 #3
0
    def test_validate_cohorts_with_project_variations(self, mock):
        self.helper_reset_validation()
        self.cohort.validate_as_user_ids = False

        wikiusers = self.session.query(WikiUserStore).all()
        username = '******'
        wikiusers[0].raw_id_or_name = username
        wikiusers[1].raw_id_or_name = username
        # set different project versions of the same project
        # they will be normalized to 'wiki' by the normalize_project mock
        wikiusers[0].project = 'en'
        wikiusers[1].project = 'enwiki'
        # add also the correspondent mediawiki user
        self.mwSession.add(MediawikiUser(user_name=username))
        self.mwSession.commit()

        v = ValidateCohort(self.cohort)
        v.validate_records(self.session, self.cohort)

        assert_equal(self.cohort.validated, True)
        assert_equal(len(
            self.session.query(WikiUserStore)
                .filter(WikiUserStore.validating_cohort == self.cohort.id)
                .filter(WikiUserStore.valid)
                .all()
        ), 3)
        assert_equal(len(
            self.session.query(WikiUserStore)
                .filter(WikiUserStore.validating_cohort == self.cohort.id)
                .filter(WikiUserStore.valid.in_([False]))
                .all()
        ), 0)
コード例 #4
0
    def test_validate_cohorts_with_project_variations(self, mock):
        self.helper_reset_validation()
        self.cohort.validate_as_user_ids = False

        wikiusers = self.session.query(WikiUserStore).all()
        username = '******'
        wikiusers[0].raw_id_or_name = username
        wikiusers[1].raw_id_or_name = username
        # set different project versions of the same project
        # they will be normalized to 'wiki' by the normalize_project mock
        wikiusers[0].project = 'en'
        wikiusers[1].project = 'enwiki'
        # add also the correspondent mediawiki user
        self.mwSession.add(MediawikiUser(user_name=username))
        self.mwSession.commit()

        v = ValidateCohort(self.cohort)
        v.validate_records(self.session, self.cohort)

        assert_equal(self.cohort.validated, True)
        assert_equal(
            len(
                self.session.query(WikiUserStore).filter(
                    WikiUserStore.validating_cohort == self.cohort.id).filter(
                        WikiUserStore.valid).all()), 3)
        assert_equal(
            len(
                self.session.query(WikiUserStore).filter(
                    WikiUserStore.validating_cohort == self.cohort.id).filter(
                        WikiUserStore.valid.in_([False])).all()), 0)
コード例 #5
0
    def test_validate_cohorts(self):
        self.helper_reset_validation()
        self.cohort.validate_as_user_ids = False
        self.session.commit()
        v = ValidateCohort(self.cohort)
        v.validate_records(self.session, self.cohort)

        assert_equal(self.cohort.validated, True)
        assert_equal(
            len(
                self.session.query(WikiUserStore).filter(
                    WikiUserStore.validating_cohort == self.cohort.id).filter(
                        WikiUserStore.valid).all()), 4)
コード例 #6
0
    def test_validate_cohorts(self):
        self.helper_reset_validation()
        self.cohort.validate_as_user_ids = False
        self.session.commit()
        v = ValidateCohort(self.cohort)
        v.validate_records(self.session, self.cohort)

        assert_equal(self.cohort.validated, True)
        assert_equal(len(
            self.session.query(WikiUserStore)
                .filter(WikiUserStore.validating_cohort == self.cohort.id)
                .filter(WikiUserStore.valid)
                .all()
        ), 4)
コード例 #7
0
    def test_detail_by_name_after_validate(self):
        self.helper_reset_validation()

        # Set a fake validation_queue_key as we are running on sync mode
        self.cohort.validation_queue_key = 33
        self.session.commit()
        #executed validation synchronously
        vc = ValidateCohort(self.cohort)
        vc.validate_records(self.session, self.cohort)
        with cohort_service_set(app, self.cohort_service):
            response = self.app.get('/cohorts/detail/{0}'.format(self.cohort.name))
            parsed = json.loads(response.data)

        # note than it does not make sense to assert validation status
        # as that is retrieved directly from celery and celery was not used in this test
        assert_equal(parsed['validated_count'], 4)
        assert_equal(parsed['total_count'], 4)
コード例 #8
0
    def test_detail_by_name_after_validate(self):
        self.helper_reset_validation()

        # Set a fake validation_queue_key as we are running in sync mode
        self.cohort.validation_queue_key = '33'
        self.session.add(self.cohort)
        self.session.commit()

        # executed validation synchronously
        vc = ValidateCohort(self.cohort)
        vc.validate_records(self.session, self.cohort)
        with cohort_service_set(app, self.cohort_service):
            response = self.app.get('/cohorts/detail/{0}'.format(
                self.cohort.name))
            parsed = json.loads(response.data)

        # note than it does not make sense to assert validation status
        # as that is retrieved directly from celery and celery was not used in this test
        assert_equal(parsed['validation']['validated_count'], 4)
        assert_equal(parsed['validation']['total_count'], 4)
コード例 #9
0
    def test_validate_cohorts_with_invalid_wikiusers(self):
        self.helper_reset_validation()
        self.cohort.validate_as_user_ids = False
        wikiusers = self.session.query(WikiUserStore).all()
        wikiusers[0].project = 'blah'
        wikiusers[1].raw_id_or_name = 'blah'
        self.session.commit()
        v = ValidateCohort(self.cohort)
        v.validate_records(self.session, self.cohort)

        assert_equal(self.cohort.validated, True)
        assert_equal(
            len(
                self.session.query(WikiUserStore).filter(
                    WikiUserStore.validating_cohort == self.cohort.id).filter(
                        WikiUserStore.valid).all()), 2)
        assert_equal(
            len(
                self.session.query(WikiUserStore).filter(
                    WikiUserStore.validating_cohort == self.cohort.id).filter(
                        WikiUserStore.valid.in_([False])).all()), 2)
コード例 #10
0
    def test_validate_cohorts_with_invalid_wikiusers(self):
        self.helper_reset_validation()
        self.cohort.validate_as_user_ids = False
        wikiusers = self.session.query(WikiUserStore).all()
        wikiusers[0].project = 'blah'
        wikiusers[1].raw_id_or_name = 'blah'
        self.session.commit()
        v = ValidateCohort(self.cohort)
        v.validate_records(self.session, self.cohort)

        assert_equal(self.cohort.validated, True)
        assert_equal(len(
            self.session.query(WikiUserStore)
                .filter(WikiUserStore.validating_cohort == self.cohort.id)
                .filter(WikiUserStore.valid)
                .all()
        ), 2)
        assert_equal(len(
            self.session.query(WikiUserStore)
                .filter(WikiUserStore.validating_cohort == self.cohort.id)
                .filter(WikiUserStore.valid.in_([False]))
                .all()
        ), 2)