-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathauthorization_request_serdeser_test.py
More file actions
64 lines (50 loc) · 2.44 KB
/
Copy pathauthorization_request_serdeser_test.py
File metadata and controls
64 lines (50 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import unittest
import json
from serdesertest.util.serdeser_json_resolver_utility import JsonTemplateResolver
# Import the classes being tested
from conductor.client.http.models.authorization_request import AuthorizationRequest
class TestAuthorizationRequestSerDes(unittest.TestCase):
"""
Unit tests for serialization and deserialization of AuthorizationRequest model.
"""
def setUp(self):
"""Set up test fixtures."""
# Load the template JSON for testing
self.server_json_str = JsonTemplateResolver.get_json_string("AuthorizationRequest")
self.server_json = json.loads(self.server_json_str)
def test_serialization_deserialization(self):
"""Test complete serialization and deserialization process."""
# Create the authorization request object directly from JSON
# The model's __init__ should handle the nested objects
auth_request = AuthorizationRequest(
subject=self.server_json.get('subject'),
target=self.server_json.get('target'),
access=self.server_json.get('access')
)
# Verify model is properly initialized
self.assertIsNotNone(auth_request, "Deserialized object should not be null")
# Verify access list
self.assertIsNotNone(auth_request.access, "Access list should not be null")
self.assertTrue(all(access in ["CREATE", "READ", "UPDATE", "DELETE", "EXECUTE"]
for access in auth_request.access))
# Verify subject and target are present
self.assertIsNotNone(auth_request.subject, "Subject should not be null")
self.assertIsNotNone(auth_request.target, "Target should not be null")
# Serialize back to dictionary
result_dict = auth_request.to_dict()
# Verify structure matches the original
self.assertEqual(
set(self.server_json.keys()),
set(result_dict.keys()),
"Serialized JSON should have the same keys as the original"
)
# Convert both to JSON strings and compare (similar to objectMapper.readTree)
original_json_normalized = json.dumps(self.server_json, sort_keys=True)
result_json_normalized = json.dumps(result_dict, sort_keys=True)
self.assertEqual(
original_json_normalized,
result_json_normalized,
"Serialized JSON should match the original SERVER_JSON"
)
if __name__ == '__main__':
unittest.main()