inspirehep.testlib.api package

Submodules

inspirehep.testlib.api.author_form module

Literature suggestion form testlib.

class inspirehep.testlib.api.author_form.AuthorFormApiClient(client)[source]

Bases: object

SUBMIT_AUTHOR_FORM_URL = '/authors/new/submit'
submit(form_input_data)[source]
class inspirehep.testlib.api.author_form.AuthorFormInputData(given_names, research_field, status='active', family_name=None, display_name=None)[source]

Bases: object

request_data()[source]

inspirehep.testlib.api.base_resource module

Base resource class and utils.

class inspirehep.testlib.api.base_resource.BaseResource[source]

Bases: object

inspirehep.testlib.api.callback module

/callback endpoint api client and resources.

class inspirehep.testlib.api.callback.CallbackClient(client)[source]

Bases: object

Client for the Inspire callback

CALLBACK_URL = '/callback/workflows'
robotupload(nonce, results)[source]
Parameters:
  • nonce (int) – nonce parameter passed to robotupload, usually the workflow id.
  • results (list[RobotuploadCallbackResult]) – list of robotupload results.
webcoll(recids)[source]
Parameters:recids (list(int)) – list of recids that webcoll parsed.
class inspirehep.testlib.api.callback.RobotuploadCallbackResult(recid, error_message, success, marcxml, url)[source]

Bases: dict

inspirehep.testlib.api.e2e module

/holdingpen endopint api client and resources.

class inspirehep.testlib.api.e2e.E2EClient(client)[source]

Bases: object

Client for the Inspire E2E api.

INIT_DB_URL = '/e2e/init_db'
INIT_ES_URL = '/e2e/init_es'
INIT_FIXTURES_URL = '/e2e/init_fixtures'
SCHEDULE_CRAWL_URL = '/e2e/schedule_crawl'
init_db()[source]
init_es()[source]
init_fixtures()[source]
schedule_crawl(**params)[source]

inspirehep.testlib.api.holdingpen module

/holdingpen endopint api client and resources.

class inspirehep.testlib.api.holdingpen.HoldingpenApiClient(client)[source]

Bases: object

Client for the Inspire Holdingpen

HOLDINGPEN_API_URL = '/api/holdingpen/'
HOLDINGPEN_EDIT_URL = '/api/holdingpen/{workflow_id}/action/edit'
HOLDINGPEN_RESOLVE_URL = '/api/holdingpen/{workflow_id}/action/resolve'
HOLDINGPEN_RESTART_URL = '/api/holdingpen/{workflow_id}/action/restart'
accept_core(holdingpen_id)[source]
accept_non_core(holdingpen_id)[source]
edit_workflow(holdingpen_entry)[source]

Helper method to edit a holdingpen entry.

Parameters:holdingpen_entry (HoldingpenResource) – entry updated with the already changed data.
Returns:
The actual http response to the last call (the
actual /edit endpoint).
Return type:requests.Response
Raises:requests.exceptions.BaseHttpError – any error related to the http calls made.

Example

>>> my_entry = holdingpen_client.get_detail_entry(holdingpen_id=1234)
>>> my_entry.core = False   # do some changes
>>> holdingpen_client.edit_workflow(holdingpen_entry=my_entry)
<Response [200]>
get_detail_entry(holdingpen_id)[source]
get_list_entries()[source]
reject(holdingpen_id)[source]
resolve_merge_conflicts(hp_entry)[source]
restart_workflow(holdingpen_entry_id)[source]
resume(hp_entry)[source]
run_harvest(spider, workflow='article', **kwargs)[source]

Run a harvest scheduling a job in celery

class inspirehep.testlib.api.holdingpen.HoldingpenAuthorResource(display_name, **kwargs)[source]

Bases: inspirehep.testlib.api.holdingpen.HoldingpenResource

Holdingpen for an author workflow.

to_json()[source]
class inspirehep.testlib.api.holdingpen.HoldingpenLiteratureResource(titles, auto_approved=None, doi=None, arxiv_eprint=None, approved_match=None, **kwargs)[source]

