|
6 | 6 |
|
7 | 7 | from docker_registry.core import compat
|
8 | 8 | import docker_registry.images as images
|
| 9 | +import docker_registry.lib.signals as signals |
9 | 10 |
|
10 | 11 | json = compat.json
|
11 | 12 |
|
@@ -79,3 +80,37 @@ def test_bytes_range(self):
|
79 | 80 | msg = 'expected size: {0}; got: {1}'.format(len(expected_data),
|
80 | 81 | len(received_data))
|
81 | 82 | self.assertEqual(expected_data, received_data, msg)
|
| 83 | + |
| 84 | + def before_put_image_json_handler_ok(self, sender, image_json): |
| 85 | + return None |
| 86 | + |
| 87 | + def before_put_image_json_handler_not_ok(self, sender, image_json): |
| 88 | + return "Not ok" |
| 89 | + |
| 90 | + def test_before_put_image_json_ok(self): |
| 91 | + image_id = self.gen_random_string() |
| 92 | + json_obj = { |
| 93 | + 'id': image_id |
| 94 | + } |
| 95 | + json_data = compat.json.dumps(json_obj) |
| 96 | + with signals.before_put_image_json.connected_to( |
| 97 | + self.before_put_image_json_handler_ok): |
| 98 | + resp = self.http_client.put('/v1/images/{0}/json'.format(image_id), |
| 99 | + data=json_data) |
| 100 | + self.assertEqual(resp.status_code, 200, resp.data) |
| 101 | + |
| 102 | + def test_before_put_image_json_not_ok(self): |
| 103 | + image_id = self.gen_random_string() |
| 104 | + json_obj = { |
| 105 | + 'id': image_id |
| 106 | + } |
| 107 | + json_data = compat.json.dumps(json_obj) |
| 108 | + with signals.before_put_image_json.connected_to( |
| 109 | + self.before_put_image_json_handler_not_ok): |
| 110 | + resp = self.http_client.put('/v1/images/{0}/json'.format(image_id), |
| 111 | + data=json_data) |
| 112 | + resp_data = json.loads(resp.data) |
| 113 | + self.assertEqual(resp.status_code, 400, resp.data) |
| 114 | + self.assertTrue('error' in resp_data, |
| 115 | + 'Expected error key in response') |
| 116 | + self.assertEqual(resp_data['error'], 'Not ok', resp.data) |
0 commit comments