Module: WikidataAdaptor::TestHelpers::RestApi::Support

Included in:
Items, Properties
Defined in:
lib/wikidata_adaptor/test_helpers/rest_api/support/support.rb

Overview

WebMock stubs for Wikibase REST API support utilities

Instance Method Summary collapse

Instance Method Details

#load_openapi_specHash

Load the OpenAPI specification from file

Returns:

  • (Hash)

    The parsed OpenAPI specification



11
12
13
14
15
# File 'lib/wikidata_adaptor/test_helpers/rest_api/support/support.rb', line 11

def load_openapi_spec
  JSON.parse(
    File.read(File.join("spec", "openapi", "openapi.json"))
  )
end

#load_path_example(path, method, response_code = "200") ⇒ Hash

Load example response from OpenAPI specification for a given path and method

Parameters:

  • path (String)

    The API path

  • method (String)

    The HTTP method

  • response_code (String) (defaults to: "200")

    The HTTP response code

Returns:

  • (Hash)

    The example response



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/wikidata_adaptor/test_helpers/rest_api/support/support.rb', line 24

def load_path_example(path, method, response_code = "200")
  load_openapi_spec.dig(
    "paths",
    path,
    method,
    "responses",
    response_code,
    "content",
    "application/json",
    "example"
  )
end

#posted_item_payload_fixtureHash

Fixture for an item creation payload

Returns:

  • (Hash)

    The posted item payload fixture



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/wikidata_adaptor/test_helpers/rest_api/support/support.rb', line 206

def posted_item_payload_fixture
  {
    "item" => {
      "labels" => {
        "en" => "Jane Doe",
        "ru" => "Джейн Доу"
      },
      "descriptions" => {
        "en" => "famous person",
        "ru" => "известная личность"
      },
      "aliases" => {
        "en" => [
          "Jane M. Doe",
          "JD"
        ],
        "ru" => [
          "Джейн М. Доу"
        ]
      },
      "statements" => {
        "P694" => [
          {
            "property" => {
              "id" => "P694"
            },
            "value" => {
              "type" => "value",
              "content" => "Q626683"
            }
          }
        ],
        "P476" => [
          {
            "property" => {
              "id" => "P476"
            },
            "value" => {
              "type" => "value",
              "content" => {
                "time" => "+1986-01-27T00:00:00Z",
                "precision" => 11,
                "calendarmodel" => "http://www.wikidata.org/entity/Q1985727"
              }
            }
          }
        ],
        "P17" => [
          {
            "property" => {
              "id" => "P17"
            },
            "value" => {
              "type" => "value",
              "content" => "Senior Team Supervisor"
            },
            "qualifiers" => [
              {
                "property" => {
                  "id" => "P706"
                },
                "value" => {
                  "type" => "value",
                  "content" => {
                    "time" => "+2023-06-13T00:00:00Z",
                    "precision" => 11,
                    "calendarmodel" => "http://www.wikidata.org/entity/Q1985727"
                  }
                }
              }
            ],
            "references" => [
              {
                "parts" => [
                  {
                    "property" => {
                      "id" => "P709"
                    },
                    "value" => {
                      "type" => "value",
                      "content" => "https://news.example.org"
                    }
                  }
                ]
              }
            ]
          }
        ]
      },
      "sitelinks" => {
        "enwiki" => {
          "title" => "Jane Doe"
        },
        "ruwiki" => {
          "title" => "Джейн Доу"
        }
      }
    },
    "comment" => "Create an Item for Jane Doe"
  }
end

#posted_item_response_fixtureHash

Fixture for a posted item response

Returns:

  • (Hash)

    The posted item response fixture



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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/wikidata_adaptor/test_helpers/rest_api/support/support.rb', line 40

def posted_item_response_fixture
  {
    "id" => "Q24",
    "type" => "item",
    "labels" => {
      "en" => "Jane Doe",
      "ru" => "Джейн Доу"
    },
    "descriptions" => {
      "en" => "famous person",
      "ru" => "известная личность"
    },
    "aliases" => {
      "en" => [
        "Jane M. Doe",
        "JD"
      ],
      "ru" => [
        "Джейн М. Доу"
      ]
    },
    "statements" => {
      "P694" => [
        {
          "id" => "Q24$BB728546-A400-4116-A772-16D54B62AC2B",
          "rank" => "normal",
          "property" => {
            "id" => "P694",
            "data_type" => "wikibase-item"
          },
          "value" => {
            "type" => "value",
            "content" => "Q626683"
          },
          "qualifiers" => [],
          "references" => []
        }
      ],
      "P476" => [
        {
          "id" => "Q24$F3B2F956-B6AB-4984-8D89-BEE0FFFA3385",
          "rank" => "normal",
          "property" => {
            "id" => "P476",
            "data_type" => "time"
          },
          "value" => {
            "type" => "value",
            "content" => {
              "time" => "+1986-01-27T00:00:00Z",
              "precision" => 11,
              "calendarmodel" => "http://www.wikidata.org/entity/Q1985727"
            }
          },
          "qualifiers" => [],
          "references" => []
        }
      ],
      "P17" => [
        {
          "id" => "Q24$9966A1CA-F3F5-4B1D-A534-7CD5953169DA",
          "rank" => "normal",
          "property" => {
            "id" => "P17",
            "data_type" => "string"
          },
          "value" => {
            "type" => "value",
            "content" => "Senior Team Supervisor"
          },
          "qualifiers" => [
            {
              "property" => {
                "id" => "P706",
                "data_type" => "time"
              },
              "value" => {
                "type" => "value",
                "content" => {
                  "time" => "+2023-06-13T00:00:00Z",
                  "precision" => 11,
                  "calendarmodel" => "http://www.wikidata.org/entity/Q1985727"
                }
              }
            }
          ],
          "references" => [
            {
              "hash" => "7ccd777f870b71a4c5056c7fd2a83a22cc39be6d",
              "parts" => [
                {
                  "property" => {
                    "id" => "P709",
                    "data_type" => "url"
                  },
                  "value" => {
                    "type" => "value",
                    "content" => "https://news.example.org"
                  }
                }
              ]
            }
          ]
        }
      ]
    },
    "sitelinks" => {
      "enwiki" => {
        "title" => "Jane Doe",
        "badges" => [],
        "url" => "https://enwiki.example.org/wiki/Jane_Doe"
      },
      "ruwiki" => {
        "title" => "Джейн Доу",
        "badges" => [],
        "url" => "https://ruwiki.example.org/wiki/Джейн_Доу"
      }
    }
  }
end

#posted_property_payload_fixtureHash

Fixture for a property creation payload

Returns:

  • (Hash)

    The posted property payload fixture



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/wikidata_adaptor/test_helpers/rest_api/support/support.rb', line 185

def posted_property_payload_fixture
  {
    "property" => {
      "data_type" => "string",
      "labels" => {
        "en" => "instance of"
      },
      "descriptions" => {
        "en" => "that class of which this subject is a particular example and member"
      },
      "aliases" => {
        "en" => ["is a"]
      }
    },
    "comment" => "Create a Property"
  }
end

#posted_property_response_fixtureHash

Fixture for a posted property response

Returns:

  • (Hash)

    The posted property response fixture



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/wikidata_adaptor/test_helpers/rest_api/support/support.rb', line 164

def posted_property_response_fixture
  {
    "id" => "P1",
    "type" => "property",
    "data_type" => "string",
    "labels" => {
      "en" => "instance of"
    },
    "descriptions" => {
      "en" => "that class of which this subject is a particular example and member"
    },
    "aliases" => {
      "en" => ["is a"]
    },
    "statements" => {}
  }
end