Exemplo n.º 1
0
async def test_import_already_in_progress_error(plugin, read, write):
    plugin.prepare_local_size_context.return_value = async_return_value(None)
    requests = [{
        "jsonrpc": "2.0",
        "id": "3",
        "method": "start_local_size_import",
        "params": {
            "game_ids": ["42"]
        }
    }, {
        "jsonrpc": "2.0",
        "id": "4",
        "method": "start_local_size_import",
        "params": {
            "game_ids": ["13"]
        }
    }]
    read.side_effect = [
        async_return_value(create_message(requests[0])),
        async_return_value(create_message(requests[1])),
        async_return_value(b"", 10)
    ]

    await plugin.run()

    responses = get_messages(write)
    assert {"jsonrpc": "2.0", "id": "3", "result": None} in responses
    assert {
        "jsonrpc": "2.0",
        "id": "4",
        "error": {
            "code": 600,
            "message": "Import already in progress"
        }
    } in responses
Exemplo n.º 2
0
async def test_prepare_get_local_size_context_error(plugin, read, write):
    request_id = "31415"
    error_details = {"Details": "Unexpected syntax"}
    error_message, error_code = FailedParsingManifest(
    ).message, FailedParsingManifest().code
    plugin.prepare_local_size_context.side_effect = FailedParsingManifest(
        data=error_details)
    request = {
        "jsonrpc": "2.0",
        "id": request_id,
        "method": "start_local_size_import",
        "params": {
            "game_ids": ["6"]
        }
    }
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"", 10)
    ]
    await plugin.run()
    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": request_id,
        "error": {
            "code": error_code,
            "message": error_message,
            "data": {
                "internal_type": "FailedParsingManifest",
                "Details": "Unexpected syntax"
            }
        }
    }]
Exemplo n.º 3
0
async def test_prepare_get_unlocked_achievements_context_error(
        plugin, read, write):
    plugin.prepare_achievements_context.side_effect = BackendError()
    request = {
        "jsonrpc": "2.0",
        "id": "3",
        "method": "start_achievements_import",
        "params": {
            "game_ids": ["14"]
        }
    }
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"", 10)
    ]

    await plugin.run()

    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": "3",
        "error": {
            "code": 4,
            "message": "Backend error"
        }
    }]
Exemplo n.º 4
0
async def test_get_friends_success(plugin, read, write):
    request = {
        "jsonrpc": "2.0",
        "id": "3",
        "method": "import_friends"
    }

    read.side_effect = [async_return_value(create_message(request)), async_return_value(b"", 10)]
    plugin.get_friends.return_value = async_return_value([
        UserInfo("3", "Jan", "https://avatar.url/u3", None),
        UserInfo("5", "Ola", None, "https://profile.url/u5"),
        UserInfo("6", "Ola2", None),
        UserInfo("7", "Ola3"),
    ])
    await plugin.run()
    plugin.get_friends.assert_called_with()

    assert get_messages(write) == [
        {
            "jsonrpc": "2.0",
            "id": "3",
            "result": {
                "friend_info_list": [
                    {"user_id": "3", "user_name": "Jan", "avatar_url": "https://avatar.url/u3"},
                    {"user_id": "5", "user_name": "Ola", "profile_url": "https://profile.url/u5"},
                    {"user_id": "6", "user_name": "Ola2"},
                    {"user_id": "7", "user_name": "Ola3"},
                ]
            }
        }
    ]
async def test_prepare_get_subscription_games_context_error(
        plugin, read, write):
    request_id = "31415"
    error_details = "Unexpected backend error"
    error_message, error_code = BackendError().message, BackendError().code
    plugin.prepare_subscription_games_context.side_effect = BackendError(
        error_details)
    request = {
        "jsonrpc": "2.0",
        "id": request_id,
        "method": "start_subscription_games_import",
        "params": {
            "subscription_names": ["sub_a", "sub_b"]
        }
    }
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"", 10)
    ]
    await plugin.run()

    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": request_id,
        "error": {
            "code": error_code,
            "message": error_message,
            "data": error_details
        }
    }]
