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
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())
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 = {}
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)
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")
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)
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()
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())
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())
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())
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())
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())
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())
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())
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)
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)
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())
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")
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")
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")