def backend_client(): mock = MagicMock(spec=()) mock.get_display_name = MagicMock() mock.get_users_info = AsyncMock() mock.get_assets = AsyncMock() mock.get_catalog_items_with_id = AsyncMock() mock.get_owned_games = AsyncMock() mock.get_productmapping = AsyncMock() mock.get_productmapping.return_value = PRODUCT_MAPPING_RESPONSE return mock
def http_client(account_id, refresh_token, authenticated): mock = MagicMock(spec=()) type(mock).account_id = account_id type(mock).refresh_token = refresh_token type(mock).authenticated = authenticated mock.authenticate_with_exchange_code = AsyncMock() mock.authenticate_with_refresh_token = AsyncMock() mock.retrieve_exchange_code = AsyncMock() mock.close = AsyncMock() mock.set_auth_lost_callback = MagicMock() return mock
def it_returns_ip_from_which_the_response_was_received(): sock = AsyncMock() resp = b'HTTP/1.1 200 OK\r\nLOCATION: http://192.168.0.1:1900/igd.xml\r\n' sock.recvfrom.async_return_value = (resp, ('192.168.0.1', 1900)) with patch('curio.socket.socket', MagicMock(return_value=sock)): _, igd_ip = curio.run(ssdp._make_ssdp_request()) assert_that(igd_ip, is_('192.168.0.1'))
async def test_middlewares(settings): middleware = AsyncMock() settings.MIDDLEWARES = [middleware] engine = BaseEngine() engine.discovery_view = mock.Mock(return_value=lambda x: True) await engine.get_response('ping') assert middleware.call_count == 1
def it_collects_port_mappings_by_index_until_index_argument_error_is_raised( ): gateway = Gateway('http://dummy/igd', '192.168.1.100') gateway.get_port_mapping = AsyncMock( async_side_effect=[1, 2, 3, soap.InvalidArgsError(402, '')]) mappings = curio.run(gateway.get_port_mappings) assert_that(mappings, is_([1, 2, 3]))
def it_returns_successfull_responses(): resp = MagicMock(content=b'xml', status_code=200) with patch('asks.post', AsyncMock(async_return_value=resp)): soap_resp = curio.run( soap.post, 'http://192.168.0.1:1900/ipc', '<xml></xml>', '"urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIpAddress"' ) assert_that(soap_resp.status_code, is_(200)) assert_that(soap_resp.body, is_(b'xml'))
def test_run_jobs_manager(self): t = self.broker.update_job_state self.broker.update_job_state = AsyncMock(return_value=dict( test='test')) self.loop.create_task(self.broker.run_jobs_manager()) async def check_job_data(): job_data = await self.broker.jobs_queue.get() self.assertEqual(job_data['test'], 'test') self.loop.run_until_complete(check_job_data()) self.broker.update_job_state = t
def api(): session = AsyncMock() return MessengerAPI('token', session)