|
1 | 1 | from scim2_models import Mutability |
2 | | -from scim2_models import Resource |
3 | 2 | from scim2_models import ResourceType |
4 | 3 |
|
5 | 4 | from scim2_tester.filling import fill_with_random_values |
| 5 | +from scim2_tester.resource_delete import check_object_deletion |
| 6 | +from scim2_tester.resource_get import check_object_query |
| 7 | +from scim2_tester.resource_get import check_object_query_without_id |
| 8 | +from scim2_tester.resource_get import model_from_resource_type |
| 9 | +from scim2_tester.resource_post import check_object_creation |
| 10 | +from scim2_tester.resource_put import check_object_replacement |
6 | 11 | from scim2_tester.utils import CheckConfig |
7 | 12 | from scim2_tester.utils import CheckResult |
8 | 13 | from scim2_tester.utils import Status |
9 | | -from scim2_tester.utils import checker |
10 | | - |
11 | | - |
12 | | -def model_from_resource_type( |
13 | | - conf: CheckConfig, resource_type: ResourceType |
14 | | -) -> type[Resource] | None: |
15 | | - for resource_model in conf.client.resource_models: |
16 | | - if resource_model.model_fields["schemas"].default[0] == resource_type.schema_: |
17 | | - return resource_model |
18 | | - |
19 | | - return None |
20 | | - |
21 | | - |
22 | | -@checker |
23 | | -def check_object_creation(conf: CheckConfig, obj: type[Resource]) -> CheckResult: |
24 | | - """Perform an object creation. |
25 | | -
|
26 | | - Todo: |
27 | | - - check if the fields of the result object are the same than the |
28 | | - fields of the request object |
29 | | -
|
30 | | - """ |
31 | | - response = conf.client.create( |
32 | | - obj, expected_status_codes=conf.expected_status_codes or [201] |
33 | | - ) |
34 | | - |
35 | | - return CheckResult( |
36 | | - conf, |
37 | | - status=Status.SUCCESS, |
38 | | - reason=f"Successful creation of a {obj.__class__.__name__} object with id {response.id}", |
39 | | - data=response, |
40 | | - ) |
41 | | - |
42 | | - |
43 | | -@checker |
44 | | -def check_object_query(conf: CheckConfig, obj: type[Resource]) -> CheckResult: |
45 | | - """Perform an object query by knowing its id. |
46 | | -
|
47 | | - Todo: |
48 | | - - check if the fields of the result object are the same than the |
49 | | - fields of the request object |
50 | | -
|
51 | | - """ |
52 | | - response = conf.client.query( |
53 | | - obj.__class__, obj.id, expected_status_codes=conf.expected_status_codes or [200] |
54 | | - ) |
55 | | - return CheckResult( |
56 | | - conf, |
57 | | - status=Status.SUCCESS, |
58 | | - reason=f"Successful query of a {obj.__class__.__name__} object with id {response.id}", |
59 | | - data=response, |
60 | | - ) |
61 | | - |
62 | | - |
63 | | -@checker |
64 | | -def check_object_query_without_id( |
65 | | - conf: CheckConfig, obj: type[Resource] |
66 | | -) -> CheckResult: |
67 | | - """Perform the query of all objects of one kind. |
68 | | -
|
69 | | - Todo: |
70 | | - - look for the object across several pages |
71 | | - - check if the fields of the result object are the same than the |
72 | | - fields of the request object |
73 | | -
|
74 | | - """ |
75 | | - response = conf.client.query( |
76 | | - obj.__class__, expected_status_codes=conf.expected_status_codes or [200] |
77 | | - ) |
78 | | - found = any(obj.id == resource.id for resource in response.resources) |
79 | | - if not found: |
80 | | - return CheckResult( |
81 | | - conf, |
82 | | - status=Status.ERROR, |
83 | | - reason=f"Could not find object {obj.__class__.__name__} with id : {obj.id}", |
84 | | - data=response, |
85 | | - ) |
86 | | - |
87 | | - return CheckResult( |
88 | | - conf, |
89 | | - status=Status.SUCCESS, |
90 | | - reason=f"Successful query of a {obj.__class__.__name__} object with id {obj.id}", |
91 | | - data=response, |
92 | | - ) |
93 | | - |
94 | | - |
95 | | -@checker |
96 | | -def check_object_replacement(conf: CheckConfig, obj: type[Resource]) -> CheckResult: |
97 | | - """Perform an object replacement. |
98 | | -
|
99 | | - Todo: |
100 | | - - check if the fields of the result object are the same than the |
101 | | - fields of the request object |
102 | | -
|
103 | | - """ |
104 | | - response = conf.client.replace( |
105 | | - obj, expected_status_codes=conf.expected_status_codes or [200] |
106 | | - ) |
107 | | - return CheckResult( |
108 | | - conf, |
109 | | - status=Status.SUCCESS, |
110 | | - reason=f"Successful replacement of a {obj.__class__.__name__} object with id {response.id}", |
111 | | - data=response, |
112 | | - ) |
113 | | - |
114 | | - |
115 | | -@checker |
116 | | -def check_object_deletion(conf: CheckConfig, obj: type[Resource]) -> CheckResult: |
117 | | - """Perform an object deletion.""" |
118 | | - conf.client.delete( |
119 | | - obj.__class__, obj.id, expected_status_codes=conf.expected_status_codes or [204] |
120 | | - ) |
121 | | - return CheckResult( |
122 | | - conf, |
123 | | - status=Status.SUCCESS, |
124 | | - reason=f"Successful deletion of a {obj.__class__.__name__} object with id {obj.id}", |
125 | | - ) |
126 | 14 |
|
127 | 15 |
|
128 | 16 | def check_resource_type( |
|
0 commit comments