コード例 #1
0
def _mock_august_authentication(token_text, token_timestamp):
    authentication = MagicMock(name="august.authentication")
    type(authentication).state = PropertyMock(
        return_value=AuthenticationState.AUTHENTICATED)
    type(authentication).access_token = PropertyMock(return_value=token_text)
    type(authentication).access_token_expires = PropertyMock(
        return_value=token_timestamp)
    return authentication
コード例 #2
0
    async def test_owner_channel_not(self):
        ownerProperty = PropertyMock(return_value=False)
        type(self.permissions).inOwnerChannel = ownerProperty

        @chat.ownerChannel
        async def t(args):
            return True

        self.assertIs(await t(self.args), False)
        ownerProperty.assert_called_once_with()
コード例 #3
0
 def test_diff_localized_no_si(self, app, community):
     type(community).short_currency = PropertyMock(return_value="TC")
     referential = Quantitative(101010110, community, app, None)
     async def exec_test():
         value = await referential.diff_localized(units=True)
         self.assertEqual(value, "101,010,110 TC")
     self.lp.run_until_complete(exec_test())
コード例 #4
0
 async def test_chatCommand(self, mock_commands, mock_data, mock_log):
     command1 = CoroutineMock(spec=lambda args: False, return_value=False)
     command2 = CoroutineMock(spec=lambda args: False, return_value=True)
     command3 = CoroutineMock(spec=lambda args: False, return_value=False)
     mock_commands.return_value = [command1, command2, command3]
     data = MagicMock(spec=CacheStore)
     data.__aenter__.return_value = data
     data.__aexit__.return_value = True
     data.isPermittedUser.return_value = False
     data.isBotManager.return_value = False
     mock_data.return_value = data
     message = Mock(spec=Message)
     type(message).command = PropertyMock(return_value='Kappa')
     await channel.chatCommand(self.channel, self.tags, 'botgotsthis',
                               message, self.now)
     data.twitch_save_id.assert_has_calls(
         [call('2', 'megotsthis'),
          call('1', 'botgotsthis')])
     self.assertEqual(data.isPermittedUser.call_count, 1)
     self.assertEqual(data.isBotManager.call_count, 1)
     self.assertEqual(mock_commands.call_count, 1)
     self.assertEqual(command1.call_count, 1)
     self.assertEqual(command2.call_count, 1)
     self.assertEqual(command3.call_count, 0)
     self.assertEqual(mock_log.call_count, 0)
コード例 #5
0
async def test_listen():
    player = PlayerNetworkChild(
        player_configuration=player_configuration,
        avatar=12,
        server_configuration=server_configuration,
        start_listening=False,
    )

    type(player).websocket_url = PropertyMock(
        return_value="ws://localhost:8899")

    player._handle_message = CoroutineMock()
    semaphore = asyncio.Semaphore()

    async def showdown_server_mock(websocket, path):
        semaphore.release()
        await websocket.ping()
        await websocket.send("error|test 1")
        await websocket.send("error|test 2")
        await websocket.send("error|test 3")

    await semaphore.acquire()

    gathered = asyncio.gather(
        websockets.serve(showdown_server_mock, "0.0.0.0", 8899))

    await player.listen()

    await gathered
    assert player._handle_message.await_count == 3
    player._handle_message.assert_awaited_with("error|test 3")
コード例 #6
0
 async def test_whisperCommand_data_except(
         self, mock_commands, mock_data, mock_log):
     mock_data.side_effect = Exception
     message = Mock(spec=Message)
     type(message).command = PropertyMock(return_value='Kappa')
     await whisper.whisperCommand(self.tags, 'botgotsthis', message,
                                  self.now)
     self.assertFalse(mock_commands.called)
     self.assertTrue(mock_log.called)
コード例 #7
0
 def test_localized_no_units_with_si(self, app, community):
     type(community).short_currency = PropertyMock(return_value="TC")
     app.preferences = {
         'digits_after_comma': 6
     }
     referential = Quantitative(101010110, community, app, None)
     async def exec_test():
         value = await referential.localized(units=False, international_system=True)
         self.assertEqual(value, "101.010110 M")
     self.lp.run_until_complete(exec_test())
