Module: WikidataAdaptor::TestHelpers::RestApi::Statements

Included in:
WikidataAdaptor::TestHelpers::RestApi
Defined in:
lib/wikidata_adaptor/test_helpers/rest_api/statements.rb

Overview

WebMock stubs for Wikibase REST API statements endpoints

Instance Method Summary collapse

Instance Method Details

#stub_delete_item_statement(item_id, statement_id, payload, response_body: "Statement deleted") ⇒ Object

DELETE /v1/entities/items/:item_id/statements/:statement_id



390
391
392
393
394
395
396
397
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 390

def stub_delete_item_statement(item_id, statement_id, payload, response_body: "Statement deleted")
  stub_rest_api_request(
    :delete,
    "/v1/entities/items/#{item_id}/statements/#{statement_id}",
    with: { body: payload.to_json },
    response_body: response_body
  )
end

#stub_delete_item_statement_unexpected_error(item_id, statement_id, payload) ⇒ WebMock::RequestStub

Stub DELETE item statement request returning 500 error

Parameters:

  • item_id (String)

    The item ID

  • statement_id (String)

    The statement ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


406
407
408
409
410
411
412
413
414
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 406

def stub_delete_item_statement_unexpected_error(item_id, statement_id, payload)
  stub_rest_api_request(
    :delete,
    "/v1/entities/items/#{item_id}/statements/#{statement_id}",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: { code: "unexpected-error", message: "Unexpected Error" }
  )
end

#stub_delete_property_statement(property_id, statement_id, payload, response_body: "Statement deleted") ⇒ Object

DELETE /v1/entities/properties/:property_id/statements/:statement_id



419
420
421
422
423
424
425
426
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 419

def stub_delete_property_statement(property_id, statement_id, payload, response_body: "Statement deleted")
  stub_rest_api_request(
    :delete,
    "/v1/entities/properties/#{property_id}/statements/#{statement_id}",
    with: { body: payload.to_json },
    response_body: response_body
  )
end

#stub_delete_property_statement_unexpected_error(property_id, statement_id, payload) ⇒ WebMock::RequestStub

Stub DELETE property statement request returning 500 error

Parameters:

  • property_id (String)

    The property ID

  • statement_id (String)

    The statement ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


435
436
437
438
439
440
441
442
443
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 435

def stub_delete_property_statement_unexpected_error(property_id, statement_id, payload)
  stub_rest_api_request(
    :delete,
    "/v1/entities/properties/#{property_id}/statements/#{statement_id}",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: { code: "unexpected-error", message: "Unexpected Error" }
  )
end

#stub_delete_statement(statement_id, payload, response_body: "Statement deleted") ⇒ Object

DELETE /v1/statements/:statement_id



448
449
450
451
452
453
454
455
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 448

def stub_delete_statement(statement_id, payload, response_body: "Statement deleted")
  stub_rest_api_request(
    :delete,
    "/v1/statements/#{statement_id}",
    with: { body: payload.to_json },
    response_body: response_body
  )
end

#stub_delete_statement_unexpected_error(statement_id, payload) ⇒ WebMock::RequestStub

Stub DELETE statement request returning 500 error

Parameters:

  • statement_id (String)

    The statement ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


463
464
465
466
467
468
469
470
471
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 463

def stub_delete_statement_unexpected_error(statement_id, payload)
  stub_rest_api_request(
    :delete,
    "/v1/statements/#{statement_id}",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: { code: "unexpected-error", message: "Unexpected Error" }
  )
end

#stub_get_item_statement(item_id, statement_id) ⇒ Object

GET /v1/entities/items/:item_id/statements/:statement_id



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 33

def stub_get_item_statement(item_id, statement_id)
  stub_rest_api_request(
    :get,
    "/v1/entities/items/#{item_id}/statements/#{statement_id}",
    response_body: {
      id: statement_id.to_s,
      rank: "normal",
      property: { id: "P92", "data-type": "string" },
      value: { content: "I am a goat", type: "value" },
      qualifiers: [],
      references: []
    }
  )
