コード例 #1
0
 def setUp(self, mock_endpoint):
     self.recipient = Recipient(mock_endpoint(),
                                'm',
                                'i',
                                i='idkey',
                                m='mkey')
     self.mock_index = self.recipient._endpoint.index
コード例 #2
0
 def setUp(self, mock_endpoint):
     self.recipient = Recipient(mock_endpoint(),
                                'm',
                                'i',
                                i='idkey',
                                m='mkey')
     self.recipient.post('test message')
     self.mock_create = self.recipient._endpoint.create
コード例 #3
0
 def setUp(self, mock_endpoint):
     # TODO: Fix this literal dependency!
     self.chunks = ('x' * 1000, 'x' * 100)
     self.recipient = Recipient(mock_endpoint(),
                                'm',
                                'i',
                                i='idkey',
                                m='mkey')
     self.recipient.post(''.join(self.chunks))
     self.mock_create = self.recipient._endpoint.create
コード例 #4
0
class RecipientMessagesTests(unittest.TestCase):
    @mock.patch('groupy.api.endpoint.Endpoint')
    def setUp(self, mock_endpoint):
        self.recipient = Recipient(mock_endpoint(),
                                   'm',
                                   'i',
                                   i='idkey',
                                   m='mkey')
        self.mock_index = self.recipient._endpoint.index

    def test_messages_calls_MessagePager_once(self, MockMP, MockM):
        messages = self.recipient.messages()
        self.assertEqual(MockMP.call_count, 1)

    def test_messages_calls_endpoint_index_once(self, MockMP, MockM):
        messages = self.recipient.messages()
        self.mock_index.assert_called_once_with('idkey',
                                                after_id=None,
                                                since_id=None,
                                                before_id=None)

    def test_messages_returns_MessagePager(self, MockMP, MockM):
        messages = self.recipient.messages()
        self.assertEqual(messages.__class__,
                         groupy.object.listers.MessagePager)

    def test_messages_after_index_arguments_use_after_id(self, MockMP, MockM):
        messages = self.recipient.messages(after=123)
        self.mock_index.assert_called_once_with('idkey',
                                                after_id=123,
                                                since_id=None,
                                                before_id=None)

    def test_messages_before_index_arguments_use_before_id(
            self, MockMP, MockM):
        messages = self.recipient.messages(before=123)
        self.mock_index.assert_called_once_with('idkey',
                                                after_id=None,
                                                since_id=None,
                                                before_id=123)

    def test_messages_since_index_arguments_use_since_id(self, MockMP, MockM):
        messages = self.recipient.messages(since=123)
        self.mock_index.assert_called_once_with('idkey',
                                                after_id=None,
                                                since_id=123,
                                                before_id=None)

    def test_messages_before_and_after_raises_ValueError(self, MockMP, MockM):
        with self.assertRaises(ValueError):
            messages = self.recipient.messages(before=12, after=34)

    def test_messages_before_and_since_raises_ValueError(self, MockMP, MockM):
        with self.assertRaises(ValueError):
            messages = self.recipient.messages(before=12, since=34)

    def test_messages_since_and_after_raises_ValueError(self, MockMP, MockM):
        with self.assertRaises(ValueError):
            messages = self.recipient.messages(since=12, after=34)
コード例 #5
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
class RecipientPostShortMessageTests(unittest.TestCase):
    @mock.patch('groupy.api.endpoint.Endpoint')
    def setUp(self, mock_endpoint):
        self.recipient = Recipient(mock_endpoint(), 'm', 'i',
                                                    i='idkey', m='mkey')
        self.recipient.post('test message')
        self.mock_create = self.recipient._endpoint.create

    def test_post_short_message_calls_endpoint_once(self):
        self.assertEqual(self.mock_create.call_count, 1)

    def test_post_short_message_calls_endpoint_with_id_key(self):
        self.mock_create.assert_called_with('idkey', 'test message')
コード例 #6
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
 def setUp(self, mock_endpoint):
     # TODO: Fix this literal dependency!
     self.chunks = ('x' * 1000, 'x' * 100)
     self.recipient = Recipient(mock_endpoint(), 'm', 'i',
                                                 i='idkey', m='mkey')
     self.recipient.post(''.join(self.chunks))
     self.mock_create = self.recipient._endpoint.create