コード例 #8
0
ファイル: test_relative.py プロジェクト: mmuman/sakia
 def test_localized_no_units_no_si(self, app, community):
     community.dividend = CoroutineMock(return_value=10000)
     type(community).short_currency = PropertyMock(return_value="TC")
     app.preferences = {
         'digits_after_comma': 6
     }
     referential = Relative(1011, community, app, None)
     async def exec_test():
         value = await referential.localized(units=False, international_system=False)
         self.assertEqual(value, "0.101100")
     self.lp.run_until_complete(exec_test())
コード例 #9
0
    def test_localized_no_si(self, app, community):
        type(community).short_currency = PropertyMock(return_value="TC")
        community.get_ud_block = CoroutineMock(
            return_value={'membersCount': 5})
        community.monetary_mass = CoroutineMock(return_value=500)
        referential = QuantitativeZSum(110, community, app, None)

        async def exec_test():
            value = await referential.localized(units=True)
            self.assertEqual(value, "10 Q0 TC")

        self.lp.run_until_complete(exec_test())
コード例 #10
0
ファイル: test_relative_zsum.py プロジェクト: mmuman/sakia
    def test_localized_no_si(self, app, community):
        type(community).short_currency = PropertyMock(return_value="TC")
        community.dividend = CoroutineMock(return_value=100)
        community.get_ud_block = CoroutineMock(side_effect=lambda *args, **kwargs: \
                                                            {'membersCount': 5, "monetaryMass": 500, "dividend": 100} if 'x' in kwargs \
                                                            else {'membersCount': 5, "monetaryMass": 1050, "dividend": 100} )
        referential = RelativeZSum(110, community, app, None)

        async def exec_test():
            value = await referential.localized(units=True)
            self.assertEqual(value, "0.1 R0 TC")

        self.lp.run_until_complete(exec_test())
コード例 #11
0
    def setUp(self):
        super().setUp()

        self.cache_property = PropertyMock(return_value=self.now)
        type(self.channel).twitchCache = self.cache_property

        self.streaming_property = PropertyMock(return_value=None)
        type(self.channel).streamingSince = self.streaming_property

        self.status_property = PropertyMock(return_value=None)
        type(self.channel).twitchStatus = self.status_property

        self.game_property = PropertyMock(return_value=None)
        type(self.channel).twitchGame = self.game_property

        self.channel.sessionData = {}
コード例 #12
0
    def test_diff_localized_no_units_no_si(self, app, community):
        community.dividend = CoroutineMock(return_value=10000)
        community.get_ud_block = CoroutineMock(
            return_value={'medianTime': 1452663088792})
        type(community).short_currency = PropertyMock(return_value="TC")
        app.preferences = {'digits_after_comma': 6}
        referential = RelativeToPast(1011, community, app, 100)

        async def exec_test():
            value = await referential.diff_localized(
                units=False, international_system=False)
            self.assertEqual(value, "0.101100")

        self.lp.run_until_complete(exec_test())
コード例 #13
0
    def test_localized_no_units_no_si(self, app, community):
        type(community).short_currency = PropertyMock(return_value="TC")
        community.get_ud_block = CoroutineMock(
            return_value={'membersCount': 5})
        community.monetary_mass = CoroutineMock(return_value=500)
        app.preferences = {'digits_after_comma': 6}
        referential = QuantitativeZSum(110, community, app, None)

        async def exec_test():
            value = await referential.localized(units=False,
                                                international_system=False)
            self.assertEqual(value, "10")

        self.lp.run_until_complete(exec_test())
コード例 #14
0
ファイル: test_relative_zsum.py プロジェクト: mmuman/sakia
    def test_diff_localized_no_units_with_si(self, app, community):
        type(community).short_currency = PropertyMock(return_value="TC")
        community.dividend = CoroutineMock(return_value=100)
        community.get_ud_block = CoroutineMock(side_effect=lambda *args, **kwargs: \
                                                            {'membersCount': 5, "monetaryMass": 500, "dividend": 100} if 'x' in kwargs \
                                                            else {'membersCount': 5, "monetaryMass": 1050, "dividend": 100} )
        app.preferences = {'digits_after_comma': 6}
        referential = RelativeZSum(90, community, app, None)

        async def exec_test():
            value = await referential.diff_localized(units=False,
                                                     international_system=True)
            self.assertEqual(value, "900.000000 mUD ")

        self.lp.run_until_complete(exec_test())
