Example #1
0
    def test_thread_count_by_survey_my_conversations_on(self):
        """checks that the returned thread count is the same for every internal user
        even if they are not part of the conversations"""
        request_args = MessageArgs(page=0,
                                   limit=100,
                                   business_id=None,
                                   cc=None,
                                   label=None,
                                   desc=None,
                                   ce=None,
                                   surveys=[self.BRES_SURVEY],
                                   is_closed=False,
                                   my_conversations=True,
                                   new_respondent_conversations=False,
                                   all_conversation_types=False,
                                   unread_conversations=False)

        for _ in range(5):
            self.create_thread(no_of_messages=2)

        with self.app.app_context():
            with current_app.test_request_context():
                thread_count_internal = Retriever.thread_count_by_survey(
                    request_args,
                    User(self.default_internal_actor, role='internal'))
                thread_count_second_internal = Retriever.thread_count_by_survey(
                    request_args,
                    User(self.second_internal_actor, role='internal'))
                self.assertEqual(thread_count_internal, 5)
                self.assertEqual(thread_count_second_internal, 0)
Example #2
0
    def get():
        """Get count of all conversations for a specific internal user
        Typically for a specific survey, supports filtering by case, collection exercise, business party id etc

        :returns: if all_conversation_types is set 'true' returns json representing all 4 counts
                  else returns the count for the single type combination requested.
        """
        logger.info("Getting count of threads for user",
                    user_uuid=g.user.user_uuid)
        message_args = get_options(request.args)

        if message_args.all_conversation_types:
            logger.info("Getting counts for all conversation states for user",
                        user_uuid=g.user.user_uuid)
            return jsonify(totals=Retriever.
                           thread_count_by_survey_and_conversation_states(
                               message_args, g.user))

        if message_args.unread_conversations:
            logger.info("Getting counts of unread conversations",
                        user_uuid=g.user.user_uuid)
            return jsonify(total=Retriever.unread_message_count(g.user))

        return jsonify(
            total=Retriever.thread_count_by_survey(message_args, g.user))