Module: WikidataAdaptor::TestHelpers::RestApi::Sitelinks

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

Overview

WebMock stubs for Wikibase REST API sitelinks endpoints

Instance Method Summary collapse

Instance Method Details

DELETE /v1/entities/items/:item_id/sitelinks/:site_id



115
116
117
118
119
120
121
122
# File 'lib/wikidata_adaptor/test_helpers/rest_api/sitelinks.rb', line 115

def stub_delete_item_sitelink(item_id, site_id, payload, response_body: "Sitelink deleted")
  stub_rest_api_request(
    :delete,
    "/v1/entities/items/#{item_id}/sitelinks/#{site_id}",
    with: { body: payload.to_json },
    response_body: response_body
  )
end

Stub DELETE item sitelink request returning 500 error

Parameters:

  • item_id (String)

    The item ID

  • site_id (String)

    The site ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


131
132
133
134
135
136
137
138
139
# File 'lib/wikidata_adaptor/test_helpers/rest_api/sitelinks.rb', line 131

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

GET /v1/entities/items/:item_id/sitelinks/:site_id



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

def stub_get_item_sitelink(item_id, site_id, response_body = nil)
  stub_rest_api_request(
    :get,
    "/v1/entities/items/#{item_id}/sitelinks/#{site_id}",
    response_body: response_body || {
      title: "Douglas Adams",
      badges: [],
      url: "https://en.wikipedia.org/wiki/Douglas_Adams"
    }
  )
end

GET /v1/entities/items/:item_id/sitelinks



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/sitelinks.rb', line 11

def stub_get_item_sitelinks(item_id, response_body = nil)
  stub_rest_api_request(
    :get,
    "/v1/entities/items/#{item_id}/sitelinks",
    response_body: response_body || {
      enwiki: {
        title: "Douglas Adams",
        badges: [],
        url: "https://en.wikipedia.org/wiki/Douglas_Adams"
      },
      frwiki: {
        title: "Douglas Adams",
        badges: [],
        url: "https://fr.wikipedia.org/wiki/Douglas_Adams"
      }
    }
  )
end

PATCH /v1/entities/items/:item_id/sitelinks



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/wikidata_adaptor/test_helpers/rest_api/sitelinks.rb', line 81

def stub_patch_item_sitelinks(item_id, payload, response_body: nil)
  stub_rest_api_request(
    :patch,
    "/v1/entities/items/#{item_id}/sitelinks",
    with: { body: payload.to_json },
    response_body: response_body || {
      enwiki: {
        title: "Douglas Adams",
        badges: [],
        url: "https://en.wikipedia.org/wiki/Douglas_Adams"
      }
    }
  )
end

Stub PATCH item sitelinks request returning 500 error

Parameters:

  • item_id (String)

    The item ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


102
103
104
105
106
107
108
109
110
# File 'lib/wikidata_adaptor/test_helpers/rest_api/sitelinks.rb', line 102

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

PUT /v1/entities/items/:item_id/sitelinks/:site_id



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/wikidata_adaptor/test_helpers/rest_api/sitelinks.rb', line 48

def stub_put_item_sitelink(item_id, site_id, payload, response_body: nil)
  stub_rest_api_request(
    :put,
    "/v1/entities/items/#{item_id}/sitelinks/#{site_id}",
    with: { body: payload.to_json },
    response_body: response_body || {
      title: "Douglas Adams",
      badges: [],
      url: "https://en.wikipedia.org/wiki/Douglas_Adams"
    }
  )
end

Stub PUT item sitelink request returning 500 error

Parameters:

  • item_id (String)

    The item ID

  • site_id (String)

    The site ID

  • payload (Hash)

    The request payload

Returns:

  • (WebMock::RequestStub)


68
69
70
71
72
73
74
75
76
# File 'lib/wikidata_adaptor/test_helpers/rest_api/sitelinks.rb', line 68

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