end

#stub_get_item_statements(item_id, response_body = nil) ⇒ Object

GET /v1/entities/items/:item_id/statements



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 11

def stub_get_item_statements(item_id, response_body = nil)
  stub_rest_api_request(
    :get,
    "/v1/entities/items/#{item_id}/statements",
    response_body: response_body || {
      additionalProp1: [
        {
          id: "Q11$6403c562-401a-2b26-85cc-8327801145e1",
          rank: "normal",
          property: { id: "P92", "data-type": "string" },
          value: { content: "I am a goat", type: "value" },
          qualifiers: [],
          references: []
        }
      ]
    }
  )
end

#stub_get_property_statement(property_id, statement_id) ⇒ Object

GET /v1/entities/properties/:property_id/statements/:statement_id



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 119

def stub_get_property_statement(property_id, statement_id)
  stub_rest_api_request(
    :get,
    "/v1/entities/properties/#{property_id}/statements/#{statement_id}",
    response_body: {
      id: statement_id.to_s,
      rank: "normal",
      property: { id: property_id.to_s, "data-type": "wikibase-item" },
      value: { content: "Q5", type: "value" },
      qualifiers: [],
      references: []
    }
  )
end

#stub_get_property_statements(property_id, response_body = nil) ⇒ Object

GET /v1/entities/properties/:property_id/statements



108
109
110
111
112
113
114
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 108

def stub_get_property_statements(property_id, response_body = nil)
  stub_rest_api_request(
    :get,
    "/v1/entities/properties/#{property_id}/statements",
    response_body: response_body || {}
  )
end

#stub_get_statement(statement_id) ⇒ Object

GET /v1/statements/:statement_id



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 90

def stub_get_statement(statement_id)
  stub_rest_api_request(
    :get,
    "/v1/statements/#{statement_id}",
    response_body: {
      id: statement_id.to_s,
      rank: "normal",
      property: { id: "P92", "data-type": "string" },
      value: { content: "I am a goat", type: "value" },
      qualifiers: [],
      references: []
    }
  )
end

#stub_patch_item_statement(item_id, statement_id, payload, response_body: nil) ⇒ Object

PATCH /v1/entities/items/:item_id/statements/:statement_id



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 283

def stub_patch_item_statement(item_id, statement_id, payload, response_body: nil)
  stub_rest_api_request(
    :patch,
    "/v1/entities/items/#{item_id}/statements/#{statement_id}",
    with: { body: payload.to_json },
    response_body: response_body || {
      id: statement_id.to_s,
      rank: "normal",
      property: { id: "P92", "data-type": "string" },
      value: { content: "Patched goat", type: "value" },
      qualifiers: [],
      references: []
    }
  )
end

#stub_patch_item_statement_unexpected_error(item_id, statement_id, payload) ⇒ WebMock::RequestStub

Stub PATCH item statement request returning 500 error

Parameters:

  • item_id (String)

    The item ID

  • statement_id (String)

    The statement ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


306
307
308
309
310
311
312
313
314
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 306

def stub_patch_item_statement_unexpected_error(item_id, statement_id, payload)
  stub_rest_api_request(
    :patch,
    "/v1/entities/items/#{item_id}/statements/#{statement_id}",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: { code: "unexpected-error", message: "Unexpected Error" }
  )
end

#stub_patch_property_statement(property_id, statement_id, payload, response_body: nil) ⇒ Object

PATCH /v1/entities/properties/:property_id/statements/:statement_id



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 319

def stub_patch_property_statement(property_id, statement_id, payload, response_body: nil)
  stub_rest_api_request(
    :patch,
    "/v1/entities/properties/#{property_id}/statements/#{statement_id}",
    with: { body: payload.to_json },
    response_body: response_body || {
      id: statement_id.to_s,
      rank: "normal",
      property: { id: property_id.to_s, "data-type": "wikibase-item" },
      value: { content: "Q99", type: "value" },
      qualifiers: [],
      references: []
    }
  )
