Skip to content

Commit

Permalink
Fix tests for httpx >= 0.16, closes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jan 23, 2021
1 parent 764914a commit 1cd2bac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_long_description():
"test": [
"pytest",
"pytest-asyncio",
"httpx",
"httpx>=0.16",
"starlette",
"pytest-cov",
"asgi-lifespan",
Expand Down
11 changes: 6 additions & 5 deletions test_asgi_csrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from asgi_csrf import asgi_csrf
from itsdangerous.url_safe import URLSafeSerializer
import httpx
from httpx._content_streams import MultipartStream
from httpx._multipart import MultipartStream, FileField, DataField
import json
import os
import pytest
Expand Down Expand Up @@ -232,13 +232,13 @@ async def test_multipart_failure_missing_token(csrftoken):
class FileFirstMultipartStream(MultipartStream):
def _iter_fields(self, data, files):
for name, value in files.items():
yield self.FileField(name=name, value=value)
yield FileField(name=name, value=value)
for name, value in data.items():
if isinstance(value, list):
for item in value:
yield self.DataField(name=name, value=item)
yield DataField(name=name, value=item)
else:
yield self.DataField(name=name, value=value)
yield DataField(name=name, value=value)


@pytest.mark.asyncio
Expand All @@ -252,8 +252,9 @@ async def test_multipart_failure_file_comes_before_token(csrftoken):
stream=FileFirstMultipartStream(
data={"csrftoken": csrftoken},
files={"csv": ("data.csv", "blah,foo\n1,2", "text/csv")},
boundary=None,
boundary=b"boo",
),
headers={"content-type": "multipart/form-data; boundary=boo"},
cookies={"csrftoken": csrftoken},
)
response = await client.send(request)
Expand Down

0 comments on commit 1cd2bac

Please sign in to comment.