Module: WikidataAdaptor::TestHelpers::RestApi::Properties
- Includes:
- Support
- Included in:
- WikidataAdaptor::TestHelpers::RestApi
- Defined in:
- lib/wikidata_adaptor/test_helpers/rest_api/properties.rb
Overview
WebMock stubs for Wikibase REST API properties endpoints
Instance Method Summary collapse
-
#stub_get_property(property_id, response_body = nil) ⇒ Object
GET /v1/entities/properties/:property_id.
-
#stub_get_property_invalid_property(property_id) ⇒ WebMock::RequestStub
Stub GET property request returning 400 invalid property error.
-
#stub_get_property_not_found(property_id) ⇒ WebMock::RequestStub
Stub GET property request returning 404 not found error.
-
#stub_get_property_unexpected_error(property_id) ⇒ WebMock::RequestStub
Stub GET property request returning 500 error.
-
#stub_patch_property(property_id, payload, response_body: nil) ⇒ Object
PATCH /v1/entities/properties/:property_id.
-
#stub_patch_property_unexpected_error(property_id, payload) ⇒ WebMock::RequestStub
Stub PATCH property request returning 500 error.
-
#stub_post_property(payload, response_body = nil) ⇒ Object
POST /v1/entities/properties.
-
#stub_post_property_access_denied ⇒ WebMock::RequestStub
Stub POST property request returning 403 access denied error.
-
#stub_post_property_data_policy_violation ⇒ WebMock::RequestStub
Stub POST property request returning 422 data policy violation error.
-
#stub_post_property_invalid_property(response_body = nil) ⇒ WebMock::RequestStub
Stub POST property request returning 400 invalid property error.
-
#stub_post_property_request_limit_reached ⇒ WebMock::RequestStub
Stub POST property request returning 429 request limit reached error.
-
#stub_post_property_unexpected_error(payload) ⇒ WebMock::RequestStub
Stub POST property request returning 500 error.
Methods included from Support
#load_openapi_spec, #load_path_example, #posted_item_payload_fixture, #posted_item_response_fixture, #posted_property_payload_fixture, #posted_property_response_fixture
Instance Method Details
#stub_get_property(property_id, response_body = nil) ⇒ Object
GET /v1/entities/properties/:property_id
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/wikidata_adaptor/test_helpers/rest_api/properties.rb', line 14 def stub_get_property(property_id, response_body = nil) stub_rest_api_request( :get, "/v1/entities/properties/#{property_id}", response_body: response_body || { id: property_id.to_s, type: "property", labels: { en: "instance of", fr: "est un(e)" }, descriptions: { en: "that class of which this subject is a particular example and member", fr: "classe dont ce sujet est un exemple particulier" }, aliases: { en: ["is a"], fr: ["est un"] }, statements: {} } ) end |
#stub_get_property_invalid_property(property_id) ⇒ WebMock::RequestStub
Stub GET property request returning 400 invalid property error
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/wikidata_adaptor/test_helpers/rest_api/properties.rb', line 43 def stub_get_property_invalid_property(property_id) stub_rest_api_request( :get, "/v1/entities/properties/#{property_id}", response_status: 400, response_body: { code: "invalid-property-id", message: "Not a valid property ID: {#{property_id}}" } ) end |
#stub_get_property_not_found(property_id) ⇒ WebMock::RequestStub
Stub GET property request returning 404 not found error
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/wikidata_adaptor/test_helpers/rest_api/properties.rb', line 60 def stub_get_property_not_found(property_id) stub_rest_api_request( :get, "/v1/entities/properties/#{property_id}", response_status: 404, response_body: { code: "property-not-found", message: "Could not find a property with the ID: {#{property_id}}" } ) end |
#stub_get_property_unexpected_error(property_id) ⇒ WebMock::RequestStub
Stub GET property request returning 500 error
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/wikidata_adaptor/test_helpers/rest_api/properties.rb', line 77 def stub_get_property_unexpected_error(property_id) stub_rest_api_request( :get, "/v1/entities/properties/#{property_id}", response_status: 500, response_body: { code: "unexpected-error", message: "Unexpected Error" } ) end |
#stub_patch_property(property_id, payload, response_body: nil) ⇒ Object
PATCH /v1/entities/properties/:property_id
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/wikidata_adaptor/test_helpers/rest_api/properties.rb', line 198 def stub_patch_property(property_id, payload, response_body: nil) stub_rest_api_request( :patch, "/v1/entities/properties/#{property_id}", with: { body: payload.to_json }, response_body: response_body || { id: property_id.to_s, type: "property", data_type: "string", labels: { en: "is instance of" }, descriptions: { en: "that class of which this subject is a particular example and member" }, aliases: { en: ["is a"] }, statements: {} } ) end |
#stub_patch_property_unexpected_error(property_id, payload) ⇒ WebMock::RequestStub
Stub PATCH property request returning 500 error
221 222 223 224 225 226 227 228 229 |
# File 'lib/wikidata_adaptor/test_helpers/rest_api/properties.rb', line 221 def stub_patch_property_unexpected_error(property_id, payload) stub_rest_api_request( :patch, "/v1/entities/properties/#{property_id}", response_status: 500, with: { body: payload.to_json }, response_body: { code: "unexpected-error", message: "Unexpected Error" } ) end |
#stub_post_property(payload, response_body = nil) ⇒ Object
POST /v1/entities/properties
92 93 94 95 96 97 98 99 100 |
# File 'lib/wikidata_adaptor/test_helpers/rest_api/properties.rb', line 92 def stub_post_property(payload, response_body = nil) stub_rest_api_request( :post, "/v1/entities/properties", response_status: 201, with: { body: payload.to_json }, response_body: response_body || posted_property_response_fixture.to_json ) end |
#stub_post_property_access_denied ⇒ WebMock::RequestStub
Stub POST property request returning 403 access denied error
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/wikidata_adaptor/test_helpers/rest_api/properties.rb', line 122 def stub_post_property_access_denied stub_rest_api_request( :post, "/v1/entities/properties", response_status: 403, response_body: { code: "permission-denied", message: "Access to resource is denied", context: { denial_reason: "{reason_code}", denial_context: "{additional_context}" } } ) end |
#stub_post_property_data_policy_violation ⇒ WebMock::RequestStub
Stub POST property request returning 422 data policy violation error
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/wikidata_adaptor/test_helpers/rest_api/properties.rb', line 141 def stub_post_property_data_policy_violation stub_rest_api_request( :post, "/v1/entities/properties", response_status: 422, response_body: { code: "data-policy-violation", message: "Edit violates data policy", context: { violation: "{violation_code}", violation_context: { some: "context" } } } ) end |
#stub_post_property_invalid_property(response_body = nil) ⇒ WebMock::RequestStub
Stub POST property request returning 400 invalid property error
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/wikidata_adaptor/test_helpers/rest_api/properties.rb', line 107 def stub_post_property_invalid_property(response_body = nil) stub_rest_api_request( :post, "/v1/entities/properties", response_status: 400, response_body: response_body || { code: "invalid-property-data", message: "The provided property data is invalid." } ) end |
#stub_post_property_request_limit_reached ⇒ WebMock::RequestStub
Stub POST property request returning 429 request limit reached error
162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/wikidata_adaptor/test_helpers/rest_api/properties.rb', line 162 def stub_post_property_request_limit_reached stub_rest_api_request( :post, "/v1/entities/properties", response_status: 429, response_body: { code: "request-limit-reached", message: "Exceeded the limit of actions that can be performed in a given span of time", context: { reason: "{reason_code}" } } ) end |
#stub_post_property_unexpected_error(payload) ⇒ WebMock::RequestStub
Stub POST property request returning 500 error
182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/wikidata_adaptor/test_helpers/rest_api/properties.rb', line 182 def stub_post_property_unexpected_error(payload) stub_rest_api_request( :post, "/v1/entities/properties", response_status: 500, with: { body: payload.to_json }, response_body: { code: "unexpected-error", message: "Unexpected Error" } ) end |