def test_filter_push(self): f = mocks.FE() w = messager.Messager(f) w.filter = None f0 = filters.Yes() w.filter_push(f0) self.assertIs(w.filter, f0) self.assertEqual(w.filter_stack, []) f1 = filters.No() w.filter_push(f1) self.assertEqual(w.filter, filters.And(f0, f1)) self.assertEqual(w.filter_stack, [f0])
async def test___init___1(self): s = slack.Slack(None, name='test') await s.incoming({ 'type': 'team_join', 'user': {'id': 'USER', 'name': 'user'}, }) await s.incoming({ 'type': 'channel_created', 'channel': { 'id': 'CHANNEL', 'name': 'channel', 'is_member': True}, }) await s.incoming({ 'type': 'im_created', 'channel': { 'id': 'IM', 'user': '******'}, }) m = slack.SlackMessage(s, { 'ts': 0.0, 'user': '******', 'type': 'message', 'text': None, 'channel': 'CHANNEL', }) self.assertEqual('test; user', str(m.sender)) self.assertEqual('00:00 test; user\n', str(m)) m = slack.SlackMessage(s, { 'ts': 0.0, 'bot_id': 'USER', 'type': 'message', 'text': None, 'channel': 'CHANNEL', }) self.assertEqual('test; user', str(m.sender)) self.assertEqual('00:00 test; user\n', str(m)) m = slack.SlackMessage(s, { 'ts': 0.0, 'user': {'id': 'USER'}, 'type': 'message', 'text': 'text', 'channel': 'CHANNEL', }) self.assertEqual('test; user', str(m.sender)) self.assertEqual('00:00 test; user\ntext', str(m)) m = slack.SlackMessage(s, { 'ts': 0.0, 'user': '******', 'type': 'message', 'text': 'text<bar|foo>text', 'channel': 'CHANNEL', }) self.assertEqual('test; user', str(m.sender)) self.assertEqual('00:00 test; user\ntextfootext', str(m)) m = slack.SlackMessage(s, { 'ts': 0.0, 'user': '******', 'type': 'message', 'text': '<@USER>\n<#CHANNEL>\n<foo>', 'channel': 'CHANNEL', }) self.assertEqual('test; user', str(m.sender)) self.assertEqual('00:00 test; user\nuser\n#channel\nfoo', str(m)) self.assertEqual('test; #channel', m.followup()) self.assertEqual( filters.And( filters.Compare('==', 'backend', 'test'), filters.Compare('==', 'channel', '#channel'), filters.Compare('==', 'sender', 'test; user'), ), m.filter(1)) m = slack.SlackMessage(s, { 'ts': 0.0, 'user': '******', 'type': 'message', 'text': 'foo', 'channel': 'IM', }) self.assertEqual('test; user', str(m.sender)) self.assertEqual('00:00 test; user\nfoo', str(m)) self.assertTrue(m.personal) self.assertEqual('test; user', m.followup()) m = slack.SlackMessage(s, { 'ts': 0.0, 'user': '******', 'type': 'presence_change', 'presence': 'out', }) self.assertEqual('test; user', str(m.sender)) self.assertEqual('00:00 test; user\nuser is out', str(m)) self.assertTrue(m.noise) self.assertEqual('test; user', m.followup())