Beispiel #1
0
def __get_reviews_from_history_queue(main_page, db_user, translator, is_executed=False):
    """

    :param main_page: Host URL
    :param db_user: User
    :param translator: Translator
    :param is_executed: Boolean
    :return: dict()
    """
    past_decision = []
    for key in review_queues:
        review_table = get_review_model_by_key(key)
        executed_list = __get_executed_reviews_of(key, main_page, review_table, translator, is_executed)
        past_decision.append({
            'title': start_with_capital(key) + ' Queue',
            'icon': reputation_icons[key],
            'queue': key,
            'content': executed_list,
            'has_reason': key in [key_delete],
            'has_oem_text': key in [key_edit, key_merge, key_split],
            'has_duplicate_text': key in [key_duplicate]
        })

    return {
        'has_access': is_executed and __has_access_to_history(db_user),
        'is_history': is_executed,
        'past_decision': past_decision
    }
Beispiel #2
0
    def __get_review_count_for_history(is_executed):
        """

        :param is_executed:
        :return:
        """
        count = 0
        tables = [get_review_model_by_key(key) for key in review_queues]
        for table in tables:
            count += DBDiscussionSession.query(table).filter_by(is_executed=is_executed).count()
        return count
Beispiel #3
0
 def test_get_text_of_element(self):
     for key in review_queues:
         queue = get_queue_by_key(key)
         adapter = QueueAdapter(queue=queue(),
                                db_user=self.user,
                                application_url='main',
                                translator=self.tn)
         review_table = get_review_model_by_key(key)
         db_review = DBDiscussionSession.query(review_table).filter_by(
             is_executed=False, is_revoked=False).first()
         text = adapter.get_text_of_element(db_review)
         self.assertTrue(isinstance(text, str))
Beispiel #4
0
 def test_get_review_count(self):
     for key in review_queues:
         queue = get_queue_by_key(key)
         adapter = QueueAdapter(queue=queue(),
                                db_user=self.user,
                                application_url='main',
                                translator=self.tn)
         review_table = get_review_model_by_key(key)
         db_review = DBDiscussionSession.query(review_table).filter_by(
             is_executed=False, is_revoked=False).first()
         okay, not_okay = adapter.get_review_count(db_review.uid)
         self.assertTrue(isinstance(okay, int))
         self.assertTrue(isinstance(not_okay, int))
Beispiel #5
0
 def test_get_all_votes_for(self):
     for key in review_queues:
         queue = get_queue_by_key(key)
         adapter = QueueAdapter(queue=queue(),
                                db_user=self.user,
                                application_url='main',
                                translator=self.tn)
         review_table = get_review_model_by_key(key)
         db_review = DBDiscussionSession.query(review_table).filter_by(
             is_executed=False, is_revoked=False).first()
         pro, con = adapter.get_all_votes_for(db_review)
         self.assertTrue(isinstance(pro, list))
         self.assertTrue(isinstance(con, list))
Beispiel #6
0
def valid_uid_as_row_in_review_queue(request):
    uid = request.json_body.get('uid')
    queue = request.json_body.get('queue', '')
    model = get_review_model_by_key(queue)

    db_review = DBDiscussionSession.query(model).get(uid) if is_integer(uid) and model else None
    if db_review:
        request.validated['queue'] = queue
        request.validated['uid'] = uid
        request.validated['review'] = db_review
        return True
    else:
        add_error(request, 'Invalid id for any review queue found: {}'.format(queue))
    return False
Beispiel #7
0
    def test_get_history_table_row(self):
        for key in review_queues:
            queue = get_queue_by_key(key)
            adapter = QueueAdapter(queue=queue(),
                                   db_user=self.user,
                                   application_url='main',
                                   translator=self.tn)
            review_table = get_review_model_by_key(key)
            db_review = DBDiscussionSession.query(review_table).filter_by(
                is_executed=False, is_revoked=False).first()
            row = adapter.get_history_table_row(db_review, {},
                                                is_executed=False,
                                                short_text='short',
                                                full_text='.' * 40)
            if not row:
                continue

            if key == key_delete:
                self.assertIn('reason', row.keys())
                continue

            self.assertTrue(any(['_shorttext' in key for key in row.keys()]))
            self.assertTrue(any(['_fulltext' in key for key in row.keys()]))