end

#stub_patch_property_statement_unexpected_error(property_id, statement_id, payload) ⇒ WebMock::RequestStub

Stub PATCH property statement request returning 500 error

Parameters:

  • property_id (String)

    The property ID

  • statement_id (String)

    The statement ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


342
343
344
345
346
347
348
349
350
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 342

def stub_patch_property_statement_unexpected_error(property_id, statement_id, payload)
  stub_rest_api_request(
    :patch,
    "/v1/entities/properties/#{property_id}/statements/#{statement_id}",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: { code: "unexpected-error", message: "Unexpected Error" }
  )
end

#stub_patch_statement(statement_id, payload, response_body: nil) ⇒ Object

PATCH /v1/statements/:statement_id



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 355

def stub_patch_statement(statement_id, payload, response_body: nil)
  stub_rest_api_request(
    :patch,
    "/v1/statements/#{statement_id}",
    with: { body: payload.to_json },
    response_body: response_body || {
      id: statement_id.to_s,
      rank: "normal",
      property: { id: "P92", "data-type": "string" },
      value: { content: "Patched goat", type: "value" },
      qualifiers: [],
      references: []
    }
  )
end

#stub_patch_statement_unexpected_error(statement_id, payload) ⇒ WebMock::RequestStub

Stub PATCH statement request returning 500 error

Parameters:

  • statement_id (String)

    The statement ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


377
378
379
380
381
382
383
384
385
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 377

def stub_patch_statement_unexpected_error(statement_id, payload)
  stub_rest_api_request(
    :patch,
    "/v1/statements/#{statement_id}",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: { code: "unexpected-error", message: "Unexpected Error" }
  )
end

#stub_post_item_statement(item_id, payload, response_body: nil) ⇒ Object

POST /v1/entities/items/:item_id/statements



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 51

def stub_post_item_statement(item_id, payload, response_body: nil)
  stub_rest_api_request(
    :post,
    "/v1/entities/items/#{item_id}/statements",
    response_status: 201,
    with: { body: payload.to_json },
    response_body: response_body || {
      id: "Q42$6403c562-401a-2b26-85cc-8327801145e1",
      rank: "normal",
      property: { id: "P92", "data-type": "string" },
      value: { content: "I am a goat", type: "value" },
      qualifiers: [],
      references: []
    }
  )
end

#stub_post_item_statement_unexpected_error(item_id, payload) ⇒ WebMock::RequestStub

Stub POST item statement request returning 500 error

Parameters:

  • item_id (String)

    The item ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 74

def stub_post_item_statement_unexpected_error(item_id, payload)
  stub_rest_api_request(
    :post,
    "/v1/entities/items/#{item_id}/statements",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: {
      code: "unexpected-error",
      message: "Unexpected Error"
    }
  )
end

#stub_post_property_statement(property_id, payload, response_body: nil) ⇒ Object

POST /v1/entities/properties/:property_id/statements



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 137

def stub_post_property_statement(property_id, payload, response_body: nil)
  stub_rest_api_request(
    :post,
    "/v1/entities/properties/#{property_id}/statements",
    response_status: 201,
    with: { body: payload.to_json },
    response_body: response_body || {
      id: "P31$11111111-2222-3333-4444-555555555555",
      rank: "normal",
      property: { id: property_id.to_s, "data-type": "wikibase-item" },
      value: { content: "Q5", type: "value" },
      qualifiers: [],
      references: []
    }
  )
end

#stub_post_property_statement_unexpected_error(property_id, payload) ⇒ WebMock::RequestStub

Stub POST property statement request returning 500 error

Parameters:

  • property_id (String)

    The property ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 160

