Debian Codegraph @

tests/unit/test_resource_options.py

raw symbols SCIP
1 # Copyright 2015 Vladimir Rutsky <[email protected]>
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 """aiohttp_cors.resource_options unit tests."""
16
17 import pytest
18
19 from aiohttp_cors.resource_options import ResourceOptions
20
21
22 def test_init_no_args():
23 """Test construction without arguments"""
24 opts = ResourceOptions()
25
26 assert not opts.allow_credentials
27 assert not opts.expose_headers
28 assert not opts.allow_headers
29 assert opts.max_age is None
30
31
32 def test_comparison():
33 assert ResourceOptions() == ResourceOptions()
34 assert not (ResourceOptions() != ResourceOptions())
35 assert not (ResourceOptions(allow_credentials=True) == ResourceOptions())
36 assert ResourceOptions(allow_credentials=True) != ResourceOptions()
37
38
39 def test_allow_methods():
40 assert ResourceOptions().allow_methods is None
41 assert ResourceOptions(allow_methods="*").allow_methods == "*"
42 assert ResourceOptions(allow_methods=[]).allow_methods == frozenset()
43 assert ResourceOptions(allow_methods=["get"]).allow_methods == frozenset(["GET"])
44 assert ResourceOptions(allow_methods=["get", "Post"]).allow_methods == {
45 "GET",
46 "POST",
47 }
48 with pytest.raises(ValueError):
49 ResourceOptions(allow_methods="GET")
50
51
52 # TODO: test arguments parsing