async def test_get_subscriptions_success(plugin, read, write):
    request = {"jsonrpc": "2.0", "id": "3", "method": "import_subscriptions"}
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"", 10)
    ]

    plugin.get_subscriptions.return_value = async_return_value([
        Subscription("1"),
        Subscription("2", False),
        Subscription("3", True, 1580899100)
    ])
    await plugin.run()
    plugin.get_subscriptions.assert_called_with()

    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": "3",
        "result": {
            "subscriptions": [{
                "subscription_name": "1"
            }, {
                "subscription_name": "2",
                "owned": False
            }, {
                "subscription_name": "3",
                "owned": True,
                "end_time": 1580899100
            }]
        }
    }]
async def test_get_friends_success(plugin, read, write):
    request = {
        "jsonrpc": "2.0",
        "id": "3",
        "method": "import_friends"
    }

    read.side_effect = [async_return_value(create_message(request)), async_return_value(b"", 10)]
    plugin.get_friends.return_value = async_return_value([
        FriendInfo("3", "Jan"),
        FriendInfo("5", "Ola")
    ])
    await plugin.run()
    plugin.get_friends.assert_called_with()

    assert get_messages(write) == [
        {
            "jsonrpc": "2.0",
            "id": "3",
            "result": {
                "friend_info_list": [
                    {"user_id": "3", "user_name": "Jan"},
                    {"user_id": "5", "user_name": "Ola"}
                ]
            }
        }
    ]
Exemplo n.º 8
0
def populate_queue_with_email_msg(mocker,
                                  app_,
                                  email_notification,
                                  queue_name='test-queue'):
    boto3.setup_default_session(region_name=app_.config['AWS_REGION'])
    sqs_connection = create_sqs_connection()
    sqs_resource = create_sqs_resource(app_.config['AWS_REGION'])
    queue = create_queue(sqs_connection, queue_name)
    msg = create_message(app_.config, sqs_resource, queue, "email",
                         email_notification)

    def _receive(MaxNumberOfMessages=1,
                 VisibilityTimeout=60,
                 MessageAttributeNames=[]):
        return [msg]

    setattr(queue, 'receive_messages', _receive)

    def _get(config, queue_name_prefix=''):
        return [queue]

    mocker.patch(
        'notifications_delivery.processor.sqs_processor._get_all_queues',
        side_effect=_get)
    return queue
async def test_get_capabilities(reader, writer, read, write):
    class PluginImpl(Plugin): #pylint: disable=abstract-method
        async def get_owned_games(self):
            pass

    request = {
        "jsonrpc": "2.0",
        "id": "3",
        "method": "get_capabilities"
    }
    token = "token"
    plugin = PluginImpl(Platform.Generic, "0.1", reader, writer, token)
    read.side_effect = [async_return_value(create_message(request)), async_return_value(b"")]
    await plugin.run()
    assert get_messages(write) == [
        {
            "jsonrpc": "2.0",
            "id": "3",
            "result": {
                "platform_name": "generic",
                "features": [
                    "ImportOwnedGames"
                ],
                "token": token
            }
        }
    ]
async def test_prepare_get_os_compatibility_context_error(plugin, read, write):
    request_id = "31415"
    plugin.prepare_os_compatibility_context.side_effect = BackendError()
    request = {
        "jsonrpc": "2.0",
        "id": request_id,
        "method": "start_os_compatibility_import",
        "params": {
            "game_ids": ["6"]
        }
    }
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"", 10)
    ]
    await plugin.run()

    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": request_id,
        "error": {
            "code": 4,
            "message": "Backend error"
        }
    }]
Exemplo n.º 11
0
async def test_success(plugin, read, write):
    request = {"jsonrpc": "2.0", "id": "3", "method": "import_local_games"}
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"")
    ]

    plugin.get_local_games.return_value = async_return_value([
        LocalGame("1", LocalGameState.Running),
        LocalGame("2", LocalGameState.Installed),
        LocalGame("3", LocalGameState.Installed | LocalGameState.Running)
    ])
    await plugin.run()
    plugin.get_local_games.assert_called_with()

    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": "3",
        "result": {
            "local_games": [{
                "game_id": "1",
                "local_game_state": LocalGameState.Running.value
            }, {
                "game_id": "2",
                "local_game_state": LocalGameState.Installed.value
            }, {
                "game_id":
                "3",
                "local_game_state":
                (LocalGameState.Installed | LocalGameState.Running).value
            }]
        }
    }]
