diff --git a/form2request/_base.py b/form2request/_base.py index 39666e6..9299e71 100644 --- a/form2request/_base.py +++ b/form2request/_base.py @@ -31,7 +31,8 @@ def _enctype( enctype = enctype.lower() if enctype not in {"application/x-www-form-urlencoded", "text/plain"}: raise ValueError( - f"The specified form enctype ({enctype!r}) is not supported." + f"The specified form enctype ({enctype!r}) is not supported " + f"for forms with the POST method." ) elif click_element is not None and ( enctype := (click_element.get("formenctype") or "").lower() @@ -39,12 +40,16 @@ def _enctype( if enctype == "multipart/form-data": raise NotImplementedError( f"{click_element} has formenctype set to {enctype!r}, which " - f"form2request does not currently support." + f"form2request does not currently support for forms with the " + f"POST method." ) elif ( enctype := (form.get("enctype") or "").lower() ) and enctype == "multipart/form-data": - raise NotImplementedError(f"Found unsupported form enctype {enctype!r}.") + raise NotImplementedError( + f"{form} has enctype set to {enctype!r}, which form2request does " + f"not currently support for forms with the POST method." + ) return enctype diff --git a/tests/test_main.py b/tests/test_main.py index e5bda82..e968502 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -226,60 +226,71 @@ "foo", ) ), - # multipart/form-data raises a NotImplementedError exception. - *( - ( - "https://example.com", - f"""
""".encode(), - {}, - NotImplementedError, - ) - for enctype in ("multipart/form-data",) + # multipart/form-data raises a NotImplementedError exception when the + # method is POST. + ( + "https://example.com", + b"""""", + {}, + NotImplementedError, + ), + # multipart/form-data does work when method is GET (default). + ( + "https://example.com", + b"""""", + {}, + Request( + "https://example.com?a=b", + "GET", + [], + b"", + ), ), # The formenctype from the submit button is taken into account, even if # it has an unknown value. ( "https://example.com", - b"""""", {}, Request( "https://example.com", - "GET", - [], + "POST", + [("Content-Type", "application/x-www-form-urlencoded")], b"", ), ), ( "https://example.com", - b"""""", {}, Request( "https://example.com", - "GET", - [], + "POST", + [("Content-Type", "application/x-www-form-urlencoded")], b"", ), ), ( "https://example.com", - b"""""", + b"""""", {}, NotImplementedError, ), # enctype may be overridden, in which case it raises ValueError for - # both unknown and unsupported values. + # both unknown and unsupported values when method is POST. ( "https://example.com", - b"""""", + b"""""", {"enctype": "multipart/form-data"}, ValueError, ), ( "https://example.com", - b"""""", + b"""""", {"enctype": "a"}, ValueError, ), @@ -709,8 +720,8 @@ ), ( "https://example.com", - b"""""", + b"""""", {}, NotImplementedError, ),