Beispiel #1
0
    def test_latest_message_from_each_thread_chosen_desc(self):
        """checks the message chosen for each thread is the latest message within that thread"""
        for _ in range(5):
            self.create_thread(no_of_messages=3)

        with self.app.app_context():
            with current_app.test_request_context():
                args = get_args(limit=MESSAGE_QUERY_LIMIT)
                response = Retriever.retrieve_thread_list(
                    self.user_internal, args)

                date = []
                thread_ids = []
                msg_ids = []
                for message in response.items:
                    serialized_msg = message.serialize(self.user_internal)
                    if 'sent_date' in serialized_msg:
                        date.append(serialized_msg['sent_date'])
                    elif 'modified_date' in serialized_msg:
                        date.append(serialized_msg['modified_date'])
                    thread_ids.append(serialized_msg['thread_id'])
                    msg_ids.append(serialized_msg['msg_id'])

                self.assertEqual(len(msg_ids), 5)

                args = get_args(page=1, limit=MESSAGE_QUERY_LIMIT)

                for x in range(0, len(thread_ids)):
                    thread = Retriever.retrieve_thread(thread_ids[x],
                                                       self.user_internal)
                    self.assertEqual(date[x],
                                     str(thread.all()[0].events[0].date_time))
                    self.assertEqual(msg_ids[x],
                                     thread.all()[0].events[0].msg_id)
Beispiel #2
0
    def test_respondent_can_only_see_their_messages(self):
        """tests that a respondent can only see their messages i.e. they should not
        see any messages sent to another respondent"""
        first_respondent_thread_id = self.create_thread(
            no_of_messages=1,
            external_actor=self.default_external_actor,
            internal_actor=self.default_internal_actor)
        second_respondent_thread_id = self.create_thread(
            no_of_messages=1,
            external_actor=self.second_external_actor,
            internal_actor=self.default_internal_actor)

        with self.app.app_context():
            with current_app.test_request_context():
                args = get_args()
                first_respondent_thread_list = Retriever.retrieve_thread_list(
                    self.user_respondent, args)
                self.assertEqual(first_respondent_thread_list.total, 1)
                second_respondent_thread_list = Retriever.retrieve_thread_list(
                    self.second_user_respondent, args)
                self.assertEqual(second_respondent_thread_list.total, 1)
                internal_thread_list = Retriever.retrieve_thread_list(
                    self.user_internal, args)
                self.assertEqual(internal_thread_list.total, 2)

                # first respondent can retrieve the message they sent
                first_respondent_thread = Retriever.retrieve_thread(
                    first_respondent_thread_id, self.user_respondent)
                self.assertIsNotNone(first_respondent_thread)

                # second respondent can retrieve the message they sent
                second_respondent_thread = Retriever.retrieve_thread(
                    second_respondent_thread_id, self.second_user_respondent)
                self.assertIsNotNone(second_respondent_thread)

                # first respondent shouldn't be able to retrieve second respondent's message
                with self.assertRaises(Forbidden):
                    Retriever.retrieve_thread(first_respondent_thread_id,
                                              self.second_user_respondent)

                # second respondent shouldn't be able to retrieve first respondent's message
                with self.assertRaises(Forbidden):
                    Retriever.retrieve_thread(second_respondent_thread_id,
                                              self.user_respondent)
Beispiel #3
0
    def get():
        """Get thread list"""
        logger.info("Getting list of threads for user",
                    user_uuid=g.user.user_uuid)
        message_args = get_options(request.args)

        ThreadList._validate_request(message_args, g.user)

        result = Retriever.retrieve_thread_list(g.user, message_args)

        logger.info("Successfully retrieved threads for user",
                    user_uuid=g.user.user_uuid)
        messages, links = process_paginated_list(result, request.host_url,
                                                 g.user, message_args,
                                                 THREAD_LIST_ENDPOINT)
        if messages:
            messages = add_users_and_business_details(messages)
        return jsonify({"messages": messages, "_links": links})
Beispiel #4
0
    def test_thread_list_returned_in_descending_order_respondent(self):
        """retrieves threads from database in desc sent_date order for respondent"""
        for _ in range(5):
            self.create_thread(no_of_messages=2)

        with self.app.app_context():
            with current_app.test_request_context():
                args = get_args(limit=MESSAGE_QUERY_LIMIT)
                response = Retriever.retrieve_thread_list(
                    self.user_respondent, args)

                date = []
                for message in response.items:
                    serialized_msg = message.serialize(self.user_respondent)
                    if 'sent_date' in serialized_msg:
                        date.append(serialized_msg['sent_date'])
                    elif 'modified_date' in serialized_msg:
                        date.append(serialized_msg['modified_date'])

                desc_date = sorted(date, reverse=True)
                self.assertEqual(len(date), 5)
                self.assertListEqual(desc_date, date)