Exemplo n.º 12
0
async def test_prepare_get_user_presence_context_error(plugin, read, write):
    request_id = "31415"
    plugin.prepare_user_presence_context.side_effect = BackendError()
    request = {
        "jsonrpc": "2.0",
        "id": request_id,
        "method": "start_user_presence_import",
        "params": {
            "user_id_list": ["6"]
        }
    }
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"", 10)
    ]
    await plugin.run()

    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": request_id,
        "error": {
            "code": 4,
            "message": "Backend error",
            "data": {
                "internal_type": "BackendError"
            }
        }
    }]
Exemplo n.º 13
0
async def test_get_local_size_success(plugin, read, write):
    context = {'abc': 'def'}
    plugin.prepare_local_size_context.return_value = async_return_value(
        context)
    request = {
        "jsonrpc": "2.0",
        "id": "11",
        "method": "start_local_size_import",
        "params": {
            "game_ids": ["777", "13", "42"]
        }
    }
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"", 10)
    ]
    plugin.get_local_size.side_effect = [
        async_return_value(100000000000, 1),
        async_return_value(None),
        async_return_value(3333333)
    ]
    await plugin.run()
    plugin.get_local_size.assert_has_calls(
        [call("777", context),
         call("13", context),
         call("42", context)])
    plugin.local_size_import_complete.assert_called_once_with()

    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": "11",
        "result": None
    }, {
        "jsonrpc": "2.0",
        "method": "local_size_import_success",
        "params": {
            "game_id": "777",
            "local_size": 100000000000
        }
    }, {
        "jsonrpc": "2.0",
        "method": "local_size_import_success",
        "params": {
            "game_id": "13",
            "local_size": None
        }
    }, {
        "jsonrpc": "2.0",
        "method": "local_size_import_success",
        "params": {
            "game_id": "42",
            "local_size": 3333333
        }
    }, {
        "jsonrpc": "2.0",
        "method": "local_size_import_finished",
        "params": None
    }]
async def test_import_in_progress(plugin, read, write):
    plugin.prepare_achievements_context.return_value = async_return_value(None)
    requests = [
        {
            "jsonrpc": "2.0",
            "id": "3",
            "method": "start_achievements_import",
            "params": {
                "game_ids": ["14"]
            }
        },
        {
            "jsonrpc": "2.0",
            "id": "4",
            "method": "start_achievements_import",
            "params": {
                "game_ids": ["15"]
            }
        }
    ]
    read.side_effect = [
        async_return_value(create_message(requests[0])),
        async_return_value(create_message(requests[1])),
        async_return_value(b"")
    ]

    await plugin.run()

    assert get_messages(write) == [
        {
            "jsonrpc": "2.0",
            "id": "3",
            "result": None
        },
        {
            "jsonrpc": "2.0",
            "id": "4",
            "error": {
                "code": 600,
                "message": "Import already in progress"
            }
        }
    ]
Exemplo n.º 15
0
async def test_success(plugin, read):
    request = {
        "jsonrpc": "2.0",
        "method": "shutdown_platform_client"
    }

    read.side_effect = [async_return_value(create_message(request)), async_return_value(b"")]
    plugin.shutdown_platform_client.return_value = async_return_value(None)
    await plugin.run()
    plugin.shutdown_platform_client.assert_called_with()
async def test_tick_after_handshake(plugin, read):
    request = {
        "jsonrpc": "2.0",
        "id": "6",
        "method": "initialize_cache",
        "params": {"data": {}}
    }
    read.side_effect = [async_return_value(create_message(request)), async_return_value(b"")]
    await plugin.run()
    plugin.tick.assert_called_with()
