async def test_get_torrent(core): request = await test_post_torrent(core) request.match_info = {} torrents, response = await json_response(torrent.get_torrent(request)) assert isinstance(torrents, list) assert len(torrents) > 0 request.match_info['tid'] = '44a040be6d74d8d290cd20128788864cbf770719' ts, response = await json_response(torrent.get_torrent(request)) assert isinstance(ts, dict) assert ts['info_hash'] == '44a040be6d74d8d290cd20128788864cbf770719' assert ts['spritzle.tags'] == ['foo'] with pytest.raises(aiohttp.web.HTTPNotFound): request.match_info['tid'] = 'a0'*20 _, response = await torrent.get_torrent(request) assert response.status == 404
async def test_get_torrent(): await test_post_torrent() request = MagicMock() request.match_info = {} torrents, response = await json_response(torrent.get_torrent(request)) assert isinstance(torrents, list) assert len(torrents) > 0 request.match_info['tid'] = '44a040be6d74d8d290cd20128788864cbf770719' ts, response = await json_response(torrent.get_torrent(request)) assert isinstance(ts, dict) assert ts['info_hash'] == '44a040be6d74d8d290cd20128788864cbf770719' with assert_raises(aiohttp.errors.HttpProcessingError) as e: request.match_info['tid'] = 'a0'*20 await torrent.get_torrent(request) assert e.exception.code == 404
async def test_post_torrent(): request = create_mock_request(filename='random_one_file.torrent') body, response = await json_response(torrent.post_torrent(request)) assert 'info_hash' in body info_hash = body['info_hash'] assert response.headers['LOCATION'] == \ 'http://localhost:8080/torrent/{}'.format(info_hash) assert response.status == 201 assert info_hash == '44a040be6d74d8d290cd20128788864cbf770719' request = MagicMock() request.match_info = {} tlist, response = await json_response(torrent.get_torrent(request)) assert tlist == ['44a040be6d74d8d290cd20128788864cbf770719']
async def test_post_torrent(core): request = await create_mock_request(core=core, filename='random_one_file.torrent', tags=['foo']) body, response = await json_response(torrent.post_torrent(request)) assert 'info_hash' in body info_hash = body['info_hash'] assert response.headers['LOCATION'] == \ f'http://localhost:8080/torrent/{info_hash}' assert response.status == 201 assert info_hash == '44a040be6d74d8d290cd20128788864cbf770719' request.match_info = {} tlist, response = await json_response(torrent.get_torrent(request)) assert tlist == ['44a040be6d74d8d290cd20128788864cbf770719'] return request