| 723 | |
| 724 | |
| 725 | def test_common_response_descriptors(): |
| 726 | response = wrappers.Response() |
| 727 | response.mimetype = "text/html" |
| 728 | assert response.mimetype == "text/html" |
| 729 | assert response.content_type == "text/html; charset=utf-8" |
| 730 | assert response.mimetype_params == {"charset": "utf-8"} |
| 731 | response.mimetype_params["x-foo"] = "yep" |
| 732 | del response.mimetype_params["charset"] |
| 733 | assert response.content_type == "text/html; x-foo=yep" |
| 734 | |
| 735 | now = datetime.now(timezone.utc).replace(microsecond=0) |
| 736 | |
| 737 | assert response.content_length is None |
| 738 | response.content_length = "42" |
| 739 | assert response.content_length == 42 |
| 740 | |
| 741 | for attr in "date", "expires": |
| 742 | assert getattr(response, attr) is None |
| 743 | setattr(response, attr, now) |
| 744 | assert getattr(response, attr) == now |
| 745 | |
| 746 | assert response.age is None |
| 747 | age_td = timedelta(days=1, minutes=3, seconds=5) |
| 748 | response.age = age_td |
| 749 | assert response.age == age_td |
| 750 | response.age = 42 |
| 751 | assert response.age == timedelta(seconds=42) |
| 752 | |
| 753 | assert response.retry_after is None |
| 754 | response.retry_after = now |
| 755 | assert response.retry_after == now |
| 756 | |
| 757 | assert not response.vary |
| 758 | response.vary.add("Cookie") |
| 759 | response.vary.add("Content-Language") |
| 760 | assert "cookie" in response.vary |
| 761 | assert response.vary.to_header() == "Cookie, Content-Language" |
| 762 | response.headers["Vary"] = "Content-Encoding" |
| 763 | assert response.vary.as_set() == {"content-encoding"} |
| 764 | |
| 765 | response.allow.update(["GET", "POST"]) |
| 766 | assert response.headers["Allow"] == "GET, POST" |
| 767 | |
| 768 | response.content_language.add("en-US") |
| 769 | response.content_language.add("fr") |
| 770 | assert response.headers["Content-Language"] == "en-US, fr" |
| 771 | |
| 772 | |
| 773 | def test_common_request_descriptors(): |