コード例 #7
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
class RecipientPostLongMessageTests(unittest.TestCase):
    @mock.patch('groupy.api.endpoint.Endpoint')
    def setUp(self, mock_endpoint):
        # TODO: Fix this literal dependency!
        self.chunks = ('x' * 1000, 'x' * 100)
        self.recipient = Recipient(mock_endpoint(), 'm', 'i',
                                                    i='idkey', m='mkey')
        self.recipient.post(''.join(self.chunks))
        self.mock_create = self.recipient._endpoint.create

    def test_post_long_message_calls_endpoint_twice(self):
        self.assertEqual(self.mock_create.call_count, 2)

    def test_post_long_message_calls_endpoint_with_each_chunk(self):
        calls = [call('idkey', self.chunks[0]), call('idkey', self.chunks[1])]
        self.mock_create.assert_has_calls(calls)
コード例 #8
0
class RecipientPostShortMessageTests(unittest.TestCase):
    @mock.patch('groupy.api.endpoint.Endpoint')
    def setUp(self, mock_endpoint):
        self.recipient = Recipient(mock_endpoint(),
                                   'm',
                                   'i',
                                   i='idkey',
                                   m='mkey')
        self.recipient.post('test message')
        self.mock_create = self.recipient._endpoint.create

    def test_post_short_message_calls_endpoint_once(self):
        self.assertEqual(self.mock_create.call_count, 1)

    def test_post_short_message_calls_endpoint_with_id_key(self):
        self.mock_create.assert_called_with('idkey', 'test message')
コード例 #9
0
class RecipientPostLongMessageTests(unittest.TestCase):
    @mock.patch('groupy.api.endpoint.Endpoint')
    def setUp(self, mock_endpoint):
        # TODO: Fix this literal dependency!
        self.chunks = ('x' * 1000, 'x' * 100)
        self.recipient = Recipient(mock_endpoint(),
                                   'm',
                                   'i',
                                   i='idkey',
                                   m='mkey')
        self.recipient.post(''.join(self.chunks))
        self.mock_create = self.recipient._endpoint.create

    def test_post_long_message_calls_endpoint_twice(self):
        self.assertEqual(self.mock_create.call_count, 2)

    def test_post_long_message_calls_endpoint_with_each_chunk(self):
        calls = [call('idkey', self.chunks[0]), call('idkey', self.chunks[1])]
        self.mock_create.assert_has_calls(calls)
コード例 #10
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
class RecipientMessagesTests(unittest.TestCase):
    @mock.patch('groupy.api.endpoint.Endpoint')
    def setUp(self, mock_endpoint):
        self.recipient = Recipient(mock_endpoint(), 'm', 'i',
                                                    i='idkey', m='mkey')
        self.mock_index = self.recipient._endpoint.index

    def test_messages_calls_MessagePager_once(self, MockMP, MockM):
        messages = self.recipient.messages()
        self.assertEqual(MockMP.call_count, 1)

    def test_messages_calls_endpoint_index_once(self, MockMP, MockM):
        messages = self.recipient.messages()
        self.mock_index.assert_called_once_with(
            'idkey', after_id=None, since_id=None, before_id=None
        )

    def test_messages_returns_MessagePager(self, MockMP, MockM):
        messages = self.recipient.messages()
        self.assertEqual(messages.__class__, groupy.object.listers.MessagePager)

    def test_messages_after_index_arguments_use_after_id(self, MockMP, MockM):
        messages = self.recipient.messages(after=123)
        self.mock_index.assert_called_once_with('idkey', after_id=123,
                                                since_id=None, before_id=None)

    def test_messages_before_index_arguments_use_before_id(self, MockMP, MockM):
        messages = self.recipient.messages(before=123)
        self.mock_index.assert_called_once_with('idkey', after_id=None,
                                                since_id=None, before_id=123)

    def test_messages_since_index_arguments_use_since_id(self, MockMP, MockM):
        messages = self.recipient.messages(since=123)
        self.mock_index.assert_called_once_with('idkey', after_id=None,
                                                since_id=123, before_id=None)

    def test_messages_before_and_after_raises_ValueError(self, MockMP, MockM):
        with self.assertRaises(ValueError):
            messages = self.recipient.messages(before=12, after=34)

    def test_messages_before_and_since_raises_ValueError(self, MockMP, MockM):
        with self.assertRaises(ValueError):
            messages = self.recipient.messages(before=12, since=34)

    def test_messages_since_and_after_raises_ValueError(self, MockMP, MockM):
        with self.assertRaises(ValueError):
            messages = self.recipient.messages(since=12, after=34)