def stub_post_property_statement_unexpected_error(property_id, payload)
  stub_rest_api_request(
    :post,
    "/v1/entities/properties/#{property_id}/statements",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: {
      code: "unexpected-error",
      message: "Unexpected Error"
    }
  )
end

#stub_put_item_statement(item_id, statement_id, payload, response_body: nil) ⇒ Object

PUT /v1/entities/items/:item_id/statements/:statement_id



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 176

def stub_put_item_statement(item_id, statement_id, payload, response_body: nil)
  stub_rest_api_request(
    :put,
    "/v1/entities/items/#{item_id}/statements/#{statement_id}",
    with: { body: payload.to_json },
    response_body: response_body || {
      id: statement_id.to_s,
      rank: "normal",
      property: { id: "P92", "data-type": "string" },
      value: { content: "Updated goat", type: "value" },
      qualifiers: [],
      references: []
    }
  )
end

#stub_put_item_statement_unexpected_error(item_id, statement_id, payload) ⇒ WebMock::RequestStub

Stub PUT item statement request returning 500 error

Parameters:

  • item_id (String)

    The item ID

  • statement_id (String)

    The statement ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


199
200
201
202
203
204
205
206
207
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 199

def stub_put_item_statement_unexpected_error(item_id, statement_id, payload)
  stub_rest_api_request(
    :put,
    "/v1/entities/items/#{item_id}/statements/#{statement_id}",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: { code: "unexpected-error", message: "Unexpected Error" }
  )
end

#stub_put_property_statement(property_id, statement_id, payload, response_body: nil) ⇒ Object

PUT /v1/entities/properties/:property_id/statements/:statement_id



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 212

def stub_put_property_statement(property_id, statement_id, payload, response_body: nil)
  stub_rest_api_request(
    :put,
    "/v1/entities/properties/#{property_id}/statements/#{statement_id}",
    with: { body: payload.to_json },
    response_body: response_body || {
      id: statement_id.to_s,
      rank: "normal",
      property: { id: property_id.to_s, "data-type": "wikibase-item" },
      value: { content: "Q42", type: "value" },
      qualifiers: [],
      references: []
    }
  )
end

#stub_put_property_statement_unexpected_error(property_id, statement_id, payload) ⇒ WebMock::RequestStub

Stub PUT property statement request returning 500 error

Parameters:

  • property_id (String)

    The property ID

  • statement_id (String)

    The statement ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


235
236
237
238
239
240
241
242
243
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 235

def stub_put_property_statement_unexpected_error(property_id, statement_id, payload)
  stub_rest_api_request(
    :put,
    "/v1/entities/properties/#{property_id}/statements/#{statement_id}",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: { code: "unexpected-error", message: "Unexpected Error" }
  )
end

#stub_put_statement(statement_id, payload, response_body: nil) ⇒ Object

PUT /v1/statements/:statement_id



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 248

def stub_put_statement(statement_id, payload, response_body: nil)
  stub_rest_api_request(
    :put,
    "/v1/statements/#{statement_id}",
    with: { body: payload.to_json },
    response_body: response_body || {
      id: statement_id.to_s,
      rank: "normal",
      property: { id: "P92", "data-type": "string" },
      value: { content: "Updated goat", type: "value" },
      qualifiers: [],
      references: []
    }
  )
end

#stub_put_statement_unexpected_error(statement_id, payload) ⇒ WebMock::RequestStub

Stub PUT statement request returning 500 error

Parameters:

  • statement_id (String)

    The statement ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


270
271
272
273
274
275
276
277
278
# File 'lib/wikidata_adaptor/test_helpers/rest_api/statements.rb', line 270

def stub_put_statement_unexpected_error(statement_id, payload)
  stub_rest_api_request(
    :put,
    "/v1/statements/#{statement_id}",
    response_status: 500,
    with: { body: payload.to_json },
    response_body: { code: "unexpected-error", message: "Unexpected Error" }
  )
end