Esempio n. 1
0
    def test_get_unread(self):

        api = uuid.uuid4().hex
        user_name = 'admin'

        with Replacer() as r:
            r.replace('opencore.views.mbox.authenticated_userid', _authenticated_user_id)

            site, from_, _, msg, thread_id, msg_id, _, _, _, _ = get_data()
            to = find_profiles(site)[user_name]

            self.mbt.send_message(site, from_, to, msg, should_commit=True)

            request = DummyRequest()
            request.api = api
            request.params['thread_id'] = thread_id
            request.params['message_id'] = msg_id

            mark_message_read(site, request)
            transaction.commit()

            self.mbt.send_message(site, from_, to, msg, should_commit=True)
            transaction.commit()

            unread = self.mbt.get_unread(site, user_name)
            self.assertTrue(unread >= 0)
Esempio n. 2
0
    def test_delete_message(self):

        api = uuid.uuid4().hex

        with Replacer() as r:
            r.replace('opencore.views.mbox.authenticated_userid', _authenticated_user_id)

            site, from_, _, msg, thread_id, msg_id, _, _, _, _ = get_data()
            to = find_profiles(site)['admin']
            self.mbt.send_message(site, from_, to, msg, should_commit=True)

            request = DummyRequest()
            request.api = api
            request.params['thread_id'] = thread_id
            request.params['message_id'] = msg_id

            delete_message(site, request)
            transaction.commit()

            try:
                raw_msg, msg = self.mbt.get_message(site, from_, 'inbox', thread_id, msg_id)
            except NoSuchThreadException:
                pass
            else:
                raise Exception('Expected a NoSuchThreadException here')
Esempio n. 3
0
    def test_format_date(self):
        orig = '2011-05-31 13:59:50'
        expected = '31 May at 13:59'

        site, from_, _, msg, thread_id, msg_id, _, _, _, _ = get_data()

        given = _format_date(site, orig)
        self.assertEquals(expected, given)
Esempio n. 4
0
    def test_mark_message_read(self):

        api = uuid.uuid4().hex

        with Replacer() as r:
            r.replace('opencore.views.mbox.authenticated_userid', _authenticated_user_id)

            site, from_, _, msg, thread_id, msg_id, _, _, _, _ = get_data()
            to = find_profiles(site)['admin']
            self.mbt.send_message(site, from_, to, msg, should_commit=True)

            request = DummyRequest()
            request.api = api
            request.params['thread_id'] = thread_id
            request.params['message_id'] = msg_id

            mark_message_read(site, request)
            transaction.commit()

            raw_msg, msg = self.mbt.get_message(site, from_, 'inbox', thread_id, msg_id)
            self.assertEquals(raw_msg.flags, ['READ'])
Esempio n. 5
0
    def test_show_mbox(self):

        _people_url = uuid.uuid4().hex
        _firstname = uuid.uuid4().hex
        _lastname = uuid.uuid4().hex
        _country = uuid.uuid4().hex

        class _DummyAPI(object):

            static_url = '/foo/bar'

            def find_profile(*ignored_args, **ignored_kwargs):
                class _Dummy(object):
                    firstname = _firstname
                    lastname = _lastname
                    country = _country
                    organization = uuid.uuid4().hex
                    thumb_url = lambda _profile, _request: '/test-thumb.jpg'

                return _Dummy()

            people_url = _people_url

        with Replacer() as r:
            r.replace('opencore.views.mbox.authenticated_userid', _authenticated_user_id)
            r.replace('opencore.views.mbox._get_profile_details',
                    lambda context, request, user: {})


            site, from_, _, msg, thread_id, _, _, _, payload, _ = get_data()
            to = find_profiles(site)['admin']
            self.mbt.send_message(site, from_, to, msg, should_commit=True)

            site, _ = open_root(get_default_config())
            request = DummyRequest()
            request.params['thread_id'] = thread_id
            request.api = _DummyAPI()

            response = show_mbox_thread(site, request)

            self.assertTrue(isinstance(response['api'], _DummyAPI))

            self.assertTrue(len(response['messages']), 1)
            message = response['messages'][0]

            flags = message['flags']
            if flags:
                self.assertEquals(flags, ['READ'])

            self.assertEquals(message['from'], 'admin')
            self.assertEquals(message['from_country'], _country)
            self.assertEquals(message['from_firstname'], _firstname)
            self.assertEquals(message['from_lastname'], _lastname)
            self.assertEquals(message['from_photo'], '/test-thumb.jpg')
            self.assertEquals(message['payload'], payload)
            self.assertTrue(len(message['payload']) > 20)
            self.assertTrue(len(message['queue_id']) > 20)

            self.assertTrue(len(message['to_data']) == 2)
            to_data = message['to_data']

            for to_datum in to_data:
                self.assertEquals(to_datum['country'], _country)
                self.assertEquals(to_datum['firstname'], _firstname)
                self.assertEquals(to_datum['lastname'], _lastname)

                name = to_datum['name']
                self.assertTrue(name in ('joe', 'sarah'))
                self.assertEquals(to_datum['photo_url'], '/test-thumb.jpg')