Exemplo n.º 17
0
async def test_import_in_progress(plugin, read, write):
    plugin.prepare_game_library_settings_context.return_value = async_return_value(None)
    requests = [
        {
            "jsonrpc": "2.0",
            "id": "3",
            "method": "start_game_library_settings_import",
            "params": {
                "game_ids": ["6"]
            }
        },
        {
            "jsonrpc": "2.0",
            "id": "4",
            "method": "start_game_library_settings_import",
            "params": {
                "game_ids": ["7"]
            }
        }
    ]
    read.side_effect = [
        async_return_value(create_message(requests[0])),
        async_return_value(create_message(requests[1])),
        async_return_value(b"", 10)
    ]

    await plugin.run()

    messages = get_messages(write)
    assert {
        "jsonrpc": "2.0",
        "id": "3",
        "result": None
    } in messages
    assert {
        "jsonrpc": "2.0",
        "id": "4",
        "error": {
            "code": 600,
            "message": "Import already in progress",
            "data": {"internal_type": "ImportInProgress"}
        }
    } in messages
async def test_shutdown(plugin, read, write):
    request = {"jsonrpc": "2.0", "id": "5", "method": "shutdown"}
    read.side_effect = [async_return_value(create_message(request))]
    await plugin.run()
    plugin.shutdown.assert_called_with()
    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": "5",
        "result": None
    }]
async def test_import_already_in_progress_error(plugin, read, write):
    plugin.prepare_subscription_games_context.return_value = async_return_value(None)
    requests = [
        {
            "jsonrpc": "2.0",
            "id": "3",
            "method": "start_subscription_games_import",
            "params": {
                "subscription_names": ["sub_a"]
            }
        },
        {
            "jsonrpc": "2.0",
            "id": "4",
            "method": "start_subscription_games_import",
            "params": {
                "subscription_names": ["sub_a","sub_b"]
            }
        }
    ]
    read.side_effect = [
        async_return_value(create_message(requests[0])),
        async_return_value(create_message(requests[1])),
        async_return_value(b"", 10)
    ]

    await plugin.run()

    responses = get_messages(write)
    assert {
        "jsonrpc": "2.0",
        "id": "3",
        "result": None
    } in responses
    assert {
        "jsonrpc": "2.0",
        "id": "4",
        "error": {
            "code": 600,
            "message": "Import already in progress",
            "data": {"internal_type": "ImportInProgress"}
        }
    } in responses
async def test_get_unlocked_achievements_success(plugin, read, write):
    plugin.prepare_achievements_context.return_value = async_return_value(5)
    request = {
        "jsonrpc": "2.0",
        "id": "3",
        "method": "start_achievements_import",
        "params": {
            "game_ids": ["14"]
        }
    }
    read.side_effect = [async_return_value(create_message(request)), async_return_value(b"", 10)]
    plugin.get_unlocked_achievements.return_value = async_return_value([
        Achievement(achievement_id="lvl10", unlock_time=1548421241),
        Achievement(achievement_name="Got level 20", unlock_time=1548422395),
        Achievement(achievement_id="lvl30", achievement_name="Got level 30", unlock_time=1548495633)
    ])
    await plugin.run()
    plugin.prepare_achievements_context.assert_called_with(["14"])
    plugin.get_unlocked_achievements.assert_called_with("14", 5)
    plugin.achievements_import_complete.asert_called_with()

    assert get_messages(write) == [
        {
            "jsonrpc": "2.0",
            "id": "3",
            "result": None
        },
        {
            "jsonrpc": "2.0",
            "method": "game_achievements_import_success",
            "params": {
                "game_id": "14",
                "unlocked_achievements": [
                    {
                        "achievement_id": "lvl10",
                        "unlock_time": 1548421241
                    },
                    {
                        "achievement_name": "Got level 20",
                        "unlock_time": 1548422395
                    },
                    {
                        "achievement_id": "lvl30",
                        "achievement_name": "Got level 30",
                        "unlock_time": 1548495633
                    }
                ]
            }
        },
        {
            "jsonrpc": "2.0",
            "method": "achievements_import_finished",
            "params": None
        }
    ]
async def test_ping(plugin, read, write):
    request = {"jsonrpc": "2.0", "id": "7", "method": "ping"}
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"")
    ]
    await plugin.run()
    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": "7",
        "result": None
    }]
