Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@responses.activate
def test_unknown_error(self):
responses.add(
responses.Response(
method=self.method_api,
url=self.api_url,
json={},
status=500,
)
)
if self.method_endpoint == "GET":
response = self.client.get(self.endpoint_url)
else:
if self.data:
response = self.client.post(
self.endpoint_url, data=self.data
)
else:
response = self.client.post(
def test_login_circuit_breaker(self):
responses.add(
responses.Response(
method="POST",
url=self.api_url,
body=CircuitBreakerError(),
status=500,
)
)
response = self.client.get(self.endpoint_url)
assert response.status_code == 503
def test_get_card_default_button(self):
payload = self.snap_payload
responses.add(
responses.Response(
method="GET", url=self.api_url, json=payload, status=200
)
)
response = self.client.get(self.endpoint_url + "?button=test")
self.assertEqual(response.status_code, 200)
self.assert_context("button", "black")
def test_crossref_create_identifiers(self, preprint, crossref_client, crossref_success_response):
responses.add(
responses.Response(
responses.POST,
crossref_client.base_url,
body=crossref_success_response,
content_type='text/html;charset=ISO-8859-1',
status=200,
),
)
res = crossref_client.create_identifier(preprint=preprint, category='doi')
doi = settings.DOI_FORMAT.format(prefix=preprint.provider.doi_prefix, guid=preprint._id)
assert res['doi'] == doi
delete_org = responses.Response(
method="DELETE",
url="https://some.realm/api/scm.config/1.0/org/org-12345",
json={},
status=200,
)
post_nodes = responses.Response(
method="POST",
url="https://some.realm/api/scm.config/1.0/nodes",
json=db["nodes"]["items"][0],
status=200,
)
post_nonesuch = responses.Response(
method="POST", url="https://some.realm/api/scm.config/1.0/nonesuch", status=404
)
post_prepare_image = responses.Response(
method="POST",
url="https://some.realm/api/scm.config/1.0/node/node-12345/prepare_image",
json={},
status=200,
)
put_node = responses.Response(
method="PUT",
url="https://some.realm/api/scm.config/1.0/node/node-12345",
json=db["nodes"]["items"][0],
status=200,
)
def test_api_500_no_answer(self):
responses.add(
responses.Response(method="GET", url=self.api_url, status=500)
)
response = self.client.get(self.endpoint_url)
assert len(responses.calls) == 1
called = responses.calls[0]
assert called.request.url == self.api_url
assert response.status_code == 502
def _prepare_mock_401_error():
responses.add(
responses.Response(
responses.POST,
'https://mock2.com/callback',
body='{"error": "user denied access"}',
status=401,
content_type='application/json',
)
def test_service_validate(self):
user = UserFactory()
url = furl.furl(self.base_url)
url.path.segments.extend(('p3', 'serviceValidate',))
service_url = 'http://test.osf.io'
ticket = fake.md5()
body = make_service_validation_response_body(user, ticket)
responses.add(
responses.Response(
responses.GET,
url.url,
body=body,
status=200,
)
)
resp = self.client.service_validate(ticket, service_url)
assert_true(resp.authenticated)
{"package_name": "tutu"},
]
},
"total": 3,
"_links": {
"last": {"href": "http://url.c?q=snap&size=1&page=1"},
"next": {"href": "http://url.c?q=snap&size=1&page=1"},
"self": {"href": "http://url.c?q=snap&size=1&page=1"},
},
}
search_api_formated = self.search_snap_api_url.format(
snap_name="snap", page="1", size="25"
)
responses.add(
responses.Response(
method="GET", url=search_api_formated, json=payload, status=200
)
)
endpoint = self.endpoint_url.format(q="snap", category="")
response = self.client.get(endpoint)
self.assertEqual(response.status_code, 200)
self.assert_context("query", "snap")
self.assert_context("category", "")
self.assert_context("category_display", None)
self.assert_context("featured_snaps", [])
self.assert_context(
"searched_snaps",
[
}
if len(files):
data = [dict(default_file, **each) for each in files]
else:
data = [default_file]
jsonapi_data = []
for datum in data:
jsonapi_data.append({'attributes': datum})
if not folder:
jsonapi_data = jsonapi_data[0]
responses.add(
responses.Response(
method,
wb_url,
json={u'data': jsonapi_data},
status=status_code,
content_type='application/json'
)