def test_set_allowing_duplicates_with_given_data(): headers = Headers({ "a-a": [{ 'key': 'a-a', 'value': 'bar', }], "a-A": [{ 'key': 'a-A', 'value': 'howdy', }], }) headers.set(name="A-a", value="yoyo", adjust_case_to_allow_duplicates=True) assert headers.to_dict() == { "a-a": [{ 'key': 'a-a', 'value': 'bar', }], "a-A": [{ 'key': 'a-A', 'value': 'howdy', }], "A-a": [{ 'key': 'A-a', 'value': 'yoyo', }], }
def test_set_allowing_duplicates_left_of_hyphen(): headers = Headers() headers.set(name="a-a", value="bar", adjust_case_to_allow_duplicates=True) headers.set(name="A-A", value="howdy", adjust_case_to_allow_duplicates=True) headers.set(name="A-a", value="yoyo", adjust_case_to_allow_duplicates=True) headers.set(name="a-A", value="boo", adjust_case_to_allow_duplicates=True) assert headers.to_dict() == { "a-a": [{ 'key': 'a-a', 'value': 'bar', }], "a-A": [{ 'key': 'a-A', 'value': 'howdy', }], "A-a": [{ 'key': 'A-a', 'value': 'yoyo', }], "A-A": [{ 'key': 'A-A', 'value': 'boo', }], } with pytest.raises(RuntimeError, match=r".*no more case variants.*"): headers.set(name="a-a", value="yoyo", adjust_case_to_allow_duplicates=True)
def test_set_existing_header(): headers = Headers({'foo': [{ 'key': 'foo', 'value': 'orig-foo-value', }]}) assert headers.get_value(name='foo') == 'orig-foo-value' headers.set(name='foo', value='new-foo-value') assert headers.get_value(name='foo') == 'new-foo-value'
def test_set_new_header(): headers = Headers({ 'existing-header': [{ 'key': 'existing-header', 'value': 'existing-value', }] }) headers.set(name='foo', value='bar') assert headers.get(name='foo') == [{'key': 'foo', 'value': 'bar'}] assert headers.get_value(name='existing-header') == 'existing-value'
def test_Headers_overlays_given_data(): orig_data = { 'foo': [{ 'key': 'foo', 'value': 'orig-foo-value', }] } headers = Headers(data=orig_data) assert headers.get_value(name='foo') == 'orig-foo-value' headers.set(name='foo', value='new-foo-value') assert headers.get_value(name='foo') == 'new-foo-value' assert orig_data['foo'][0]['value'] == 'new-foo-value'
def test_set_allowing_duplicates(): headers = Headers() headers.set(name="Set-Cookie", value="bar", adjust_case_to_allow_duplicates=True) headers.set(name="Set-Cookie", value="howdy", adjust_case_to_allow_duplicates=True) headers.set(name="Set-Cookie", value="yoyo", adjust_case_to_allow_duplicates=True) assert headers.to_dict() == { "set-cookie": [{ 'key': 'set-cookie', 'value': 'bar', }], "set-cookiE": [{ 'key': 'set-cookiE', 'value': 'howdy', }], "set-cookIe": [{ 'key': 'set-cookIe', 'value': 'yoyo', }], }
def test_set_allowing_duplicates_but_none_left(): headers = Headers() headers.set(name="a", value="bar", adjust_case_to_allow_duplicates=True) headers.set(name="A", value="howdy", adjust_case_to_allow_duplicates=True) with pytest.raises(RuntimeError, match=r".*no more case variants.*"): headers.set(name="a", value="yoyo", adjust_case_to_allow_duplicates=True)