Beispiel #8
0
    def __get_queue_information(self, queue_name: str):
        """
        Returns some information of the current queue

        :param queue_name: name of the queue
        :return:
        """
        last_reviewer = get_last_reviewer_by_key(queue_name)
        table = get_review_model_by_key(queue_name)
        task_count = get_review_count_for(table, last_reviewer, self.db_user)
        count, all_rights = get_reputation_of(self.db_user)
        visit_key_str = _.get_key_by_string('visit{}Queue'.format(
            start_with_capital(queue_name)))
        visit_limit_key_str = _.get_key_by_string(
            'visit{}QueueLimitation'.format(start_with_capital(queue_name)))
        return {
            'task_name':
            self.translator.get(get_title_by_key(queue_name)),
            'id':
            queue_name,
            'url':
            f'{self.application_url}/review/{queue_name}',
            'icon':
            reputation_icons[queue_name],
            'task_count':
            task_count,
            'is_allowed':
            count >= reputation_borders[queue_name] or all_rights,
            'is_allowed_text':
            self.translator.get(visit_key_str),
            'is_not_allowed_text':
            self.translator.get(visit_limit_key_str).format(
                str(reputation_borders[queue_name])),
            'last_reviews':
            self.__get_last_reviewer_of(last_reviewer, self.application_url)
        }
Beispiel #9
0
    def __test_cancel_ballot(self, key):
        queue = get_queue_by_key(key)
        adapter = QueueAdapter(queue=queue(),
                               db_user=self.user,
                               application_url='main',
                               translator=self.tn)
        review_table = get_review_model_by_key(key)
        last_reviewer_table = get_last_reviewer_by_key(key)

        # count of elements before we add new things to cancel
        review_count_1 = DBDiscussionSession.query(review_table).count()

        # add things which we can cancel
        if key in [key_merge, key_split]:
            db_new_review = review_table(detector=4, premisegroup=5)
        elif key is key_duplicate:
            db_new_review = review_table(detector=4,
                                         duplicate_statement=5,
                                         original_statement=4)
        else:
            db_new_review = review_table(detector=4)

        DBDiscussionSession.add(db_new_review)
        DBDiscussionSession.flush()

        if key == key_split:
            DBDiscussionSession.add(
                last_reviewer_table(reviewer=3,
                                    review=db_new_review.uid,
                                    should_split=True))
        elif key == key_merge:
            DBDiscussionSession.add(
                last_reviewer_table(reviewer=3,
                                    review=db_new_review.uid,
                                    should_merge=True))
        else:
            DBDiscussionSession.add(
                last_reviewer_table(reviewer=3,
                                    review=db_new_review.uid,
                                    is_okay=True))

        DBDiscussionSession.flush()

        # count of elements after we add new things to cancel
        review_count_2 = DBDiscussionSession.query(review_table).count()
        review_canceled_1 = DBDiscussionSession.query(ReviewCanceled).count()

        # cancel things
        adapter.cancel_ballot(db_new_review)

        # count of elements after we canceled
        review_count_3 = DBDiscussionSession.query(review_table).count()
        review_canceled_2 = DBDiscussionSession.query(ReviewCanceled).count()

        self.assertLess(review_count_1, review_count_2)
        self.assertEqual(review_count_3, review_count_2)
        self.assertTrue(db_new_review.is_revoked)

        self.assertLess(review_canceled_1, review_canceled_2)
        self.__delete_review_in_test_cancel_ballot(key, db_new_review,
                                                   last_reviewer_table,
                                                   review_table)