コード例 #11
0
 def setUp(self, mock_endpoint):
     recipient = Recipient(mock_endpoint(), 'm', 'i', i='idkey', m='mkey')
     self.recipient = recipient
コード例 #12
0
 def setUp(self, mock_endpoint):
     recipient = Recipient(mock_endpoint(), 'm', 'i', i='idkey', m='mkey')
     recipient.message_count = 10
     self.recipient = recipient
コード例 #13
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
 def test_chunkify_breaks_words_if_no_whitespace(self):
     chunks = Recipient._chunkify('abc123', 5)
     self.assertEqual(chunks, ['abc12', '3'])
コード例 #14
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
 def test_chunkify_breaks_across_whitespace_if_possible(self):
     chunks = Recipient._chunkify('abc 123', 5)
     self.assertEqual(chunks, ['abc', '123'])
コード例 #15
0
 def test_empty_text_returns_one_None_chunk(self):
     chunks = Recipient._chunkify('')
     self.assertEqual(chunks, [None])
コード例 #16
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
 def setUp(self, mock_endpoint):
     self.recipient = Recipient(mock_endpoint(), 'm', 'i',
                                                 i='idkey', m='mkey')
     self.mock_index = self.recipient._endpoint.index
コード例 #17
0
 def test_text_shorter_than_chunk_size_remain_one_chunk(self):
     chunks = Recipient._chunkify('x', 2)
     self.assertEqual(len(chunks), 1)
コード例 #18
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
 def setUp(self, mock_endpoint):
     self.recipient = Recipient(mock_endpoint(), 'm', 'i',
                                                 i='idkey', m='mkey')
     self.recipient.post('test message')
     self.mock_create = self.recipient._endpoint.create
コード例 #19
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
 def setUp(self, mock_endpoint):
     recipient = Recipient(mock_endpoint(), 'm', 'i', i='idkey', m='mkey')
     recipient.message_count = 10
     self.recipient = recipient
コード例 #20
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
 def test_text_shorter_than_chunk_size_remain_one_chunk(self):
     chunks = Recipient._chunkify('x', 2)
     self.assertEqual(len(chunks), 1)
コード例 #21
0
 def test_text_longer_than_chunk_size_gets_split(self):
     chunks = Recipient._chunkify('xxx', 2)
     self.assertEqual(len(chunks), 2)
コード例 #22
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
 def test_text_equal_to_chunk_size_remains_one_chunk(self):
     chunks = Recipient._chunkify('xx', 2)
     self.assertEqual(len(chunks), 1)
コード例 #23
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
 def test_text_longer_than_chunk_size_gets_split(self):
     chunks = Recipient._chunkify('xxx', 2)
     self.assertEqual(len(chunks), 2)
コード例 #24
0
 def test_text_equal_to_chunk_size_remains_one_chunk(self):
     chunks = Recipient._chunkify('xx', 2)
     self.assertEqual(len(chunks), 1)
コード例 #25
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
 def test_text_as_None_returns_one_None_chunk(self):
     chunks = Recipient._chunkify(None)
     self.assertEqual(chunks, [None])
コード例 #26
0
 def test_text_as_None_returns_one_None_chunk(self):
     chunks = Recipient._chunkify(None)
     self.assertEqual(chunks, [None])
コード例 #27
0
 def test_chunkify_breaks_words_if_no_whitespace(self):
     chunks = Recipient._chunkify('abc123', 5)
     self.assertEqual(chunks, ['abc12', '3'])
コード例 #28
0
 def test_chunkify_breaks_across_whitespace_if_possible(self):
     chunks = Recipient._chunkify('abc 123', 5)
     self.assertEqual(chunks, ['abc', '123'])
コード例 #29
0
ファイル: test_responses.py プロジェクト: JCDJulian/Groupy
 def test_empty_text_returns_one_None_chunk(self):
     chunks = Recipient._chunkify('')
     self.assertEqual(chunks, [None])