def test_empty_message(self, gu, fd): cl = client.Client(FakeArgs()) cl.downloader._download = mock.MagicMock(return_value='aa') cl.session = mock.MagicMock() channel = o.Channel({'name': 'test', 'id': 'C00000001'}) cl._create_message({'type': 'message', 'text': ''}, channel) cl.session.add.assert_not_called()
def test_message_with_reaction(self, gu, fd): cl = client.Client(FakeArgs()) cl.downloader._download = mock.MagicMock(return_value='aa') cl.session = mock.MagicMock() channel = o.Channel({'name': 'test', 'id': 'C00000001'}) cl._create_message(MSGS['messages'][1], channel) msg = cl.session.add.call_args[0][0] self.assertEqual(len(msg.attachments), 1) self.assertEqual(len(msg.reactions), 1) self.assertEqual(msg.reactions[0].name, '+1') self.assertFalse(msg.is_starred)
def test_external_file_upload(self, gu, fd): cl = client.Client(FakeArgs()) cl.downloader._download = mock.MagicMock(return_value='aa') cl.session = mock.MagicMock() channel = o.Channel({'name': 'test', 'id': 'C00000001'}) cl._create_message(SHARED, channel) msg = cl.session.add.call_args[0][0] self.assertEqual(len(msg.attachments), 0) self.assertTrue('shared a file' in msg.text) self.assertFalse(msg.is_starred) self.assertEqual(msg.type, 'file_share') fd.assert_called_once_with(msg, SHARED['files'][0])
def test_pinned_message_with_attachments(self, gu, fd): cl = client.Client(FakeArgs()) cl.downloader._download = mock.MagicMock(return_value='aa') cl.session = mock.MagicMock() cl._url_file_to_attachment = True channel = o.Channel({'name': 'test', 'id': 'C00000001'}) cl._create_message(PINNED, channel) msg = cl.session.add.call_args[0][0] self.assertEqual(len(msg.attachments), 1) self.assertEqual(msg.text, '<@UAAAAAAAA> pinned a message to this ' 'channel.') self.assertEqual(msg.type, 'pinned_item') self.assertEqual(msg.attachments[0].text, 'the text') self.assertEqual(msg.attachments[0].title, 'Fake service title')
def update_channels(self): """Fetch and update channel list with current state in db""" logging.info("Fetching and update channels information in DB") result = self._channels_list() if not result: return for data in result: channel = self.q(o.Channel).\ filter(o.Channel.slackid == data['id']).one_or_none() if not channel: channel = o.Channel() self.session.add(channel) self._update_channel(channel, data) self.session.commit()
def test_starred_item(self, gu): cl = client.Client(FakeArgs()) cl.downloader._download = mock.MagicMock(return_value='aa') cl.session = mock.MagicMock() channel = o.Channel({'name': 'test', 'id': 'C00000001'}) data = { "type": "message", "user": "******", "text": "test", "ts": "1479501074.000032", "is_starred": True } cl._create_message(data, channel) msg = cl.session.add.call_args[0][0] self.assertEqual(len(msg.attachments), 0) self.assertEqual(msg.text, 'test') self.assertEqual(msg.type, '') self.assertTrue(msg.is_starred)
def update_channels(self): """Fetch and update channel list with current state in db""" logging.info("Fetching and update channels information in DB") result = self._channels_list() if not result: return if self._raw_fname: with open(self._raw_fname.format(name='channels'), 'w') as fobj: fobj.write(json.dumps(result)) for data in result: channel = self.q(o.Channel).\ filter(o.Channel.slackid == data['id']).one_or_none() if not channel: channel = o.Channel() self.session.add(channel) self._update_channel(channel, data) self.session.commit()