Best Python code snippet using autotest_python
test_event_manager.py
Source:test_event_manager.py
...42 encode = stack.enter_context(mock.patch.object(base64, "b64encode"))43 encode.return_value.decode = mock.Mock(return_value="nonce")44 with stack:45 assert event_manager_._fixed_size_nonce() == "nonce"46 monotonic.assert_called_once_with()47 monotonic.return_value.to_bytes.assert_called_once_with(8, "big")48 randbits.assert_called_once_with(92)49 randbits.return_value.to_bytes.assert_called_once_with(12, "big")50 encode.assert_called_once_with("foobar")51 encode.return_value.decode.assert_called_once_with("ascii")52@pytest.fixture()53def shard():54 return mock.Mock(id=987)55@pytest.mark.asyncio()56async def test__request_guild_members(shard):57 shard.request_guild_members = mock.AsyncMock()58 await event_manager_._request_guild_members(shard, 123, include_presences=True, nonce="okokok")59 shard.request_guild_members.assert_awaited_once_with(123, include_presences=True, nonce="okokok")60@pytest.mark.asyncio()61async def test__request_guild_members_handles_state_conflict_error(shard):62 shard.request_guild_members = mock.AsyncMock(side_effect=errors.ComponentStateConflictError(reason="OK"))63 await event_manager_._request_guild_members(shard, 123, include_presences=True, nonce="okokok")64 shard.request_guild_members.assert_awaited_once_with(123, include_presences=True, nonce="okokok")65class TestEventManagerImpl:66 @pytest.fixture()67 def event_factory(self):68 return mock.Mock()69 @pytest.fixture()70 def event_manager(self, event_factory):71 obj = hikari_test_helpers.mock_class_namespace(event_manager_.EventManagerImpl, slots_=False)(72 event_factory, intents.Intents.ALL, cache=mock.Mock()73 )74 obj.dispatch = mock.AsyncMock()75 return obj76 @pytest.fixture()77 def stateless_event_manager(self, event_factory):78 obj = hikari_test_helpers.mock_class_namespace(event_manager_.EventManagerImpl, slots_=False)(79 event_factory, intents.Intents.ALL, cache=None80 )81 obj.dispatch = mock.AsyncMock()82 return obj83 @pytest.mark.asyncio()84 async def test_on_ready_stateful(self, event_manager, shard, event_factory):85 payload = {}86 event = mock.Mock(my_user=mock.Mock())87 event_factory.deserialize_ready_event.return_value = event88 await event_manager.on_ready(shard, payload)89 event_manager._cache.update_me.assert_called_once_with(event.my_user)90 event_factory.deserialize_ready_event.assert_called_once_with(shard, payload)91 event_manager.dispatch.assert_awaited_once_with(event)92 @pytest.mark.asyncio()93 async def test_on_ready_stateless(self, stateless_event_manager, shard, event_factory):94 payload = {}95 await stateless_event_manager.on_ready(shard, payload)96 event_factory.deserialize_ready_event.assert_called_once_with(shard, payload)97 stateless_event_manager.dispatch.assert_awaited_once_with(event_factory.deserialize_ready_event.return_value)98 @pytest.mark.asyncio()99 async def test_on_resumed(self, event_manager, shard, event_factory):100 payload = {}101 await event_manager.on_resumed(shard, payload)102 event_factory.deserialize_resumed_event.assert_called_once_with(shard)103 event_manager.dispatch.assert_awaited_once_with(event_factory.deserialize_resumed_event.return_value)104 @pytest.mark.asyncio()105 async def test_on_channel_create_stateful(self, event_manager, shard, event_factory):106 payload = {}107 event = mock.Mock(channel=mock.Mock(channels.GuildChannel))108 event_factory.deserialize_guild_channel_create_event.return_value = event109 await event_manager.on_channel_create(shard, payload)110 event_manager._cache.set_guild_channel.assert_called_once_with(event.channel)111 event_factory.deserialize_guild_channel_create_event.assert_called_once_with(shard, payload)112 event_manager.dispatch.assert_awaited_once_with(event)113 @pytest.mark.asyncio()114 async def test_on_channel_create_stateless(self, stateless_event_manager, shard, event_factory):115 payload = {}116 await stateless_event_manager.on_channel_create(shard, payload)117 event_factory.deserialize_guild_channel_create_event.assert_called_once_with(shard, payload)118 stateless_event_manager.dispatch.assert_awaited_once_with(119 event_factory.deserialize_guild_channel_create_event.return_value120 )121 @pytest.mark.asyncio()122 async def test_on_channel_update_stateful(self, event_manager, shard, event_factory):123 payload = {"id": 123}124 old_channel = object()125 event = mock.Mock(channel=mock.Mock(channels.GuildChannel))126 event_factory.deserialize_guild_channel_update_event.return_value = event127 event_manager._cache.get_guild_channel.return_value = old_channel128 await event_manager.on_channel_update(shard, payload)129 event_manager._cache.get_guild_channel.assert_called_once_with(123)130 event_manager._cache.update_guild_channel.assert_called_once_with(event.channel)131 event_factory.deserialize_guild_channel_update_event.assert_called_once_with(132 shard, payload, old_channel=old_channel133 )134 event_manager.dispatch.assert_awaited_once_with(event)135 @pytest.mark.asyncio()136 async def test_on_channel_update_stateless(self, stateless_event_manager, shard, event_factory):137 payload = {"id": 123}138 await stateless_event_manager.on_channel_update(shard, payload)139 event_factory.deserialize_guild_channel_update_event.assert_called_once_with(shard, payload, old_channel=None)140 stateless_event_manager.dispatch.assert_awaited_once_with(141 event_factory.deserialize_guild_channel_update_event.return_value142 )143 @pytest.mark.asyncio()144 async def test_on_channel_delete_stateful(self, event_manager, shard, event_factory):145 payload = {}146 event = mock.Mock(channel=mock.Mock(id=123))147 event_factory.deserialize_guild_channel_delete_event.return_value = event148 await event_manager.on_channel_delete(shard, payload)149 event_manager._cache.delete_guild_channel.assert_called_once_with(123)150 event_factory.deserialize_guild_channel_delete_event.assert_called_once_with(shard, payload)151 event_manager.dispatch.assert_awaited_once_with(event)152 @pytest.mark.asyncio()153 async def test_on_channel_delete_stateless(self, stateless_event_manager, shard, event_factory):154 payload = {}155 await stateless_event_manager.on_channel_delete(shard, payload)156 event_factory.deserialize_guild_channel_delete_event.assert_called_once_with(shard, payload)157 stateless_event_manager.dispatch.assert_awaited_once_with(158 event_factory.deserialize_guild_channel_delete_event.return_value159 )160 @pytest.mark.asyncio()161 async def test_on_channel_pins_update(self, stateless_event_manager, shard, event_factory):162 payload = {}163 event = mock.Mock()164 event_factory.deserialize_channel_pins_update_event.return_value = event165 await stateless_event_manager.on_channel_pins_update(shard, payload)166 event_factory.deserialize_channel_pins_update_event.assert_called_once_with(shard, payload)167 stateless_event_manager.dispatch.assert_awaited_once_with(event)168 @pytest.mark.asyncio()169 async def test_on_guild_create_stateful_with_unavailable_field(self, event_manager, shard, event_factory):170 payload = {"unavailable": False}171 event = mock.Mock(172 guild=mock.Mock(id=123, is_large=False),173 channels={"TestChannel": 456},174 emojis={"TestEmoji": 789},175 roles={"TestRole": 1234},176 members={"TestMember": 5678},177 presences={"TestPresence": 9012},178 voice_states={"TestState": 345},179 chunk_nonce=None,180 )181 event_factory.deserialize_guild_available_event.return_value = event182 shard.request_guild_members = mock.AsyncMock()183 await event_manager.on_guild_create(shard, payload)184 assert event.chunk_nonce is None185 shard.request_guild_members.assert_not_called()186 event_manager._cache.update_guild.assert_called_once_with(event.guild)187 event_manager._cache.clear_guild_channels_for_guild.assert_called_once_with(123)188 event_manager._cache.set_guild_channel.assert_called_once_with(456)189 event_manager._cache.clear_emojis_for_guild.assert_called_once_with(123)190 event_manager._cache.set_emoji.assert_called_once_with(789)191 event_manager._cache.clear_roles_for_guild.assert_called_once_with(123)192 event_manager._cache.set_role.assert_called_once_with(1234)193 event_manager._cache.clear_members_for_guild.assert_called_once_with(123)194 event_manager._cache.set_member.assert_called_once_with(5678)195 event_manager._cache.clear_presences_for_guild.assert_called_once_with(123)196 event_manager._cache.set_presence.assert_called_once_with(9012)197 event_manager._cache.clear_voice_states_for_guild.assert_called_once_with(123)198 event_manager._cache.set_voice_state.assert_called_once_with(345)199 event_factory.deserialize_guild_available_event.assert_called_once_with(shard, payload)200 event_manager.dispatch.assert_awaited_once_with(event)201 @pytest.mark.asyncio()202 async def test_on_guild_create_stateful_without_unavailable_field(self, event_manager, shard, event_factory):203 payload = {}204 event = mock.Mock(205 guild=mock.Mock(id=123, is_large=False),206 channels={"TestChannel": 456},207 emojis={"TestEmoji": 789},208 roles={"TestRole": 1234},209 members={"TestMember": 5678},210 presences={"TestPresence": 9012},211 voice_states={"TestState": 345},212 chunk_nonce=None,213 )214 event_factory.deserialize_guild_join_event.return_value = event215 shard.request_guild_members = mock.AsyncMock()216 await event_manager.on_guild_create(shard, payload)217 assert event.chunk_nonce is None218 shard.request_guild_members.assert_not_called()219 event_manager._cache.update_guild.assert_called_once_with(event.guild)220 event_manager._cache.clear_guild_channels_for_guild.assert_called_once_with(123)221 event_manager._cache.set_guild_channel.assert_called_once_with(456)222 event_manager._cache.clear_emojis_for_guild.assert_called_once_with(123)223 event_manager._cache.set_emoji.assert_called_once_with(789)224 event_manager._cache.clear_roles_for_guild.assert_called_once_with(123)225 event_manager._cache.set_role.assert_called_once_with(1234)226 event_manager._cache.clear_members_for_guild.assert_called_once_with(123)227 event_manager._cache.set_member.assert_called_once_with(5678)228 event_manager._cache.clear_presences_for_guild.assert_called_once_with(123)229 event_manager._cache.set_presence.assert_called_once_with(9012)230 event_manager._cache.clear_voice_states_for_guild.assert_called_once_with(123)231 event_manager._cache.set_voice_state.assert_called_once_with(345)232 event_factory.deserialize_guild_join_event.assert_called_once_with(shard, payload)233 event_manager.dispatch.assert_awaited_once_with(event)234 @pytest.mark.asyncio()235 async def test_on_guild_create_when_request_chunks_with_unavailable_field(236 self, event_manager, shard, event_factory237 ):238 payload = {"unavailable": False}239 event = mock.Mock(240 guild=mock.Mock(id=123, is_large=True),241 channels={"TestChannel": 456},242 emojis={"TestEmoji": 789},243 roles={"TestRole": 1234},244 members={"TestMember": 5678},245 presences={"TestPresence": 9012},246 voice_states={"TestState": 345},247 chunk_nonce=None,248 )249 event_factory.deserialize_guild_available_event.return_value = event250 shard.request_guild_members = mock.Mock()251 stack = contextlib.ExitStack()252 create_task = stack.enter_context(mock.patch.object(asyncio, "create_task"))253 uuid = stack.enter_context(mock.patch("hikari.impl.event_manager._fixed_size_nonce", return_value="uuid"))254 _request_guild_members = stack.enter_context(255 mock.patch("hikari.impl.event_manager._request_guild_members", new_callable=mock.Mock)256 )257 with stack:258 await event_manager.on_guild_create(shard, payload)259 uuid.assert_called_once_with()260 nonce = "987.uuid"261 assert event.chunk_nonce == nonce262 _request_guild_members.assert_called_once_with(shard, event.guild, include_presences=True, nonce=nonce)263 create_task.assert_called_once_with(264 _request_guild_members.return_value, name="987:123 guild create members request"265 )266 event_manager._cache.update_guild.assert_called_once_with(event.guild)267 event_manager._cache.clear_guild_channels_for_guild.assert_called_once_with(123)268 event_manager._cache.set_guild_channel.assert_called_once_with(456)269 event_manager._cache.clear_emojis_for_guild.assert_called_once_with(123)270 event_manager._cache.set_emoji.assert_called_once_with(789)271 event_manager._cache.clear_roles_for_guild.assert_called_once_with(123)272 event_manager._cache.set_role.assert_called_once_with(1234)273 event_manager._cache.clear_members_for_guild.assert_called_once_with(123)274 event_manager._cache.set_member.assert_called_once_with(5678)275 event_manager._cache.clear_presences_for_guild.assert_called_once_with(123)276 event_manager._cache.set_presence.assert_called_once_with(9012)277 event_manager._cache.clear_voice_states_for_guild.assert_called_once_with(123)278 event_manager._cache.set_voice_state.assert_called_once_with(345)279 event_factory.deserialize_guild_available_event.assert_called_once_with(shard, payload)280 event_manager.dispatch.assert_awaited_once_with(event)281 @pytest.mark.asyncio()282 async def test_on_guild_create_when_request_chunks_without_unavailable_field(283 self, event_manager, shard, event_factory284 ):285 payload = {}286 event = mock.Mock(287 guild=mock.Mock(id=123, is_large=True),288 channels={"TestChannel": 456},289 emojis={"TestEmoji": 789},290 roles={"TestRole": 1234},291 members={"TestMember": 5678},292 presences={"TestPresence": 9012},293 voice_states={"TestState": 345},294 chunk_nonce=None,295 )296 event_factory.deserialize_guild_join_event.return_value = event297 shard.request_guild_members = mock.Mock()298 stack = contextlib.ExitStack()299 create_task = stack.enter_context(mock.patch.object(asyncio, "create_task"))300 uuid = stack.enter_context(mock.patch("hikari.impl.event_manager._fixed_size_nonce", return_value="uuid"))301 _request_guild_members = stack.enter_context(302 mock.patch("hikari.impl.event_manager._request_guild_members", new_callable=mock.Mock)303 )304 with stack:305 await event_manager.on_guild_create(shard, payload)306 uuid.assert_called_once_with()307 nonce = "987.uuid"308 assert event.chunk_nonce == nonce309 _request_guild_members.assert_called_once_with(shard, event.guild, include_presences=True, nonce=nonce)310 create_task.assert_called_once_with(311 _request_guild_members.return_value, name="987:123 guild create members request"312 )313 event_manager._cache.update_guild.assert_called_once_with(event.guild)314 event_manager._cache.clear_guild_channels_for_guild.assert_called_once_with(123)315 event_manager._cache.set_guild_channel.assert_called_once_with(456)316 event_manager._cache.clear_emojis_for_guild.assert_called_once_with(123)317 event_manager._cache.set_emoji.assert_called_once_with(789)318 event_manager._cache.clear_roles_for_guild.assert_called_once_with(123)319 event_manager._cache.set_role.assert_called_once_with(1234)320 event_manager._cache.clear_members_for_guild.assert_called_once_with(123)321 event_manager._cache.set_member.assert_called_once_with(5678)322 event_manager._cache.clear_presences_for_guild.assert_called_once_with(123)323 event_manager._cache.set_presence.assert_called_once_with(9012)324 event_manager._cache.clear_voice_states_for_guild.assert_called_once_with(123)325 event_manager._cache.set_voice_state.assert_called_once_with(345)326 event_factory.deserialize_guild_join_event.assert_called_once_with(shard, payload)327 event_manager.dispatch.assert_awaited_once_with(event)328 @pytest.mark.asyncio()329 async def test_on_guild_create_stateless_with_unavailable_field(330 self, stateless_event_manager, shard, event_factory331 ):332 payload = {"unavailable": False}333 shard.request_guild_members = mock.AsyncMock()334 await stateless_event_manager.on_guild_create(shard, payload)335 event_factory.deserialize_guild_available_event.assert_called_once_with(shard, payload)336 stateless_event_manager.dispatch.assert_awaited_once_with(337 event_factory.deserialize_guild_available_event.return_value338 )339 @pytest.mark.asyncio()340 async def test_on_guild_create_stateless_without_unavailable_field(341 self, stateless_event_manager, shard, event_factory342 ):343 payload = {}344 shard.request_guild_members = mock.AsyncMock()345 await stateless_event_manager.on_guild_create(shard, payload)346 event_factory.deserialize_guild_join_event.assert_called_once_with(shard, payload)347 stateless_event_manager.dispatch.assert_awaited_once_with(348 event_factory.deserialize_guild_join_event.return_value349 )350 @pytest.mark.asyncio()351 async def test_on_guild_update_stateful(self, event_manager, shard, event_factory):352 payload = {"id": 123}353 old_guild = object()354 mock_role = object()355 mock_emoji = object()356 event = mock.Mock(roles={555: mock_role}, emojis={333: mock_emoji}, guild=mock.Mock(id=123))357 event_factory.deserialize_guild_update_event.return_value = event358 event_manager._cache.get_guild.return_value = old_guild359 await event_manager.on_guild_update(shard, payload)360 event_manager._cache.get_guild.assert_called_once_with(123)361 event_manager._cache.update_guild.assert_called_once_with(event.guild)362 event_manager._cache.clear_roles_for_guild.assert_called_once_with(123)363 event_manager._cache.set_role.assert_called_once_with(mock_role)364 event_manager._cache.clear_emojis_for_guild.assert_called_once_with(123)365 event_manager._cache.set_emoji.assert_called_once_with(mock_emoji)366 event_factory.deserialize_guild_update_event.assert_called_once_with(shard, payload, old_guild=old_guild)367 event_manager.dispatch.assert_awaited_once_with(event)368 @pytest.mark.asyncio()369 async def test_on_guild_update_stateless(self, stateless_event_manager, shard, event_factory):370 payload = {"id": 123}371 await stateless_event_manager.on_guild_update(shard, payload)372 event_factory.deserialize_guild_update_event.assert_called_once_with(shard, payload, old_guild=None)373 stateless_event_manager.dispatch.assert_awaited_once_with(374 event_factory.deserialize_guild_update_event.return_value375 )376 @pytest.mark.asyncio()377 async def test_on_guild_delete_stateful_when_available(self, event_manager, shard, event_factory):378 payload = {"unavailable": False, "id": "123"}379 event = mock.Mock(guild_id=123)380 event_factory.deserialize_guild_leave_event.return_value = event381 await event_manager.on_guild_delete(shard, payload)382 event_manager._cache.delete_guild.assert_called_once_with(123)383 event_manager._cache.clear_voice_states_for_guild.assert_called_once_with(123)384 event_manager._cache.clear_invites_for_guild.assert_called_once_with(123)385 event_manager._cache.clear_members_for_guild.assert_called_once_with(123)386 event_manager._cache.clear_presences_for_guild.assert_called_once_with(123)387 event_manager._cache.clear_guild_channels_for_guild.assert_called_once_with(123)388 event_manager._cache.clear_emojis_for_guild.assert_called_once_with(123)389 event_manager._cache.clear_roles_for_guild.assert_called_once_with(123)390 event_factory.deserialize_guild_leave_event.assert_called_once_with(391 shard, payload, old_guild=event_manager._cache.delete_guild.return_value392 )393 event_manager.dispatch.assert_awaited_once_with(event)394 @pytest.mark.asyncio()395 async def test_on_guild_delete_stateful_when_unavailable(self, event_manager, shard, event_factory):396 payload = {"unavailable": True, "id": "123"}397 event = mock.Mock(guild_id=123)398 event_factory.deserialize_guild_unavailable_event.return_value = event399 await event_manager.on_guild_delete(shard, payload)400 event_manager._cache.set_guild_availability.assert_called_once_with(event.guild_id, False)401 event_factory.deserialize_guild_unavailable_event.assert_called_once_with(shard, payload)402 event_manager.dispatch.assert_awaited_once_with(event)403 @pytest.mark.asyncio()404 async def test_on_guild_delete_stateless_when_available(self, stateless_event_manager, shard, event_factory):405 payload = {"unavailable": False, "id": "123"}406 await stateless_event_manager.on_guild_delete(shard, payload)407 event_factory.deserialize_guild_leave_event.assert_called_once_with(shard, payload, old_guild=None)408 stateless_event_manager.dispatch.assert_awaited_once_with(409 event_factory.deserialize_guild_leave_event.return_value410 )411 @pytest.mark.asyncio()412 async def test_on_guild_delete_stateless_when_unavailable(self, stateless_event_manager, shard, event_factory):413 payload = {"unavailable": True}414 await stateless_event_manager.on_guild_delete(shard, payload)415 event_factory.deserialize_guild_unavailable_event.assert_called_once_with(shard, payload)416 stateless_event_manager.dispatch.assert_awaited_once_with(417 event_factory.deserialize_guild_unavailable_event.return_value418 )419 @pytest.mark.asyncio()420 async def test_on_guild_ban_add(self, event_manager, shard, event_factory):421 payload = {}422 event = mock.Mock()423 event_factory.deserialize_guild_ban_add_event.return_value = event424 await event_manager.on_guild_ban_add(shard, payload)425 event_factory.deserialize_guild_ban_add_event.assert_called_once_with(shard, payload)426 event_manager.dispatch.assert_awaited_once_with(event)427 @pytest.mark.asyncio()428 async def test_on_guild_ban_remove(self, event_manager, shard, event_factory):429 payload = {}430 event = mock.Mock()431 event_factory.deserialize_guild_ban_remove_event.return_value = event432 await event_manager.on_guild_ban_remove(shard, payload)433 event_factory.deserialize_guild_ban_remove_event.assert_called_once_with(shard, payload)434 event_manager.dispatch.assert_awaited_once_with(event)435 @pytest.mark.asyncio()436 async def test_on_guild_emojis_update_stateful(self, event_manager, shard, event_factory):437 payload = {"guild_id": 123}438 old_emojis = {"Test": 123}439 mock_emoji = object()440 event = mock.Mock(emojis=[mock_emoji], guild_id=123)441 event_factory.deserialize_guild_emojis_update_event.return_value = event442 event_manager._cache.clear_emojis_for_guild.return_value = old_emojis443 await event_manager.on_guild_emojis_update(shard, payload)444 event_manager._cache.clear_emojis_for_guild.assert_called_once_with(123)445 event_manager._cache.set_emoji.assert_called_once_with(mock_emoji)446 event_factory.deserialize_guild_emojis_update_event.assert_called_once_with(shard, payload, old_emojis=[123])447 event_manager.dispatch.assert_awaited_once_with(event)448 @pytest.mark.asyncio()449 async def test_on_guild_emojis_update_stateless(self, stateless_event_manager, shard, event_factory):450 payload = {"guild_id": 123}451 await stateless_event_manager.on_guild_emojis_update(shard, payload)452 event_factory.deserialize_guild_emojis_update_event.assert_called_once_with(shard, payload, old_emojis=None)453 stateless_event_manager.dispatch.assert_awaited_once_with(454 event_factory.deserialize_guild_emojis_update_event.return_value455 )456 @pytest.mark.asyncio()457 async def test_on_guild_integrations_update(self, event_manager, shard):458 assert await event_manager.on_guild_integrations_update(shard, {}) is None459 event_manager.dispatch.assert_not_called()460 @pytest.mark.asyncio()461 async def test_on_integration_create(self, event_manager, shard, event_factory):462 payload = {}463 event = mock.Mock()464 event_factory.deserialize_integration_create_event.return_value = event465 await event_manager.on_integration_create(shard, payload)466 event_factory.deserialize_integration_create_event.assert_called_once_with(shard, payload)467 event_manager.dispatch.assert_awaited_once_with(event)468 @pytest.mark.asyncio()469 async def test_on_integration_delete(self, event_manager, shard, event_factory):470 payload = {}471 event = mock.Mock()472 event_factory.deserialize_integration_delete_event.return_value = event473 await event_manager.on_integration_delete(shard, payload)474 event_factory.deserialize_integration_delete_event.assert_called_once_with(shard, payload)475 event_manager.dispatch.assert_awaited_once_with(event)476 @pytest.mark.asyncio()477 async def test_on_integration_update(self, event_manager, shard, event_factory):478 payload = {}479 event = mock.Mock()480 event_factory.deserialize_integration_update_event.return_value = event481 await event_manager.on_integration_update(shard, payload)482 event_factory.deserialize_integration_update_event.assert_called_once_with(shard, payload)483 event_manager.dispatch.assert_awaited_once_with(event)484 @pytest.mark.asyncio()485 async def test_on_guild_member_add_stateful(self, event_manager, shard, event_factory):486 payload = {}487 event = mock.Mock(user=object(), member=object())488 event_factory.deserialize_guild_member_add_event.return_value = event489 await event_manager.on_guild_member_add(shard, payload)490 event_manager._cache.update_member.assert_called_once_with(event.member)491 event_factory.deserialize_guild_member_add_event.assert_called_once_with(shard, payload)492 event_manager.dispatch.assert_awaited_once_with(event)493 @pytest.mark.asyncio()494 async def test_on_guild_member_add_stateless(self, stateless_event_manager, shard, event_factory):495 payload = {}496 await stateless_event_manager.on_guild_member_add(shard, payload)497 event_factory.deserialize_guild_member_add_event.assert_called_once_with(shard, payload)498 stateless_event_manager.dispatch.assert_awaited_once_with(499 event_factory.deserialize_guild_member_add_event.return_value500 )501 @pytest.mark.asyncio()502 async def test_on_guild_member_remove_stateful(self, event_manager, shard, event_factory):503 payload = {"guild_id": "456", "user": {"id": "123"}}504 await event_manager.on_guild_member_remove(shard, payload)505 event_manager._cache.delete_member.assert_called_once_with(456, 123)506 event_factory.deserialize_guild_member_remove_event.assert_called_once_with(507 shard, payload, old_member=event_manager._cache.delete_member.return_value508 )509 event_manager.dispatch.assert_awaited_once_with(510 event_factory.deserialize_guild_member_remove_event.return_value511 )512 @pytest.mark.asyncio()513 async def test_on_guild_member_remove_stateless(self, stateless_event_manager, shard, event_factory):514 payload = {}515 await stateless_event_manager.on_guild_member_remove(shard, payload)516 event_factory.deserialize_guild_member_remove_event.assert_called_once_with(shard, payload, old_member=None)517 stateless_event_manager.dispatch.assert_awaited_once_with(518 event_factory.deserialize_guild_member_remove_event.return_value519 )520 @pytest.mark.asyncio()521 async def test_on_guild_member_update_stateful(self, event_manager, shard, event_factory):522 payload = {"user": {"id": 123}, "guild_id": 456}523 old_member = object()524 event = mock.Mock(member=mock.Mock())525 event_factory.deserialize_guild_member_update_event.return_value = event526 event_manager._cache.get_member.return_value = old_member527 await event_manager.on_guild_member_update(shard, payload)528 event_manager._cache.get_member.assert_called_once_with(456, 123)529 event_manager._cache.update_member.assert_called_once_with(event.member)530 event_factory.deserialize_guild_member_update_event.assert_called_once_with(531 shard, payload, old_member=old_member532 )533 event_manager.dispatch.assert_awaited_once_with(event)534 @pytest.mark.asyncio()535 async def test_on_guild_member_update_stateless(self, stateless_event_manager, shard, event_factory):536 payload = {"user": {"id": 123}, "guild_id": 456}537 await stateless_event_manager.on_guild_member_update(shard, payload)538 event_factory.deserialize_guild_member_update_event.assert_called_once_with(shard, payload, old_member=None)539 stateless_event_manager.dispatch.assert_awaited_once_with(540 event_factory.deserialize_guild_member_update_event.return_value541 )542 @pytest.mark.asyncio()543 async def test_on_guild_members_chunk_stateful(self, event_manager, shard, event_factory):544 payload = {}545 event = mock.Mock(members={"TestMember": 123}, presences={"TestPresences": 456})546 event_factory.deserialize_guild_member_chunk_event.return_value = event547 await event_manager.on_guild_members_chunk(shard, payload)548 event_manager._cache.set_member.assert_called_once_with(123)549 event_manager._cache.set_presence.assert_called_once_with(456)550 event_factory.deserialize_guild_member_chunk_event.assert_called_once_with(shard, payload)551 event_manager.dispatch.assert_awaited_once_with(event)552 @pytest.mark.asyncio()553 async def test_on_guild_members_chunk_stateless(self, stateless_event_manager, shard, event_factory):554 payload = {}555 await stateless_event_manager.on_guild_members_chunk(shard, payload)556 event_factory.deserialize_guild_member_chunk_event.assert_called_once_with(shard, payload)557 stateless_event_manager.dispatch.assert_awaited_once_with(558 event_factory.deserialize_guild_member_chunk_event.return_value559 )560 @pytest.mark.asyncio()561 async def test_on_guild_role_create_stateful(self, event_manager, shard, event_factory):562 payload = {}563 event = mock.Mock(role=object())564 event_factory.deserialize_guild_role_create_event.return_value = event565 await event_manager.on_guild_role_create(shard, payload)566 event_manager._cache.set_role.assert_called_once_with(event.role)567 event_factory.deserialize_guild_role_create_event.assert_called_once_with(shard, payload)568 event_manager.dispatch.assert_awaited_once_with(event)569 @pytest.mark.asyncio()570 async def test_on_guild_role_create_stateless(self, stateless_event_manager, shard, event_factory):571 payload = {}572 await stateless_event_manager.on_guild_role_create(shard, payload)573 event_factory.deserialize_guild_role_create_event.assert_called_once_with(shard, payload)574 stateless_event_manager.dispatch.assert_awaited_once_with(575 event_factory.deserialize_guild_role_create_event.return_value576 )577 @pytest.mark.asyncio()578 async def test_on_guild_role_update_stateful(self, event_manager, shard, event_factory):579 payload = {"role": {"id": 123}}580 old_role = object()581 event = mock.Mock(role=mock.Mock())582 event_factory.deserialize_guild_role_update_event.return_value = event583 event_manager._cache.get_role.return_value = old_role584 await event_manager.on_guild_role_update(shard, payload)585 event_manager._cache.get_role.assert_called_once_with(123)586 event_manager._cache.update_role.assert_called_once_with(event.role)587 event_factory.deserialize_guild_role_update_event.assert_called_once_with(shard, payload, old_role=old_role)588 event_manager.dispatch.assert_awaited_once_with(event)589 @pytest.mark.asyncio()590 async def test_on_guild_role_update_stateless(self, stateless_event_manager, shard, event_factory):591 payload = {"role": {"id": 123}}592 await stateless_event_manager.on_guild_role_update(shard, payload)593 event_factory.deserialize_guild_role_update_event.assert_called_once_with(shard, payload, old_role=None)594 stateless_event_manager.dispatch.assert_awaited_once_with(595 event_factory.deserialize_guild_role_update_event.return_value596 )597 @pytest.mark.asyncio()598 async def test_on_guild_role_delete_stateful(self, event_manager, shard, event_factory):599 payload = {"role_id": "123"}600 await event_manager.on_guild_role_delete(shard, payload)601 event_manager._cache.delete_role.assert_called_once_with(123)602 event_factory.deserialize_guild_role_delete_event.assert_called_once_with(603 shard, payload, old_role=event_manager._cache.delete_role.return_value604 )605 event_manager.dispatch.assert_awaited_once_with(event_factory.deserialize_guild_role_delete_event.return_value)606 @pytest.mark.asyncio()607 async def test_on_guild_role_delete_stateless(self, stateless_event_manager, shard, event_factory):608 payload = {}609 await stateless_event_manager.on_guild_role_delete(shard, payload)610 event_factory.deserialize_guild_role_delete_event.assert_called_once_with(shard, payload, old_role=None)611 stateless_event_manager.dispatch.assert_awaited_once_with(612 event_factory.deserialize_guild_role_delete_event.return_value613 )614 @pytest.mark.asyncio()615 async def test_on_invite_create_stateful(self, event_manager, shard, event_factory):616 payload = {}617 event = mock.Mock(invite="qwerty")618 event_factory.deserialize_invite_create_event.return_value = event619 await event_manager.on_invite_create(shard, payload)620 event_manager._cache.set_invite.assert_called_once_with("qwerty")621 event_factory.deserialize_invite_create_event.assert_called_once_with(shard, payload)622 event_manager.dispatch.assert_awaited_once_with(event)623 @pytest.mark.asyncio()624 async def test_on_invite_create_stateless(self, stateless_event_manager, shard, event_factory):625 payload = {}626 await stateless_event_manager.on_invite_create(shard, payload)627 event_factory.deserialize_invite_create_event.assert_called_once_with(shard, payload)628 stateless_event_manager.dispatch.assert_awaited_once_with(629 event_factory.deserialize_invite_create_event.return_value630 )631 @pytest.mark.asyncio()632 async def test_on_invite_delete_stateful(self, event_manager, shard, event_factory):633 payload = {"code": "qwerty"}634 await event_manager.on_invite_delete(shard, payload)635 event_manager._cache.delete_invite.assert_called_once_with("qwerty")636 event_factory.deserialize_invite_delete_event.assert_called_once_with(637 shard, payload, old_invite=event_manager._cache.delete_invite.return_value638 )639 event_manager.dispatch.assert_awaited_once_with(event_factory.deserialize_invite_delete_event.return_value)640 @pytest.mark.asyncio()641 async def test_on_invite_delete_stateless(self, stateless_event_manager, shard, event_factory):642 payload = {}643 await stateless_event_manager.on_invite_delete(shard, payload)644 event_factory.deserialize_invite_delete_event.assert_called_once_with(shard, payload, old_invite=None)645 stateless_event_manager.dispatch.assert_awaited_once_with(646 event_factory.deserialize_invite_delete_event.return_value647 )648 @pytest.mark.asyncio()649 async def test_on_message_create_stateful(self, event_manager, shard, event_factory):650 payload = {}651 event = mock.Mock(message=object())652 event_factory.deserialize_message_create_event.return_value = event653 await event_manager.on_message_create(shard, payload)654 event_manager._cache.set_message.assert_called_once_with(event.message)655 event_factory.deserialize_message_create_event.assert_called_once_with(shard, payload)656 event_manager.dispatch.assert_awaited_once_with(event)657 @pytest.mark.asyncio()658 async def test_on_message_create_stateless(self, stateless_event_manager, shard, event_factory):659 payload = {}660 await stateless_event_manager.on_message_create(shard, payload)661 event_factory.deserialize_message_create_event.assert_called_once_with(shard, payload)662 stateless_event_manager.dispatch.assert_awaited_once_with(663 event_factory.deserialize_message_create_event.return_value664 )665 @pytest.mark.asyncio()666 async def test_on_message_update_stateful(self, event_manager, shard, event_factory):667 payload = {"id": 123}668 old_message = object()669 event = mock.Mock(message=mock.Mock())670 event_factory.deserialize_message_update_event.return_value = event671 event_manager._cache.get_message.return_value = old_message672 await event_manager.on_message_update(shard, payload)673 event_manager._cache.get_message.assert_called_once_with(123)674 event_manager._cache.update_message.assert_called_once_with(event.message)675 event_factory.deserialize_message_update_event.assert_called_once_with(shard, payload, old_message=old_message)676 event_manager.dispatch.assert_awaited_once_with(event)677 @pytest.mark.asyncio()678 async def test_on_message_update_stateless(self, stateless_event_manager, shard, event_factory):679 payload = {"id": 123}680 await stateless_event_manager.on_message_update(shard, payload)681 event_factory.deserialize_message_update_event.assert_called_once_with(shard, payload, old_message=None)682 stateless_event_manager.dispatch.assert_awaited_once_with(683 event_factory.deserialize_message_update_event.return_value684 )685 @pytest.mark.asyncio()686 async def test_on_message_delete_stateful(self, event_manager, shard, event_factory):687 payload = {"id": 123}688 await event_manager.on_message_delete(shard, payload)689 event_manager._cache.delete_message.assert_called_once_with(123)690 event_factory.deserialize_message_delete_event.assert_called_once_with(691 shard, payload, old_message=event_manager._cache.delete_message.return_value692 )693 event_manager.dispatch.assert_awaited_once_with(event_factory.deserialize_message_delete_event.return_value)694 @pytest.mark.asyncio()695 async def test_on_message_delete_stateless(self, stateless_event_manager, shard, event_factory):696 payload = {}697 await stateless_event_manager.on_message_delete(shard, payload)698 event_factory.deserialize_message_delete_event.assert_called_once_with(shard, payload, old_message=None)699 stateless_event_manager.dispatch.assert_awaited_once_with(700 event_factory.deserialize_message_delete_event.return_value701 )702 @pytest.mark.asyncio()703 async def test_on_message_delete_bulk_stateful(self, event_manager, shard, event_factory):704 payload = {"ids": [123, 456, 789]}705 message1 = object()706 message2 = object()707 message3 = object()708 event_manager._cache.delete_message.side_effect = [message1, message2, message3]709 await event_manager.on_message_delete_bulk(shard, payload)710 event_manager._cache.delete_message.assert_has_calls([mock.call(123), mock.call(456), mock.call(789)])711 event_factory.deserialize_guild_message_delete_bulk_event.assert_called_once_with(712 shard, payload, old_messages={123: message1, 456: message2, 789: message3}713 )714 event_manager.dispatch.assert_awaited_once_with(715 event_factory.deserialize_guild_message_delete_bulk_event.return_value716 )717 @pytest.mark.asyncio()718 async def test_on_message_delete_bulk_stateless(self, stateless_event_manager, shard, event_factory):719 payload = {}720 await stateless_event_manager.on_message_delete_bulk(shard, payload)721 event_factory.deserialize_guild_message_delete_bulk_event.assert_called_once_with(722 shard, payload, old_messages={}723 )724 stateless_event_manager.dispatch.assert_awaited_once_with(725 event_factory.deserialize_guild_message_delete_bulk_event.return_value726 )727 @pytest.mark.asyncio()728 async def test_on_message_reaction_add(self, event_manager, shard, event_factory):729 payload = {}730 event = mock.Mock()731 event_factory.deserialize_message_reaction_add_event.return_value = event732 await event_manager.on_message_reaction_add(shard, payload)733 event_factory.deserialize_message_reaction_add_event.assert_called_once_with(shard, payload)734 event_manager.dispatch.assert_awaited_once_with(event)735 @pytest.mark.asyncio()736 async def test_on_message_reaction_remove(self, event_manager, shard, event_factory):737 payload = {}738 event = mock.Mock()739 event_factory.deserialize_message_reaction_remove_event.return_value = event740 await event_manager.on_message_reaction_remove(shard, payload)741 event_factory.deserialize_message_reaction_remove_event.assert_called_once_with(shard, payload)742 event_manager.dispatch.assert_awaited_once_with(event)743 @pytest.mark.asyncio()744 async def test_on_message_reaction_remove_all(self, event_manager, shard, event_factory):745 payload = {}746 event = mock.Mock()747 event_factory.deserialize_message_reaction_remove_all_event.return_value = event748 await event_manager.on_message_reaction_remove_all(shard, payload)749 event_factory.deserialize_message_reaction_remove_all_event.assert_called_once_with(shard, payload)750 event_manager.dispatch.assert_awaited_once_with(event)751 @pytest.mark.asyncio()752 async def test_on_message_reaction_remove_emoji(self, event_manager, shard, event_factory):753 payload = {}754 event = mock.Mock()755 event_factory.deserialize_message_reaction_remove_emoji_event.return_value = event756 await event_manager.on_message_reaction_remove_emoji(shard, payload)757 event_factory.deserialize_message_reaction_remove_emoji_event.assert_called_once_with(shard, payload)758 event_manager.dispatch.assert_awaited_once_with(event)759 @pytest.mark.asyncio()760 async def test_on_presence_update_stateful_update(self, event_manager, shard, event_factory):761 payload = {"user": {"id": 123}, "guild_id": 456}762 old_presence = object()763 event = mock.Mock(presence=mock.Mock(visible_status=presences.Status.ONLINE))764 event_factory.deserialize_presence_update_event.return_value = event765 event_manager._cache.get_presence.return_value = old_presence766 await event_manager.on_presence_update(shard, payload)767 event_manager._cache.get_presence.assert_called_once_with(456, 123)768 event_manager._cache.update_presence.assert_called_once_with(event.presence)769 event_factory.deserialize_presence_update_event.assert_called_once_with(770 shard, payload, old_presence=old_presence771 )772 event_manager.dispatch.assert_awaited_once_with(event)773 @pytest.mark.asyncio()774 async def test_on_presence_update_stateful_delete(self, event_manager, shard, event_factory):775 payload = {"user": {"id": 123}, "guild_id": 456}776 old_presence = object()777 event = mock.Mock(presence=mock.Mock(visible_status=presences.Status.OFFLINE))778 event_factory.deserialize_presence_update_event.return_value = event779 event_manager._cache.get_presence.return_value = old_presence780 await event_manager.on_presence_update(shard, payload)781 event_manager._cache.get_presence.assert_called_once_with(456, 123)782 event_manager._cache.delete_presence.assert_called_once_with(event.presence.guild_id, event.presence.user_id)783 event_factory.deserialize_presence_update_event.assert_called_once_with(784 shard, payload, old_presence=old_presence785 )786 event_manager.dispatch.assert_awaited_once_with(event)787 @pytest.mark.asyncio()788 async def test_on_presence_update_stateless(self, stateless_event_manager, shard, event_factory):789 payload = {"user": {"id": 123}, "guild_id": 456}790 await stateless_event_manager.on_presence_update(shard, payload)791 event_factory.deserialize_presence_update_event.assert_called_once_with(shard, payload, old_presence=None)792 stateless_event_manager.dispatch.assert_awaited_once_with(793 event_factory.deserialize_presence_update_event.return_value794 )795 @pytest.mark.asyncio()796 async def test_on_typing_start(self, event_manager, shard, event_factory):797 payload = {}798 event = mock.Mock()799 event_factory.deserialize_typing_start_event.return_value = event800 await event_manager.on_typing_start(shard, payload)801 event_factory.deserialize_typing_start_event.assert_called_once_with(shard, payload)802 event_manager.dispatch.assert_awaited_once_with(event)803 @pytest.mark.asyncio()804 async def test_on_user_update_stateful(self, event_manager, shard, event_factory):805 payload = {}806 old_user = object()807 event = mock.Mock(user=mock.Mock())808 event_factory.deserialize_own_user_update_event.return_value = event809 event_manager._cache.get_me.return_value = old_user810 await event_manager.on_user_update(shard, payload)811 event_manager._cache.update_me.assert_called_once_with(event.user)812 event_factory.deserialize_own_user_update_event.assert_called_once_with(shard, payload, old_user=old_user)813 event_manager.dispatch.assert_awaited_once_with(event)814 @pytest.mark.asyncio()815 async def test_on_user_update_stateless(self, stateless_event_manager, shard, event_factory):816 payload = {}817 await stateless_event_manager.on_user_update(shard, payload)818 event_factory.deserialize_own_user_update_event.assert_called_once_with(shard, payload, old_user=None)819 stateless_event_manager.dispatch.assert_awaited_once_with(820 event_factory.deserialize_own_user_update_event.return_value821 )822 @pytest.mark.asyncio()823 async def test_on_voice_state_update_stateful_update(self, event_manager, shard, event_factory):824 payload = {"user_id": 123, "guild_id": 456}825 old_state = object()826 event = mock.Mock(state=mock.Mock(channel_id=123))827 event_factory.deserialize_voice_state_update_event.return_value = event828 event_manager._cache.get_voice_state.return_value = old_state829 await event_manager.on_voice_state_update(shard, payload)830 event_manager._cache.get_voice_state.assert_called_once_with(456, 123)831 event_manager._cache.update_voice_state.assert_called_once_with(event.state)832 event_factory.deserialize_voice_state_update_event.assert_called_once_with(shard, payload, old_state=old_state)833 event_manager.dispatch.assert_awaited_once_with(event)834 @pytest.mark.asyncio()835 async def test_on_voice_state_update_stateful_delete(self, event_manager, shard, event_factory):836 payload = {"user_id": 123, "guild_id": 456}837 old_state = object()838 event = mock.Mock(state=mock.Mock(channel_id=None))839 event_factory.deserialize_voice_state_update_event.return_value = event840 event_manager._cache.get_voice_state.return_value = old_state841 await event_manager.on_voice_state_update(shard, payload)842 event_manager._cache.get_voice_state.assert_called_once_with(456, 123)843 event_manager._cache.delete_voice_state.assert_called_once_with(event.state.guild_id, event.state.user_id)844 event_factory.deserialize_voice_state_update_event.assert_called_once_with(shard, payload, old_state=old_state)845 event_manager.dispatch.assert_awaited_once_with(event)846 @pytest.mark.asyncio()847 async def test_on_voice_state_update_stateless(self, stateless_event_manager, shard, event_factory):848 payload = {"user_id": 123, "guild_id": 456}849 await stateless_event_manager.on_voice_state_update(shard, payload)850 event_factory.deserialize_voice_state_update_event.assert_called_once_with(shard, payload, old_state=None)851 stateless_event_manager.dispatch.assert_awaited_once_with(852 event_factory.deserialize_voice_state_update_event.return_value853 )854 @pytest.mark.asyncio()855 async def test_on_voice_server_update(self, event_manager, shard, event_factory):856 payload = {}857 event = mock.Mock()858 event_factory.deserialize_voice_server_update_event.return_value = event859 await event_manager.on_voice_server_update(shard, payload)860 event_factory.deserialize_voice_server_update_event.assert_called_once_with(shard, payload)861 event_manager.dispatch.assert_awaited_once_with(event)862 @pytest.mark.asyncio()863 async def test_on_webhooks_update(self, event_manager, shard, event_factory):864 payload = {}865 event = mock.Mock()866 event_factory.deserialize_webhook_update_event.return_value = event867 await event_manager.on_webhooks_update(shard, payload)868 event_factory.deserialize_webhook_update_event.assert_called_once_with(shard, payload)869 event_manager.dispatch.assert_awaited_once_with(event)870 @pytest.mark.asyncio()871 async def test_on_interaction_create(self, event_manager, shard, event_factory):872 payload = {"id": "123"}873 await event_manager.on_interaction_create(shard, payload)874 event_factory.deserialize_interaction_create_event.assert_called_once_with(shard, payload)875 event_manager.dispatch.assert_awaited_once_with(event_factory.deserialize_interaction_create_event.return_value)876 @pytest.mark.asyncio()877 async def test_on_guild_scheduled_event_create(878 self,879 event_manager: event_manager_.EventManagerImpl,880 shard: mock.Mock,881 event_factory: event_factory_.EventFactory,882 ):883 mock_payload = mock.Mock()884 await event_manager.on_guild_scheduled_event_create(shard, mock_payload)885 event_factory.deserialize_scheduled_event_create_event.assert_called_once_with(shard, mock_payload)886 event_manager.dispatch.assert_awaited_once_with(887 event_factory.deserialize_scheduled_event_create_event.return_value888 )889 @pytest.mark.asyncio()890 async def test_on_guild_scheduled_event_delete(891 self,892 event_manager: event_manager_.EventManagerImpl,893 shard: mock.Mock,894 event_factory: event_factory_.EventFactory,895 ):896 mock_payload = mock.Mock()897 await event_manager.on_guild_scheduled_event_delete(shard, mock_payload)898 event_factory.deserialize_scheduled_event_delete_event.assert_called_once_with(shard, mock_payload)899 event_manager.dispatch.assert_awaited_once_with(900 event_factory.deserialize_scheduled_event_delete_event.return_value901 )902 @pytest.mark.asyncio()903 async def test_on_guild_scheduled_event_update(904 self,905 event_manager: event_manager_.EventManagerImpl,906 shard: mock.Mock,907 event_factory: event_factory_.EventFactory,908 ):909 mock_payload = mock.Mock()910 await event_manager.on_guild_scheduled_event_update(shard, mock_payload)911 event_factory.deserialize_scheduled_event_update_event.assert_called_once_with(shard, mock_payload)912 event_manager.dispatch.assert_awaited_once_with(913 event_factory.deserialize_scheduled_event_update_event.return_value914 )915 @pytest.mark.asyncio()916 async def test_on_guild_scheduled_event_user_add(917 self,918 event_manager: event_manager_.EventManagerImpl,919 shard: mock.Mock,920 event_factory: event_factory_.EventFactory,921 ):922 mock_payload = mock.Mock()923 await event_manager.on_guild_scheduled_event_user_add(shard, mock_payload)924 event_factory.deserialize_scheduled_event_user_add_event.assert_called_once_with(shard, mock_payload)925 event_manager.dispatch.assert_awaited_once_with(926 event_factory.deserialize_scheduled_event_user_add_event.return_value927 )928 @pytest.mark.asyncio()929 async def test_on_guild_scheduled_event_user_remove(930 self,931 event_manager: event_manager_.EventManagerImpl,932 shard: mock.Mock,933 event_factory: event_factory_.EventFactory,934 ):935 mock_payload = mock.Mock()936 await event_manager.on_guild_scheduled_event_user_remove(shard, mock_payload)937 event_factory.deserialize_scheduled_event_user_remove_event.assert_called_once_with(shard, mock_payload)938 event_manager.dispatch.assert_awaited_once_with(939 event_factory.deserialize_scheduled_event_user_remove_event.return_value...
test_agent_manager.py
Source:test_agent_manager.py
...36 self.mgr.needs_resync = False37 def test_initialize_service_hook(self):38 with mock.patch.object(self.mgr, 'sync_state') as sync:39 self.mgr.initialize_service_hook(mock.Mock())40 sync.assert_called_once_with()41 def test_periodic_resync_needs_sync(self):42 with mock.patch.object(self.mgr, 'sync_state') as sync:43 self.mgr.needs_resync = True44 self.mgr.periodic_resync(mock.Mock())45 sync.assert_called_once_with()46 def test_periodic_resync_no_sync(self):47 with mock.patch.object(self.mgr, 'sync_state') as sync:48 self.mgr.needs_resync = False49 self.mgr.periodic_resync(mock.Mock())50 self.assertFalse(sync.called)51 def test_collect_stats(self):52 self.mgr.collect_stats(mock.Mock())53 self.rpc_mock.update_pool_stats.assert_has_calls([54 mock.call('1', mock.ANY),55 mock.call('2', mock.ANY)56 ])57 def test_collect_stats_exception(self):58 self.driver_mock.get_stats.side_effect = Exception59 self.mgr.collect_stats(mock.Mock())60 self.assertFalse(self.rpc_mock.called)61 self.assertTrue(self.mgr.needs_resync)62 self.assertTrue(self.log.exception.called)63 def _sync_state_helper(self, ready, reloaded, destroyed):64 with contextlib.nested(65 mock.patch.object(self.mgr, '_reload_pool'),66 mock.patch.object(self.mgr, '_destroy_pool')67 ) as (reload, destroy):68 self.rpc_mock.get_ready_devices.return_value = ready69 self.mgr.sync_state()70 self.assertEqual(len(reloaded), len(reload.mock_calls))71 self.assertEqual(len(destroyed), len(destroy.mock_calls))72 reload.assert_has_calls([mock.call(i) for i in reloaded])73 destroy.assert_has_calls([mock.call(i) for i in destroyed])74 self.assertFalse(self.mgr.needs_resync)75 def test_sync_state_all_known(self):76 self._sync_state_helper(['1', '2'], ['1', '2'], [])77 def test_sync_state_all_unknown(self):78 self.mgr.instance_mapping = {}79 self._sync_state_helper(['1', '2'], ['1', '2'], [])80 def test_sync_state_destroy_all(self):81 self._sync_state_helper([], [], ['1', '2'])82 def test_sync_state_both(self):83 self.mgr.instance_mapping = {'1': 'devdriver'}84 self._sync_state_helper(['2'], ['2'], ['1'])85 def test_sync_state_exception(self):86 self.rpc_mock.get_ready_devices.side_effect = Exception87 self.mgr.sync_state()88 self.assertTrue(self.log.exception.called)89 self.assertTrue(self.mgr.needs_resync)90 def test_reload_pool(self):91 config = {'driver': 'devdriver'}92 self.rpc_mock.get_logical_device.return_value = config93 pool_id = 'new_id'94 self.assertNotIn(pool_id, self.mgr.instance_mapping)95 self.mgr._reload_pool(pool_id)96 self.driver_mock.deploy_instance.assert_called_once_with(config)97 self.assertIn(pool_id, self.mgr.instance_mapping)98 self.rpc_mock.pool_deployed.assert_called_once_with(pool_id)99 def test_reload_pool_driver_not_found(self):100 config = {'driver': 'unknown_driver'}101 self.rpc_mock.get_logical_device.return_value = config102 pool_id = 'new_id'103 self.assertNotIn(pool_id, self.mgr.instance_mapping)104 self.mgr._reload_pool(pool_id)105 self.assertTrue(self.log.error.called)106 self.assertFalse(self.driver_mock.deploy_instance.called)107 self.assertNotIn(pool_id, self.mgr.instance_mapping)108 self.assertFalse(self.rpc_mock.pool_deployed.called)109 def test_reload_pool_exception_on_driver(self):110 config = {'driver': 'devdriver'}111 self.rpc_mock.get_logical_device.return_value = config112 self.driver_mock.deploy_instance.side_effect = Exception113 pool_id = 'new_id'114 self.assertNotIn(pool_id, self.mgr.instance_mapping)115 self.mgr._reload_pool(pool_id)116 self.driver_mock.deploy_instance.assert_called_once_with(config)117 self.assertNotIn(pool_id, self.mgr.instance_mapping)118 self.assertFalse(self.rpc_mock.pool_deployed.called)119 self.assertTrue(self.log.exception.called)120 self.assertTrue(self.mgr.needs_resync)121 def test_destroy_pool(self):122 pool_id = '1'123 self.assertIn(pool_id, self.mgr.instance_mapping)124 self.mgr._destroy_pool(pool_id)125 self.driver_mock.undeploy_instance.assert_called_once_with(pool_id)126 self.assertNotIn(pool_id, self.mgr.instance_mapping)127 self.rpc_mock.pool_destroyed.assert_called_once_with(pool_id)128 self.assertFalse(self.mgr.needs_resync)129 def test_destroy_pool_exception_on_driver(self):130 pool_id = '1'131 self.assertIn(pool_id, self.mgr.instance_mapping)132 self.driver_mock.undeploy_instance.side_effect = Exception133 self.mgr._destroy_pool(pool_id)134 self.driver_mock.undeploy_instance.assert_called_once_with(pool_id)135 self.assertIn(pool_id, self.mgr.instance_mapping)136 self.assertFalse(self.rpc_mock.pool_destroyed.called)137 self.assertTrue(self.log.exception.called)138 self.assertTrue(self.mgr.needs_resync)139 def test_get_driver_unknown_device(self):140 self.assertRaises(manager.DeviceNotFoundOnAgent,141 self.mgr._get_driver, 'unknown')142 def test_remove_orphans(self):143 self.mgr.remove_orphans()144 self.driver_mock.remove_orphans.assert_called_once_with(['1', '2'])145 def test_create_vip(self):146 vip = {'id': 'id1', 'pool_id': '1'}147 self.mgr.create_vip(mock.Mock(), vip)148 self.driver_mock.create_vip.assert_called_once_with(vip)149 self.rpc_mock.update_status.assert_called_once_with('vip', vip['id'],150 constants.ACTIVE)151 def test_create_vip_failed(self):152 vip = {'id': 'id1', 'pool_id': '1'}153 self.driver_mock.create_vip.side_effect = Exception154 self.mgr.create_vip(mock.Mock(), vip)155 self.driver_mock.create_vip.assert_called_once_with(vip)156 self.rpc_mock.update_status.assert_called_once_with('vip', vip['id'],157 constants.ERROR)158 def test_update_vip(self):159 old_vip = {'id': 'id1'}160 vip = {'id': 'id1', 'pool_id': '1'}161 self.mgr.update_vip(mock.Mock(), old_vip, vip)162 self.driver_mock.update_vip.assert_called_once_with(old_vip, vip)163 self.rpc_mock.update_status.assert_called_once_with('vip', vip['id'],164 constants.ACTIVE)165 def test_update_vip_failed(self):166 old_vip = {'id': 'id1'}167 vip = {'id': 'id1', 'pool_id': '1'}168 self.driver_mock.update_vip.side_effect = Exception169 self.mgr.update_vip(mock.Mock(), old_vip, vip)170 self.driver_mock.update_vip.assert_called_once_with(old_vip, vip)171 self.rpc_mock.update_status.assert_called_once_with('vip', vip['id'],172 constants.ERROR)173 def test_delete_vip(self):174 vip = {'id': 'id1', 'pool_id': '1'}175 self.mgr.delete_vip(mock.Mock(), vip)176 self.driver_mock.delete_vip.assert_called_once_with(vip)177 def test_create_pool(self):178 pool = {'id': 'id1'}179 self.assertNotIn(pool['id'], self.mgr.instance_mapping)180 self.mgr.create_pool(mock.Mock(), pool, 'devdriver')181 self.driver_mock.create_pool.assert_called_once_with(pool)182 self.rpc_mock.update_status.assert_called_once_with('pool', pool['id'],183 constants.ACTIVE)184 self.assertIn(pool['id'], self.mgr.instance_mapping)185 def test_create_pool_failed(self):186 pool = {'id': 'id1'}187 self.assertNotIn(pool['id'], self.mgr.instance_mapping)188 self.driver_mock.create_pool.side_effect = Exception189 self.mgr.create_pool(mock.Mock(), pool, 'devdriver')190 self.driver_mock.create_pool.assert_called_once_with(pool)191 self.rpc_mock.update_status.assert_called_once_with('pool', pool['id'],192 constants.ERROR)193 self.assertNotIn(pool['id'], self.mgr.instance_mapping)194 def test_update_pool(self):195 old_pool = {'id': '1'}196 pool = {'id': '1'}197 self.mgr.update_pool(mock.Mock(), old_pool, pool)198 self.driver_mock.update_pool.assert_called_once_with(old_pool, pool)199 self.rpc_mock.update_status.assert_called_once_with('pool', pool['id'],200 constants.ACTIVE)201 def test_update_pool_failed(self):202 old_pool = {'id': '1'}203 pool = {'id': '1'}204 self.driver_mock.update_pool.side_effect = Exception205 self.mgr.update_pool(mock.Mock(), old_pool, pool)206 self.driver_mock.update_pool.assert_called_once_with(old_pool, pool)207 self.rpc_mock.update_status.assert_called_once_with('pool', pool['id'],208 constants.ERROR)209 def test_delete_pool(self):210 pool = {'id': '1'}211 self.assertIn(pool['id'], self.mgr.instance_mapping)212 self.mgr.delete_pool(mock.Mock(), pool)213 self.driver_mock.delete_pool.assert_called_once_with(pool)214 self.assertNotIn(pool['id'], self.mgr.instance_mapping)215 def test_create_member(self):216 member = {'id': 'id1', 'pool_id': '1'}217 self.mgr.create_member(mock.Mock(), member)218 self.driver_mock.create_member.assert_called_once_with(member)219 self.rpc_mock.update_status.assert_called_once_with('member',220 member['id'],221 constants.ACTIVE)222 def test_create_member_failed(self):223 member = {'id': 'id1', 'pool_id': '1'}224 self.driver_mock.create_member.side_effect = Exception225 self.mgr.create_member(mock.Mock(), member)226 self.driver_mock.create_member.assert_called_once_with(member)227 self.rpc_mock.update_status.assert_called_once_with('member',228 member['id'],229 constants.ERROR)230 def test_update_member(self):231 old_member = {'id': 'id1'}232 member = {'id': 'id1', 'pool_id': '1'}233 self.mgr.update_member(mock.Mock(), old_member, member)234 self.driver_mock.update_member.assert_called_once_with(old_member,235 member)236 self.rpc_mock.update_status.assert_called_once_with('member',237 member['id'],238 constants.ACTIVE)239 def test_update_member_failed(self):240 old_member = {'id': 'id1'}241 member = {'id': 'id1', 'pool_id': '1'}242 self.driver_mock.update_member.side_effect = Exception243 self.mgr.update_member(mock.Mock(), old_member, member)244 self.driver_mock.update_member.assert_called_once_with(old_member,245 member)246 self.rpc_mock.update_status.assert_called_once_with('member',247 member['id'],248 constants.ERROR)249 def test_delete_member(self):250 member = {'id': 'id1', 'pool_id': '1'}251 self.mgr.delete_member(mock.Mock(), member)252 self.driver_mock.delete_member.assert_called_once_with(member)253 def test_create_monitor(self):254 monitor = {'id': 'id1'}255 assoc_id = {'monitor_id': monitor['id'], 'pool_id': '1'}256 self.mgr.create_pool_health_monitor(mock.Mock(), monitor, '1')257 self.driver_mock.create_pool_health_monitor.assert_called_once_with(258 monitor, '1')259 self.rpc_mock.update_status.assert_called_once_with('health_monitor',260 assoc_id,261 constants.ACTIVE)262 def test_create_monitor_failed(self):263 monitor = {'id': 'id1'}264 assoc_id = {'monitor_id': monitor['id'], 'pool_id': '1'}265 self.driver_mock.create_pool_health_monitor.side_effect = Exception266 self.mgr.create_pool_health_monitor(mock.Mock(), monitor, '1')267 self.driver_mock.create_pool_health_monitor.assert_called_once_with(268 monitor, '1')269 self.rpc_mock.update_status.assert_called_once_with('health_monitor',270 assoc_id,271 constants.ERROR)272 def test_update_monitor(self):273 monitor = {'id': 'id1'}274 assoc_id = {'monitor_id': monitor['id'], 'pool_id': '1'}275 self.mgr.update_pool_health_monitor(mock.Mock(), monitor, monitor, '1')276 self.driver_mock.update_pool_health_monitor.assert_called_once_with(277 monitor, monitor, '1')278 self.rpc_mock.update_status.assert_called_once_with('health_monitor',279 assoc_id,280 constants.ACTIVE)281 def test_update_monitor_failed(self):282 monitor = {'id': 'id1'}283 assoc_id = {'monitor_id': monitor['id'], 'pool_id': '1'}284 self.driver_mock.update_pool_health_monitor.side_effect = Exception285 self.mgr.update_pool_health_monitor(mock.Mock(), monitor, monitor, '1')286 self.driver_mock.update_pool_health_monitor.assert_called_once_with(287 monitor, monitor, '1')288 self.rpc_mock.update_status.assert_called_once_with('health_monitor',289 assoc_id,290 constants.ERROR)291 def test_delete_monitor(self):292 monitor = {'id': 'id1'}293 self.mgr.delete_pool_health_monitor(mock.Mock(), monitor, '1')294 self.driver_mock.delete_pool_health_monitor.assert_called_once_with(295 monitor, '1')296 def test_agent_disabled(self):297 payload = {'admin_state_up': False}298 self.mgr.agent_updated(mock.Mock(), payload)299 self.driver_mock.undeploy_instance.assert_has_calls(...
test_run_scripts.py
Source:test_run_scripts.py
...55 instances_with_services.return_value = instances56 mess = pu.start_process_event_message('DataNodes, NodeManagers')57 ins.node_group.node_processes = ['datanode', 'test']58 rs.start_dn_nm_processes(instances)59 instances_with_services.assert_called_once_with(60 instances, ['datanode', 'nodemanager'])61 add_provisioning_step.assert_called_once_with('111', mess, 1)62 set_current_instance_id.assert_called_once_with('123')63 _start_processes.assert_called_once_with(ins, ['datanode'])64 @mock.patch('sahara.plugins.utils.check_cluster_exists')65 def test_start_processes_datanode(self, check_cluster_exists):66 processes = ['datanode']67 rs._start_processes(self.instance, processes)68 self.r.execute_command.assert_called_once_with(69 'sudo su - -c "hadoop-daemon.sh start datanode" hadoop')70 @mock.patch('sahara.plugins.utils.check_cluster_exists')71 def test_start_processes_nodemanager(self, check_cluster_exists):72 processes = ['nodemanager']73 rs._start_processes(self.instance, processes)74 self.r.execute_command.assert_called_once_with(75 'sudo su - -c "yarn-daemon.sh start nodemanager" hadoop')76 @mock.patch('sahara.plugins.utils.check_cluster_exists')77 def test_start_processes_both(self, check_cluster_exists):78 processes = ['datanode', 'nodemanager']79 rs._start_processes(self.instance, processes)80 cmd_1 = 'sudo su - -c "hadoop-daemon.sh start datanode" hadoop'81 cmd_2 = 'sudo su - -c "yarn-daemon.sh start nodemanager" hadoop'82 calls = [mock.call(cmd_1), mock.call(cmd_2)]83 self.r.execute_command.assert_has_calls(calls, any_order=True)84 def test_start_hadoop_process(self):85 process = 'test'86 rs.start_hadoop_process(self.instance, process)87 self.remote.execute_command.assert_called_once_with(88 'sudo su - -c "hadoop-daemon.sh start %s" hadoop' % process)89 def test_start_yarn_process(self):90 process = 'test'91 rs.start_yarn_process(self.instance, process)92 self.remote.execute_command.assert_called_once_with(93 'sudo su - -c "yarn-daemon.sh start %s" hadoop' % process)94 @mock.patch('sahara.plugins.utils.check_cluster_exists')95 @mock.patch('sahara.plugins.utils.add_provisioning_step')96 def test_start_historyserver(self, add_provisioning_step,97 check_cluster_exists):98 rs.start_historyserver(self.instance)99 self.remote.execute_command.assert_called_once_with(100 'sudo su - -c "mr-jobhistory-daemon.sh start historyserver" ' +101 'hadoop')102 @mock.patch(PLUGINS_PATH + 'run_scripts._start_oozie')103 @mock.patch(PLUGINS_PATH + 'run_scripts._oozie_share_lib')104 @mock.patch(PLUGINS_PATH + 'run_scripts._start_mysql')105 @mock.patch(PLUGINS_PATH + 'config_helper.is_mysql_enabled')106 @mock.patch(PLUGINS_PATH + 'utils.get_oozie_password')107 @mock.patch('sahara.plugins.context.set_current_instance_id')108 @mock.patch('sahara.plugins.utils.check_cluster_exists')109 @mock.patch('sahara.plugins.utils.add_provisioning_step')110 def test_start_oozie_process(self, add_provisioning_step,111 check_cluster_exists,112 set_current_instance_id, get_oozie_password,113 is_mysql_enabled, _start_mysql,114 _oozie_share_lib, _start_oozie):115 self.instance.instance_id = '112233'116 pctx = mock.Mock()117 is_mysql_enabled.return_value = True118 sql_script = pu.get_file_text(119 'plugins/vanilla/hadoop2/resources/create_oozie_db.sql',120 'sahara_plugin_vanilla')121 get_oozie_password.return_value = '123'122 pwd_script = sql_script.replace('password', '123')123 rs.start_oozie_process(pctx, self.instance)124 set_current_instance_id.assert_called_once_with('112233')125 is_mysql_enabled.assert_called_once_with(pctx,126 self.instance.cluster)127 _start_mysql.assert_called_once_with(self.r)128 self.r.write_file_to.assert_called_once_with('create_oozie_db.sql',129 pwd_script)130 self.r.execute_command.assert_called_once_with(131 'mysql -u root < create_oozie_db.sql && '132 'rm create_oozie_db.sql')133 _oozie_share_lib.assert_called_once_with(self.r)134 _start_oozie.assert_called_once_with(self.r)135 @mock.patch(PLUGINS_PATH + 'config_helper.get_spark_home')136 @mock.patch('sahara.plugins.context.set_current_instance_id')137 @mock.patch('sahara.plugins.utils.check_cluster_exists')138 @mock.patch('sahara.plugins.utils.add_provisioning_step')139 def test_start_spark_history_server(self, add_provisioning_step,140 check_cluster_exists,141 set_current_instance_id,142 get_spark_home):143 get_spark_home.return_value = '/spark'144 rs.start_spark_history_server(self.instance)145 get_spark_home.assert_called_once_with(self.instance.cluster)146 set_current_instance_id.assert_called_once_with(147 self.instance.instance_id)148 self.r.execute_command.assert_called_once_with(149 'sudo su - -c "bash /spark/sbin/start-history-server.sh" hadoop')150 def test_format_namenode(self):151 rs.format_namenode(self.instance)152 self.remote.execute_command.assert_called_once_with(153 'sudo su - -c "hdfs namenode -format" hadoop')154 @mock.patch('sahara_plugin_vanilla.plugins.vanilla.utils.get_namenode')155 @mock.patch('sahara.plugins.utils.check_cluster_exists')156 @mock.patch('sahara.plugins.utils.add_provisioning_step')157 def test_refresh_hadoop_nodes(self, add_provisioning_step,158 check_cluster_exists, get_namenode):159 cluster = mock.Mock()160 get_namenode.return_value = self.instance161 rs.refresh_hadoop_nodes(cluster)162 get_namenode.assert_called_once_with(cluster)163 self.remote.execute_command.assert_called_once_with(164 'sudo su - -c "hdfs dfsadmin -refreshNodes" hadoop')165 @mock.patch('sahara_plugin_vanilla.plugins.vanilla.utils.'166 'get_resourcemanager')167 @mock.patch('sahara.plugins.utils.check_cluster_exists')168 @mock.patch('sahara.plugins.utils.add_provisioning_step')169 def test_refresh_yarn_nodes(self, add_provisioning_step,170 check_cluster_exists, get_resourcemanager):171 cluster = mock.Mock()172 get_resourcemanager.return_value = self.instance173 rs.refresh_yarn_nodes(cluster)174 get_resourcemanager.assert_called_once_with(cluster)175 self.remote.execute_command.assert_called_once_with(176 'sudo su - -c "yarn rmadmin -refreshNodes" hadoop')177 def test_oozie_share_lib(self):178 cmd_1 = 'sudo su - -c "mkdir /tmp/oozielib && ' \179 'tar zxf /opt/oozie/oozie-sharelib-*.tar.gz -C ' \180 '/tmp/oozielib && ' \181 'hadoop fs -mkdir /user && ' \182 'hadoop fs -mkdir /user/hadoop && ' \183 'hadoop fs -put /tmp/oozielib/share /user/hadoop/ && ' \184 'rm -rf /tmp/oozielib" hadoop'185 cmd_2 = 'sudo su - -c "/opt/oozie/bin/ooziedb.sh ' \186 'create -sqlfile oozie.sql ' \187 '-run Validate DB Connection" hadoop'188 command = [mock.call(cmd_1),189 mock.call(cmd_2)]190 rs._oozie_share_lib(self.r)191 self.r.execute_command.assert_has_calls(command, any_order=True)192 def test_start_mysql(self):193 rs._start_mysql(self.r)194 self.r.execute_command.assert_called_once_with('/opt/start-mysql.sh')195 def test_start_oozie(self):196 rs._start_oozie(self.r)197 self.r.execute_command.assert_called_once_with(198 'sudo su - -c "/opt/oozie/bin/oozied.sh start" hadoop')199 @mock.patch('sahara_plugin_vanilla.plugins.vanilla.utils.get_namenode')200 @mock.patch('sahara_plugin_vanilla.plugins.vanilla.utils.get_datanodes')201 @mock.patch('sahara.plugins.utils.check_cluster_exists')202 @mock.patch('sahara.plugins.utils.add_provisioning_step')203 @mock.patch('sahara.plugins.utils.plugin_option_poll')204 def test_await_datanodes(self, plugin_option_poll, add_provisioning_step,205 check_cluster_exists, get_datanodes,206 get_namenode):207 cluster = mock.Mock()208 get_datanodes.return_value = ['node1']209 r = mock.Mock()210 remote = mock.Mock(return_value=r)211 remote.__enter__ = remote212 remote.__exit__ = mock.Mock()213 namenode = mock.Mock()214 namenode.remote.return_value = remote215 get_namenode.return_value = namenode216 mess = _('Waiting on 1 datanodes to start up')217 test_data = {'remote': r, 'count': 1}218 timeout = config_helper.DATANODES_STARTUP_TIMEOUT219 rs.await_datanodes(cluster)220 get_datanodes.assert_called_once_with(cluster)221 get_namenode.assert_called_once_with(cluster)222 plugin_option_poll.assert_called_once_with(cluster,223 rs._check_datanodes_count,224 timeout, mess, 1, test_data)225 def test_check_datanodes_count(self):226 self.r.execute_command = mock.Mock(return_value=(0, '1'))227 self.assertEqual(rs._check_datanodes_count(self.r, 0), True)228 self.assertEqual(rs._check_datanodes_count(self.r, 1), True)229 self.r.execute_command.assert_called_once_with(230 'sudo su -lc "hdfs dfsadmin -report" hadoop | '231 'grep \'Live datanodes\|Datanodes available:\' | '232 'grep -o \'[0-9]\+\' | head -n 1')233 def test_hive_create_warehouse_dir(self):234 rs._hive_create_warehouse_dir(self.r)235 self.r.execute_command.assert_called_once_with(236 "sudo su - -c 'hadoop fs -mkdir -p "237 "/user/hive/warehouse' hadoop")238 def test_hive_copy_shared_conf(self):239 dest = '/root/test.xml'240 rs._hive_copy_shared_conf(self.r, dest)241 self.r.execute_command.assert_called_once_with(242 "sudo su - -c 'hadoop fs -mkdir -p /root && "243 "hadoop fs -put /opt/hive/conf/hive-site.xml "244 "/root/test.xml' hadoop")245 def test_hive_create_db(self):246 rs._hive_create_db(self.r)247 self.r.execute_command.assert_called_once_with(248 'mysql -u root < /tmp/create_hive_db.sql')249 def test_hive_metastore_start(self):250 rs._hive_metastore_start(self.r)251 self.r.execute_command.assert_called_once_with(252 "sudo su - -c 'nohup /opt/hive/bin/hive"253 " --service metastore > /dev/null &' hadoop")254 @mock.patch(PLUGINS_PATH + 'utils.get_hive_password')255 @mock.patch(PLUGINS_PATH + 'config_helper.is_mysql_enabled')256 @mock.patch(PLUGINS_PATH + 'run_scripts._hive_metastore_start')257 @mock.patch(PLUGINS_PATH + 'run_scripts._hive_create_db')258 @mock.patch(PLUGINS_PATH + 'run_scripts._start_mysql')259 @mock.patch(PLUGINS_PATH + 'run_scripts._hive_copy_shared_conf')260 @mock.patch(PLUGINS_PATH + 'run_scripts._hive_create_warehouse_dir')261 @mock.patch('sahara_plugin_vanilla.plugins.vanilla.utils.get_oozie')262 @mock.patch('sahara.plugins.context.set_current_instance_id')263 @mock.patch('sahara.plugins.utils.check_cluster_exists')264 @mock.patch('sahara.plugins.utils.add_provisioning_step')265 def test_start_hiveserver_process(self, add_provisioning_step,266 check_cluster_exists,267 set_current_instance_id, get_oozie,268 _hive_create_warehouse_dir,269 _hive_copy_shared_conf, _start_mysql,270 _hive_create_db, _hive_metastore_start,271 is_mysql_enabled, get_hive_password):272 pctx = mock.Mock()273 path = edp.get_hive_shared_conf_path('hadoop')274 is_mysql_enabled.return_value = True275 cluster = self.instance.cluster276 self.instance.cluster.hadoop_version = '2.7.1'277 ng_cluster = self.instance.node_group.cluster278 get_oozie.return_value = None279 sql_script = pu.get_file_text(280 'plugins/vanilla/v2_7_1/resources/create_hive_db.sql',281 'sahara_plugin_vanilla')282 get_hive_password.return_value = '123'283 pwd_script = sql_script.replace('{{password}}', '123')284 rs.start_hiveserver_process(pctx, self.instance)285 set_current_instance_id.assert_called_once_with(286 self.instance.instance_id)287 _hive_create_warehouse_dir.assert_called_once_with(self.r)288 _hive_copy_shared_conf.assert_called_once_with(self.r, path)289 is_mysql_enabled.assert_called_once_with(pctx, cluster)290 get_oozie.assert_called_once_with(ng_cluster)291 _start_mysql.assert_called_once_with(self.r)292 get_hive_password.assert_called_once_with(cluster)293 self.r.write_file_to.assert_called_once_with(294 '/tmp/create_hive_db.sql', pwd_script)295 _hive_create_db.assert_called_once_with(self.r)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!