Bases: inspirehep.testlib.api.holdingpen.HoldingpenResource

Holdingpen entry for a literature workflow.

set_conflicts(conflicts)[source]
to_json()[source]
class inspirehep.testlib.api.holdingpen.HoldingpenResource(workflow_id, approved, is_update, core, status, control_number)[source]

Bases: inspirehep.testlib.api.base_resource.BaseResource

Inspire holdingpen entry to represent a workflow

classmethod from_json(json, workflow_id=None)[source]

Constructor for a holdingpen entry, it will be able to be mapped to and from json, and used to fully edit entries. Usually you pass to it the full raw json from the details of a holdingpen entry.

Parameters:json (dict) – dictionary of a single entry as returned by the api.
set_action(action)[source]
to_json()[source]

Translates the current entry to a json applying any changes to the original json passed, or just with the info added to the entry since it’s instantiation.

Returns:Json view of the current status of the entry.
Return type:dict

inspirehep.testlib.api.literature module

/literature endpoint api client and resources.

class inspirehep.testlib.api.literature.LiteratureApiClient(client)[source]

Bases: object

Client for the Inspire Literature section

LITERATURE_API_URL = '/api/literature/'
get_record(rec_id)[source]
class inspirehep.testlib.api.literature.LiteratureResource(control_number, doi, arxiv_eprint, titles)[source]

Bases: inspirehep.testlib.api.base_resource.BaseResource

Inspire base entry to represent a literature record

classmethod from_json(json)[source]
Parameters:json (dict) – dictionary of a single entry as returned by the api.
class inspirehep.testlib.api.literature.LiteratureResourceTitle(source, title)[source]

Bases: inspirehep.testlib.api.base_resource.BaseResource

classmethod from_json(json)[source]
to_json()[source]

inspirehep.testlib.api.literature_form module

Literature suggestion form testlib.

class inspirehep.testlib.api.literature_form.LiteratureFormApiClient(client)[source]

Bases: object

SUBMIT_LITERATURE_FORM_URL = '/literature/new/submit'
submit(form_input_data)[source]
class inspirehep.testlib.api.literature_form.LiteratureFormInputData(title, language='en', type_of_doc='article')[source]

Bases: object

add_author(name, affiliation=None)[source]
request_data()[source]

inspirehep.testlib.api.mitm_client module

Client interface for INSPIRE-MITMPROXY.

class inspirehep.testlib.api.mitm_client.MITMClient(proxy_host='http://mitm-manager.local')[source]

Bases: object

assert_interaction_used(service_name, interaction_name, times=None)[source]
get_interactions_for_service(service_name)[source]
set_scenario(scenario_name)[source]
start_recording()[source]
stop_recording()[source]
inspirehep.testlib.api.mitm_client.with_mitmproxy(*args, **kwargs)[source]

Decorator to abstract fixture recording and scenario setup for the E2E tests with mitmproxy.

Parameters:
  • scenario_name (Optional[str]) – scenario name, by default test name without ‘test_‘ prefix
  • should_record (Optional[bool]) – is recording new interactions allowed during test run, by default False
  • *args (List[Callable]) – list of length of either zero or one: decorated function. This is to allow the decorator to function both with and without calling it with parameters: if args is present, we can deduce that the decorator was used without parameters.
Returns:

a decorator the can be used both with and without calling brackets

(if all params should be default)

Return type:

Callable

Module contents

Main API client for Inspire

class inspirehep.testlib.api.InspireApiClient(auto_login=True, base_url='http://inpirehep.local')[source]

Bases: object

Inspire Client for end-to-end testing

LOCAL_LOGIN_URL = '/login/?next=%2F&local=1'
login_local(user='admin@inspirehep.net', password='123456')[source]

Perform a local log-in in Inspire storing the session

class inspirehep.testlib.api.Session(*args, **kwargs)[source]

Bases: requests.sessions.Session

get(*args, **kwargs)[source]
get_full_url(*paths)[source]
post(*args, **kwargs)[source]
put(*args, **kwargs)[source]
static response_to_string(res)[source]
Parameters:resrequests.Response object

Parse the given request and generate an informative string from it