@@ -74,41 +74,49 @@ class MockSchemaRegistryClient(SchemaRegistryClient):
74
74
not match MockSchemaRegistryClient.USERINFO.
75
75
76
76
Request paths to trigger exceptions:
77
- +--------+----------------------------------+-------+------------------------------+
78
- | Method | Request Path | Code | Description |
79
- +========+==================================+=======+==============================+
80
- | GET | /schemas/ids/404 | 40403 | Schema not found |
81
- +--------+----------------------------------+-------+------------------------------+
82
- | GET | /subjects/notfound/versions | 40401 | Subject not found |
83
- +--------+----------------------------------+-------+------------------------------+
84
- | GET | /subjects/notfound/versions/[0-9]| 40401 | Subject not found |
85
- +--------+----------------------------------+-------+------------------------------+
86
- | GET | /subjects/notfound/versions/404 | 40402 | Version not found |
87
- +--------+----------------------------------+-------+------------------------------+
88
- | GET | /subjects/notfound/versions/422 | 42202 | Invalid version |
89
- +--------+----------------------------------+-------+------------------------------+
90
- | DELETE | /subjects/notfound | 40401 | Subject not found |
91
- +--------+----------------------------------+-------+------------------------------+
92
- | POST | /subjects/conflict/versions | 409* | Incompatible Schema |
93
- +--------+----------------------------------+-------+------------------------------+
94
- | POST | /subjects/invalid/versions | 42201 | Invalid Schema |
95
- +--------+----------------------------------+-------+------------------------------+
96
- | POST | /subjects/notfound | 40401 | Subject not found |
97
- +--------+----------------------------------+-------+------------------------------+
98
- | POST | /subjects/schemanotfound | 40403 | Schema not found |
99
- +--------+----------------------------------+-------+------------------------------+
100
- | DELETE | /subjects/notfound | 40401 | Subject not found |
101
- +--------+----------------------------------+-------+------------------------------+
102
- | DELETE | /subjects/notfound/versions/[0-9]| 40401 | Subject not found |
103
- +--------+----------------------------------+-------+------------------------------+
104
- | DELETE | /subjects/notfound/versions/404 | 40402 | Version not found |
105
- +--------+----------------------------------+-------+------------------------------+
106
- | DELETE | /subjects/notfound/versions/422 | 42202 | Invalid version |
107
- +--------+----------------------------------+-------+------------------------------+
108
- | GET | /config/notconfig | 40401 | Subject not found |
109
- +--------+----------------------------------+-------+------------------------------+
110
- | PUT | /config** | 42203 | Invalid compatibility level |
111
- +--------+----------------------------------+-------+------------------------------+
77
+ +--------+-------------------------------------------------+-------+------------------------------+
78
+ | Method | Request Path | Code | Description |
79
+ +========+=================================================+=======+==============================+
80
+ | GET | /schemas/ids/404 | 40403 | Schema not found |
81
+ +--------+-------------------------------------------------+-------+------------------------------+
82
+ | GET | /subjects/notfound/versions | 40401 | Subject not found |
83
+ +--------+-------------------------------------------------+-------+------------------------------+
84
+ | GET | /subjects/notfound/versions/[0-9] | 40401 | Subject not found |
85
+ +--------+-------------------------------------------------+-------+------------------------------+
86
+ | GET | /subjects/notfound/versions/404 | 40402 | Version not found |
87
+ +--------+-------------------------------------------------+-------+------------------------------+
88
+ | GET | /subjects/notfound/versions/422 | 42202 | Invalid version |
89
+ +--------+-------------------------------------------------+-------+------------------------------+
90
+ | DELETE | /subjects/notfound | 40401 | Subject not found |
91
+ +--------+-------------------------------------------------+-------+------------------------------+
92
+ | POST | /subjects/conflict/versions | 409* | Incompatible Schema |
93
+ +--------+-------------------------------------------------+-------+------------------------------+
94
+ | POST | /subjects/invalid/versions | 42201 | Invalid Schema |
95
+ +--------+-------------------------------------------------+-------+------------------------------+
96
+ | POST | /subjects/notfound | 40401 | Subject not found |
97
+ +--------+-------------------------------------------------+-------+------------------------------+
98
+ | POST | /subjects/schemanotfound | 40403 | Schema not found |
99
+ +--------+-------------------------------------------------+-------+------------------------------+
100
+ | DELETE | /subjects/notfound | 40401 | Subject not found |
101
+ +--------+-------------------------------------------------+-------+------------------------------+
102
+ | DELETE | /subjects/notfound/versions/[0-9] | 40401 | Subject not found |
103
+ +--------+-------------------------------------------------+-------+------------------------------+
104
+ | DELETE | /subjects/notfound/versions/404 | 40402 | Version not found |
105
+ +--------+-------------------------------------------------+-------+------------------------------+
106
+ | DELETE | /subjects/notfound/versions/422 | 42202 | Invalid version |
107
+ +--------+-------------------------------------------------+-------+------------------------------+
108
+ | GET | /config/notconfig | 40401 | Subject not found |
109
+ +--------+-------------------------------------------------+-------+------------------------------+
110
+ | PUT | /config** | 42203 | Invalid compatibility level |
111
+ +--------+-------------------------------------------------+-------+------------------------------+
112
+ | POST | /compatibility/subjects/notfound/versions/[0-9] | 40401 | Subject not found |
113
+ +--------+-------------------------------------------------+-------+------------------------------+
114
+ | POST | /compatibility/subjects/invalid/versions/[0-9] | 42201 | Invalid Schema |
115
+ +--------+-------------------------------------------------+-------+------------------------------+
116
+ | POST | /compatibility/subjects/notfound/versions/404 | 40402 | Version not found |
117
+ +--------+-------------------------------------------------+-------+------------------------------+
118
+ | POST | /compatibility/subjects/invalid/versions/bad | 42202 | Invalid version |
119
+ +--------+-------------------------------------------------+-------+------------------------------+
112
120
* POST /subjects/{}/versions does not follow the documented API error.
113
121
** PUT /config reacts to a trigger in the body: - {"compatibility": "FULL"}
114
122
@@ -127,6 +135,7 @@ class MockSchemaRegistryClient(SchemaRegistryClient):
127
135
subjects = re .compile ("/subjects/?(.*)$" )
128
136
subject_versions = re .compile ("/subjects/(.*)/versions/?(.*)$" )
129
137
compatibility = re .compile ("/config/?(.*)$" )
138
+ compatibility_subjects_versions = re .compile ("/compatibility/subjects/(.*)/versions/?(.*)$" )
130
139
131
140
# constants
132
141
SCHEMA_ID = 47
@@ -168,6 +177,8 @@ def __init__(self, conf):
168
177
json = self .delete_subject_version_callback )
169
178
adapter .register_uri ('POST' , self .subject_versions ,
170
179
json = self .post_subject_version_callback )
180
+ adapter .register_uri ('POST' , self .compatibility_subjects_versions ,
181
+ json = self .post_compatibility_subjects_versions_callback )
171
182
172
183
adapter .add_matcher (self ._auth_matcher )
173
184
self ._rest_client .session .mount ('http://' , adapter )
@@ -348,6 +359,40 @@ def post_subject_version_callback(self, request, context):
348
359
context .status_code = 200
349
360
return {'id' : self .SCHEMA_ID }
350
361
362
+ def post_compatibility_subjects_versions_callback (self , request , context ):
363
+ self .counter ['POST' ][request .path ] += 1
364
+
365
+ path_match = re .match (self .compatibility_subjects_versions , request .path )
366
+ subject = path_match .group (1 )
367
+ version = path_match .group (2 )
368
+
369
+ if version == '422' :
370
+ context .status_code = 422
371
+ return {'error_code' : 42202 ,
372
+ 'message' : 'Invalid version' }
373
+
374
+ if version == '404' :
375
+ context .status_code = 404
376
+ return {'error_code' : 40402 ,
377
+ 'message' : "Version not found" }
378
+
379
+ if subject == 'conflict' :
380
+ context .status_code = 200
381
+ return {'is_compatible' : False }
382
+
383
+ if subject == 'notfound' :
384
+ context .status_code = 404
385
+ return {'error_code' : 40401 ,
386
+ 'message' : 'Subject not found' }
387
+
388
+ if subject == 'invalid' :
389
+ context .status_code = 422
390
+ return {'error_code' : 42201 ,
391
+ 'message' : "Invalid Schema" }
392
+
393
+ context .status_code = 200
394
+ return {'is_compatible' : True }
395
+
351
396
352
397
@pytest .fixture (scope = "package" )
353
398
def load_avsc ():
0 commit comments