Exemplo n.º 22
0
async def test_success(plugin, read, write):
    request = {"jsonrpc": "2.0", "id": "3", "method": "import_owned_games"}
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"", 10)
    ]

    plugin.get_owned_games.return_value = async_return_value([
        Game("3", "Doom", None, LicenseInfo(LicenseType.SinglePurchase, None)),
        Game("5", "Witcher 3", [
            Dlc("7", "Hearts of Stone",
                LicenseInfo(LicenseType.SinglePurchase, None)),
            Dlc("8", "Temerian Armor Set",
                LicenseInfo(LicenseType.FreeToPlay, None)),
        ], LicenseInfo(LicenseType.SinglePurchase, None))
    ])
    await plugin.run()
    plugin.get_owned_games.assert_called_with()
    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": "3",
        "result": {
            "owned_games": [{
                "game_id": "3",
                "game_title": "Doom",
                "license_info": {
                    "license_type": "SinglePurchase"
                }
            }, {
                "game_id":
                "5",
                "game_title":
                "Witcher 3",
                "dlcs": [{
                    "dlc_id": "7",
                    "dlc_title": "Hearts of Stone",
                    "license_info": {
                        "license_type": "SinglePurchase"
                    }
                }, {
                    "dlc_id": "8",
                    "dlc_title": "Temerian Armor Set",
                    "license_info": {
                        "license_type": "FreeToPlay"
                    }
                }],
                "license_info": {
                    "license_type": "SinglePurchase"
                }
            }]
        }
    }]
async def test_get_subscription_games_success_empty(plugin, read, write):
    plugin.prepare_subscription_games_context.return_value = async_return_value(5)
    request = {
        "jsonrpc": "2.0",
        "id": "3",
        "method": "start_subscription_games_import",
        "params": {
            "subscription_names": ["sub_a"]
        }
    }
    read.side_effect = [async_return_value(create_message(request)), async_return_value(b"", 10)]

    async def sub_games():
        yield None

    plugin.get_subscription_games.return_value = sub_games()
    await plugin.run()
    plugin.prepare_subscription_games_context.assert_called_with(["sub_a"])
    plugin.get_subscription_games.assert_called_with("sub_a", 5)
    plugin.subscription_games_import_complete.asert_called_with()

    assert get_messages(write) == [
        {
            "jsonrpc": "2.0",
            "id": "3",
            "result": None
        },
        {
            "jsonrpc": "2.0",
            "method": "subscription_games_import_success",
            "params": {
                "subscription_name": "sub_a",
                "subscription_games": None
            }
        },
        {
            'jsonrpc': '2.0',
            'method':
                'subscription_games_partial_import_finished',
                'params': {
                    "subscription_name": "sub_a"
                }
        },
        {
            "jsonrpc": "2.0",
            "method": "subscription_games_import_finished",
            "params": None
        }
    ]
async def test_get_subscription_games_error(exception, code, message, internal_type, plugin, read, write):
    plugin.prepare_subscription_games_context.return_value = async_return_value(None)
    request = {
        "jsonrpc": "2.0",
        "id": "3",
        "method": "start_subscription_games_import",
        "params": {
            "subscription_names": ["sub_a"]
        }
    }

    read.side_effect = [async_return_value(create_message(request)), async_return_value(b"", 10)]
    plugin.get_subscription_games.side_effect = exception
    await plugin.run()
    plugin.get_subscription_games.assert_called()
    plugin.subscription_games_import_complete.asert_called_with()

    assert get_messages(write) == [
        {
            "jsonrpc": "2.0",
            "id": "3",
            "result": None
        },
        {
            "jsonrpc": "2.0",
            "method": "subscription_games_import_failure",
            "params": {
                "subscription_name": "sub_a",
                "error": {
                    "code": code,
                    "message": message,
                    "data": {"internal_type": internal_type}
                }
            }
        },
        {
            'jsonrpc': '2.0',
            'method':
                'subscription_games_partial_import_finished',
                'params': {
                    "subscription_name": "sub_a"
                }
        },
        {
            "jsonrpc": "2.0",
            "method": "subscription_games_import_finished",
            "params": None
        }
    ]
