-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
114 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pytest | |
pytest-cov | ||
coverage | ||
coveralls | ||
pytest-aiohttp>=0.1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
aiohttp>=2.0.1 | ||
aiohttp>=2.2.0 | ||
pyyaml | ||
lxml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,31 @@ | ||
# coding=utf-8 | ||
|
||
import pytest | ||
import json | ||
|
||
import asyncio | ||
import random | ||
|
||
from xpaw import HttpRequest | ||
from xpaw.downloader import Downloader, DownloaderMiddlewareManager | ||
from xpaw.downloadermws import CookieJarMiddleware | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def loop(request): | ||
def close(): | ||
loop.close() | ||
|
||
loop = asyncio.new_event_loop() | ||
asyncio.set_event_loop(loop) | ||
request.addfinalizer(close) | ||
return loop | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def downloader(loop): | ||
return Downloader(timeout=20, loop=loop) | ||
|
||
|
||
def test_cookies(downloader, loop): | ||
req = HttpRequest("http://httpbin.org/cookies", cookies={"k1": "v1", "k2": "v2"}) | ||
resp = loop.run_until_complete(downloader.download(req)) | ||
async def test_cookies(loop): | ||
downloader = Downloader(timeout=20, loop=loop) | ||
seed = str(random.randint(0, 2147483647)) | ||
req = HttpRequest("http://httpbin.org/cookies", cookies={"seed": seed}) | ||
resp = await downloader.download(req) | ||
cookies = json.loads(resp.text)["cookies"] | ||
assert len(cookies) == 2 and cookies.get("k1") == "v1" and cookies.get("k2") == "v2" | ||
assert len(cookies) == 1 and cookies.get("seed") == seed | ||
|
||
|
||
def test_cookie_jar(downloader, loop): | ||
async def test_cookie_jar(loop): | ||
downloader = Downloader(timeout=20, loop=loop) | ||
dmm = DownloaderMiddlewareManager(CookieJarMiddleware(loop=loop)) | ||
loop.run_until_complete(dmm.download(downloader, HttpRequest("http://httpbin.org/cookies/set?k1=v1&k2=v2"))) | ||
resp = loop.run_until_complete(dmm.download(downloader, HttpRequest("http://httpbin.org/cookies"))) | ||
seed = str(random.randint(0, 2147483647)) | ||
await dmm.download(downloader, HttpRequest("http://httpbin.org/cookies/set?seed={}".format(seed))) | ||
resp = await dmm.download(downloader, HttpRequest("http://httpbin.org/cookies")) | ||
cookies = json.loads(resp.text)["cookies"] | ||
assert len(cookies) == 2 and cookies.get("k1") == "v1" and cookies.get("k2") == "v2" | ||
loop.run_until_complete(dmm.download(downloader, HttpRequest("http://httpbin.org/cookies/delete?k1="))) | ||
resp = loop.run_until_complete(dmm.download(downloader, HttpRequest("http://httpbin.org/cookies"))) | ||
assert len(cookies) == 1 and cookies.get("seed") == seed | ||
await dmm.download(downloader, HttpRequest("http://httpbin.org/cookies/delete?seed=")) | ||
resp = await dmm.download(downloader, HttpRequest("http://httpbin.org/cookies")) | ||
cookies = json.loads(resp.text)["cookies"] | ||
assert len(cookies) == 1 and cookies.get("k2") == "v2" | ||
assert len(cookies) == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.