コード例 #15
0
 async def test_whisperCommand_except(self, mock_commands, mock_data,
                                      mock_log):
     command = CoroutineMock(spec=lambda args: False, side_effect=Exception)
     mock_commands.return_value = [command, command]
     data = MagicMock(spec=CacheStore)
     data.__aenter__.return_value = data
     data.__aexit__.return_value = False
     mock_data.return_value = data
     message = Mock(spec=Message)
     type(message).command = PropertyMock(return_value='Kappa')
     await whisper.whisperCommand(self.tags, 'botgotsthis', message,
                                  self.now)
     self.assertEqual(data.isBotManager.call_count, 1)
     self.assertEqual(mock_commands.call_count, 1)
     self.assertEqual(command.call_count, 1)
     self.assertTrue(mock_log.called)
コード例 #16
0
 async def test_whisperCommand(self, mock_commands, mock_data):
     command1 = CoroutineMock(spec=lambda args: False, return_value=False)
     command2 = CoroutineMock(spec=lambda args: False, return_value=True)
     command3 = CoroutineMock(spec=lambda args: False, return_value=False)
     mock_commands.return_value = [command1, command2, command3]
     data = MagicMock(spec=CacheStore)
     data.__aenter__.return_value = data
     data.__aexit__.return_value = True
     mock_data.return_value = data
     message = Mock(spec=Message)
     type(message).command = PropertyMock(return_value='Kappa')
     await whisper.whisperCommand(self.tags, 'botgotsthis', message,
                                  self.now)
     self.assertEqual(data.isBotManager.call_count, 1)
     self.assertEqual(mock_commands.call_count, 1)
     self.assertEqual(command1.call_count, 1)
     self.assertEqual(command2.call_count, 1)
     self.assertEqual(command3.call_count, 0)
コード例 #17
0
    def test_localized_no_si(self, app, community):
        community.dividend = CoroutineMock(return_value=1000)
        community.get_ud_block = CoroutineMock(
            return_value={'medianTime': 1452663088792})
        type(community).short_currency = PropertyMock(return_value="TC")
        app.preferences = {'digits_after_comma': 6}
        referential = RelativeToPast(101, community, app, 100)

        async def exec_test():
            value = await referential.localized(units=True)
            self.assertEqual(
                value, "0.101000 UD({0}) TC".format(
                    QLocale.toString(
                        QLocale(),
                        QDateTime.fromTime_t(1452663088792).date(),
                        QLocale.dateFormat(QLocale(), QLocale.ShortFormat))))

        self.lp.run_until_complete(exec_test())