Exemplo n.º 25
0
async def test_initialize_cache(plugin, read, write, cache_data):
    request_id = 3
    request = {
        "jsonrpc": "2.0",
        "id": str(request_id),
        "method": "initialize_cache",
        "params": {"data": cache_data}
    }
    read.side_effect = [async_return_value(create_message(request)), async_return_value(b"")]

    assert {} == plugin.persistent_cache
    await plugin.run()
    plugin.handshake_complete.assert_called_once_with()
    assert cache_data == plugin.persistent_cache
    assert_rpc_response(write, response_id=request_id)
async def test_success(plugin, read):
    request = {
        "jsonrpc": "2.0",
        "method": "uninstall_game",
        "params": {
            "game_id": "3"
        }
    }
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"")
    ]
    plugin.get_owned_games.return_value = None
    await plugin.run()
    plugin.uninstall_game.assert_called_with(game_id="3")
async def test_stored_credentials(plugin, read, write):
    request = {
        "jsonrpc": "2.0",
        "id": "3",
        "method": "init_authentication",
        "params": {
            "stored_credentials": {
                "token": "ABC"
            }
        }
    }
    read.side_effect = [async_return_value(create_message(request)), async_return_value(b"", 10)]
    plugin.authenticate.return_value = async_return_value(Authentication("132", "Zenek"))
    await plugin.run()
    plugin.authenticate.assert_called_with(stored_credentials={"token": "ABC"})
    write.assert_called()
Exemplo n.º 28
0
async def test_get_user_presence_error(exception, code, message, internal_type,
                                       plugin, read, write):
    user_id = "69"
    request_id = "55"
    plugin.prepare_user_presence_context.return_value = async_return_value(
        None)
    request = {
        "jsonrpc": "2.0",
        "id": request_id,
        "method": "start_user_presence_import",
        "params": {
            "user_id_list": [user_id]
        }
    }
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"", 10)
    ]
    plugin.get_user_presence.side_effect = exception
    await plugin.run()
    plugin.get_user_presence.assert_called()
    plugin.user_presence_import_complete.assert_called_once_with()

    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": request_id,
        "result": None
    }, {
        "jsonrpc": "2.0",
        "method": "user_presence_import_failure",
        "params": {
            "user_id": user_id,
            "error": {
                "code": code,
                "message": message,
                "data": {
                    "internal_type": internal_type
                }
            }
        }
    }, {
        "jsonrpc": "2.0",
        "method": "user_presence_import_finished",
        "params": None
    }]
Exemplo n.º 29
0
async def test_failure(plugin, read, write, error, code, message):
    request = {"jsonrpc": "2.0", "id": "3", "method": "import_local_games"}
    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"")
    ]
    plugin.get_local_games.side_effect = error()
    await plugin.run()
    plugin.get_local_games.assert_called_with()

    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": "3",
        "error": {
            "code": code,
            "message": message
        }
    }]
Exemplo n.º 30
0
async def test_failure(plugin, read, write):
    request = {"jsonrpc": "2.0", "id": "3", "method": "import_owned_games"}

    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"", 10)
    ]
    plugin.get_owned_games.side_effect = UnknownError()
    await plugin.run()
    plugin.get_owned_games.assert_called_with()
    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": "3",
        "error": {
            "code": 0,
            "message": "Unknown error"
        }
    }]
Exemplo n.º 31
0
def populate_queue_with_email_msg(mocker,
                                  app_,
                                  email_notification,
                                  queue_name='test-queue'):
    boto3.setup_default_session(region_name=app_.config['AWS_REGION'])
    sqs_connection = create_sqs_connection()
    sqs_resource = create_sqs_resource(app_.config['AWS_REGION'])
    queue = create_queue(sqs_connection, queue_name)
    msg = create_message(app_.config, sqs_resource, queue, "email", email_notification)

    def _receive(MaxNumberOfMessages=1, VisibilityTimeout=60, MessageAttributeNames=[]):
        return [msg]

    setattr(queue, 'receive_messages', _receive)

    def _get(config, queue_name_prefix=''):
        return [queue]

    mocker.patch(
        'notifications_delivery.processor.sqs_processor._get_all_queues', side_effect=_get)
    return queue