async def test_wait_error_code_1(self): TestDriver.message = {'failed': 1, 'ts': 42} session = API(TestSession()) lp = LongPoll(session, mode=0) response = await lp.wait() self.assertDictEqual(response, {'ts': -TestSession.TS})
async def test_wait_valid(self): TestDriver.message = {'ts': -TestSession.TS} session = API(TestSession()) lp = LongPoll(session, mode=0) response = await lp.wait() self.assertDictEqual(response, TestDriver.message)
async def test_get_pts_need_ts(self): session = API(TestSession()) lp = LongPoll(session, mode=0) result = await lp.get_pts(need_ts=True) self.assertEqual(len(result), 2) self.assertEqual(result[0], TestSession.PTS) self.assertEqual(result[1], TestSession.TS)
async def test_get_pts_cached_value(self): session = API(TestSession()) lp = LongPoll(session, mode=0) await lp.get_pts() pts = await lp.get_pts() self.assertIsInstance(pts, type(TestSession.PTS)) self.assertEqual(pts, TestSession.PTS)
async def test_wait_error_code_4(self): TestDriver.message = {'failed': 4} session = API(TestSession()) lp = LongPoll(session, mode=0) with self.assertRaises(VkLongPollError): await lp.wait()
async def test_longpoll_get_pts_need_ts(session): lp = LongPoll(session, mode=0) result = await lp.get_pts(need_ts=True) assert len(result) == 2 assert result[0] == Session.PTS assert result[1] == Session.TS
async def test_longpoll_get_cached_pts(session): lp = LongPoll(session, mode=0) await lp.get_pts() pts = await lp.get_pts() assert pts == Session.PTS
@pytest.mark.parametrize( 'messages, exception, ts', [ ([{'ts': 23}], None, 23), ([{'failed': 1, 'ts': 42}, {'ts': 45, 'updates': [Driver.original_event]}], None, 45), ([{'failed': 2}, {'ts': 63, 'updates': [Driver.original_event]}], None, 63), ([{'failed': 3}, {'ts': 56, 'updates': [Driver.original_event]}], None, 56), ([{'failed': 4}, {'ts': 11, 'updates': [Driver.original_event]}], VkLongPollError, None), ] ) @pytest.mark.parametrize( 'longpoll', [ lambda session: LongPoll(session, mode=0), lambda session: LongPoll(session, mode=1), lambda session: LongPoll(session, mode=1, version=1), lambda session: BotsLongPoll(session, group_id=1), lambda session: BotsLongPoll(session, group_id=1, version=3), ] ) async def test_longpoll_wait(longpoll, messages, exception, ts): session = Session() session.driver.messages = messages session = API(session) lp = longpoll(session) session._session.driver.expected_mode = lp.base_params.get('mode') session._session.driver.expected_version = lp.base_params.get('version')
async def test_init_with_api(self): session = API(TestSession()) lp = LongPoll(session, mode=0) await lp._get_long_poll_server()