コード例 #18
0
class TestTasksTwitchStreams(TestTasksTwitchBase):
    def setUp(self):
        super().setUp()

        self.cache_property = PropertyMock(return_value=self.now)
        type(self.channel).twitchCache = self.cache_property

        self.streaming_property = PropertyMock(return_value=None)
        type(self.channel).streamingSince = self.streaming_property

        self.status_property = PropertyMock(return_value=None)
        type(self.channel).twitchStatus = self.status_property

        self.game_property = PropertyMock(return_value=None)
        type(self.channel).twitchGame = self.game_property

        self.channel.sessionData = {}

    @patch('lib.api.twitch.active_streams')
    async def test_streams_empty(self, mock_active):
        self.mock_globals.channels = {}
        await twitch.checkStreamsAndChannel(self.now)
        self.assertFalse(mock_active.called)

    @patch('lib.api.twitch.active_streams')
    async def test_streams_none(self, mock_active):
        mock_active.return_value = None
        await twitch.checkStreamsAndChannel(self.now)
        self.assertTrue(mock_active.called)
        self.assertFalse(self.cache_property.called)
        self.assertFalse(self.streaming_property.called)
        self.assertFalse(self.status_property.called)
        self.assertFalse(self.game_property.called)

    @patch('lib.api.twitch.active_streams')
    async def test_streams(self, mock_active):
        streamed = datetime(1999, 1, 1)
        mock_active.return_value = {
            'botgotsthis': TwitchStatus(streamed, 'Kappa', 'Creative', [])
        }
        await twitch.checkStreamsAndChannel(self.now)
        self.assertTrue(mock_active.called)
        self.cache_property.assert_called_once_with(self.now)
        self.streaming_property.assert_called_once_with(streamed)
        self.status_property.assert_called_once_with('Kappa')
        self.game_property.assert_called_once_with('Creative')

    @patch('lib.api.twitch.active_streams')
    async def test_streams_offline(self, mock_active):
        mock_active.return_value = {}
        await twitch.checkStreamsAndChannel(self.now)
        self.assertTrue(mock_active.called)
        self.assertFalse(self.cache_property.called)
        self.streaming_property.assert_called_once_with(None)
        self.assertFalse(self.status_property.called)
        self.assertFalse(self.game_property.called)

    @patch('lib.api.twitch.channel_community')
    @patch('lib.api.twitch.channel_properties')
    async def test_offline_empty(self, mock_channel, mock_community):
        self.mock_globals.channels = {}
        await twitch.checkOfflineChannels(self.now)
        self.assertFalse(mock_channel.called)
        self.assertFalse(self.cache_property.called)
        self.assertFalse(self.streaming_property.called)
        self.assertFalse(self.status_property.called)
        self.assertFalse(self.game_property.called)
        self.assertFalse(mock_community.called)
        self.assertFalse(self.data.twitch_save_community.called)

    @patch('lib.api.twitch.channel_community')
    @patch('lib.api.twitch.channel_properties')
    async def test_offline_streaming(self, mock_channel, mock_community):
        self.channel.isStreaming = True
        self.cache_property.return_value = self.now - timedelta(hours=1)
        await twitch.checkOfflineChannels(self.now)
        self.assertFalse(mock_channel.called)
        self.assertFalse(self.cache_property.called)
        self.assertFalse(self.streaming_property.called)
        self.assertFalse(self.status_property.called)
        self.assertFalse(self.game_property.called)
        self.assertFalse(mock_community.called)
        self.assertFalse(self.data.twitch_save_community.called)

    @patch('lib.api.twitch.channel_community')
    @patch('lib.api.twitch.channel_properties')
    async def test_offline_recent(self, mock_channel, mock_community):
        mock_community.return_value = None
        self.channel.isStreaming = False
        self.cache_property.return_value = self.now
        await twitch.checkOfflineChannels(self.now)
        self.assertFalse(mock_channel.called)
        self.cache_property.assert_called_once_with()
        self.assertFalse(self.streaming_property.called)
        self.assertFalse(self.status_property.called)
        self.assertFalse(self.game_property.called)
        self.assertFalse(mock_community.called)
        self.assertFalse(self.data.twitch_save_community.called)

    @patch('lib.api.twitch.channel_community')
    @patch('lib.api.twitch.channel_properties')
    async def test_offline_none(self, mock_channel, mock_community):
        mock_community.return_value = None
        mock_channel.return_value = None
        self.channel.isStreaming = False
        self.cache_property.return_value = self.now - timedelta(hours=1)
        await twitch.checkOfflineChannels(self.now)
        mock_channel.assert_called_once_with('botgotsthis')
        self.cache_property.assert_has_calls(
            [call(),
             call(self.now),
             call(self.now - timedelta(seconds=240))])
        self.assertFalse(self.streaming_property.called)
        self.assertFalse(self.status_property.called)
        self.assertFalse(self.game_property.called)
        self.assertFalse(mock_community.called)
        self.assertFalse(self.data.twitch_save_community.called)

    @patch('lib.api.twitch.channel_community')
    @patch('lib.api.twitch.channel_properties')
    async def test_offline(self, mock_channel, mock_community):
        mock_community.return_value = None
        mock_channel.return_value = TwitchStatus(None, 'Keepo', 'Music', None)
        self.channel.isStreaming = False
        self.cache_property.return_value = self.now - timedelta(hours=1)
        await twitch.checkOfflineChannels(self.now)
        mock_channel.assert_called_once_with('botgotsthis')
        self.cache_property.assert_has_calls([call(), call(self.now)])
        self.streaming_property.assert_called_once_with(None)
        self.status_property.assert_called_once_with('Keepo')
        self.game_property.assert_called_once_with('Music')
        mock_community.assert_called_once_with('botgotsthis')
        self.assertFalse(self.data.twitch_save_community.called)

    @patch('lib.api.twitch.channel_community')
    @patch('lib.api.twitch.channel_properties')
    async def test_offline_multiple(self, mock_channel, mock_community):
        async def wait(*args):
            await asyncio.sleep(0.2)
            return TwitchStatus(None, 'Keepo', 'Music', None)

        async def call_0():
            await twitch.checkOfflineChannels(self.now)

        async def call_1():
            await asyncio.sleep(0.1)
            await twitch.checkOfflineChannels(self.now)

        mock_community.return_value = None
        mock_channel.side_effect = wait
        self.channel.isStreaming = False
        self.cache_property.return_value = self.now - timedelta(hours=1)
        await asyncio.gather(call_0(), call_1())
        mock_channel.assert_called_once_with('botgotsthis')
        self.cache_property.assert_has_calls([call(), call(self.now)])
        self.streaming_property.assert_called_once_with(None)
        self.status_property.assert_called_once_with('Keepo')
        self.game_property.assert_called_once_with('Music')
        mock_community.assert_called_once_with('botgotsthis')
        self.assertFalse(self.data.twitch_save_community.called)

    @patch('lib.api.twitch.channel_community')
    @patch('lib.api.twitch.channel_properties')
    async def test_offline_community_empty(self, mock_channel, mock_community):
        mock_community.return_value = []
        mock_channel.return_value = TwitchStatus(None, 'Keepo', 'Music', None)
        self.channel.isStreaming = False
        self.cache_property.return_value = self.now - timedelta(hours=1)
        await twitch.checkOfflineChannels(self.now)
        mock_channel.assert_called_once_with('botgotsthis')
        self.cache_property.assert_has_calls([call(), call(self.now)])
        self.streaming_property.assert_called_once_with(None)
        self.status_property.assert_called_once_with('Keepo')
        self.game_property.assert_called_once_with('Music')
        mock_community.assert_called_once_with('botgotsthis')
        self.assertFalse(self.data.twitch_save_community.called)

    @patch('lib.api.twitch.channel_community')
    @patch('lib.api.twitch.channel_properties')
    async def test_offline_community(self, mock_channel, mock_community):
        mock_community.return_value = [TwitchCommunity('1', 'BotGotsThis')]
        mock_channel.return_value = TwitchStatus(None, 'Keepo', 'Music', None)
        self.channel.isStreaming = False
        self.cache_property.return_value = self.now - timedelta(hours=1)
        await twitch.checkOfflineChannels(self.now)
        mock_channel.assert_called_once_with('botgotsthis')
        self.cache_property.assert_has_calls([call(), call(self.now)])
        self.streaming_property.assert_called_once_with(None)
        self.status_property.assert_called_once_with('Keepo')
        self.game_property.assert_called_once_with('Music')
        mock_community.assert_called_once_with('botgotsthis')
        self.data.twitch_save_community.assert_called_once_with(
            '1', 'BotGotsThis')
コード例 #19
0
 def test_diff_units(self, app, community):
     type(community).short_currency = PropertyMock(return_value="TC")
     referential = RelativeToPast(0, community, app, 100)
     self.assertEqual(referential.units, "UD(t) TC")
コード例 #20
0
ファイル: test_relative_zsum.py プロジェクト: mmuman/sakia
 def test_units(self, app, community):
     type(community).short_currency = PropertyMock(return_value="TC")
     referential = RelativeZSum(0, community, app, None)
     self.assertEqual(referential.units, "R0 TC")
コード例 #21
0
 def test_diff_units(self, app, community):
     type(community).short_currency = PropertyMock(return_value="TC")
     referential = Quantitative(0, community, app, None)
     self.assertEqual(referential.units, "TC")