one.tests.test_alyxclient
Unit tests for the one.webclient module.
Functions
Point the parameter files at a directory belonging to this module. |
|
Classes
Tests for AlyxClient authentication, token storage, login/out methods and user prompts. |
|
Tests for AlyxClient methods that modify the JSON field of a REST endpoint. |
|
Tests for REST caching system, the cache decorator and cache flags. |
|
Tests for AlyxClient REST API schema parsing and printing. |
|
Test behaviour when AlyxClient receives a 429 Too Many Requests response. |
- setUpModule()[source]
Point the parameter files at a directory belonging to this module.
These tests log in and out, which rewrites the parameter file for whichever database they use - the developer’s real ~/.one without this. The test database is then set up silently so no class depends on another having run first.
- class TestRestDocumentation(methodName='runTest')[source]
Bases:
TestCaseTests for AlyxClient REST API schema parsing and printing.
- test_print_endpoint_info()[source]
Test endpoint query params are printed when calling AlyxClient.rest without action.
- class TestAuthentication(methodName='runTest')[source]
Bases:
TestCaseTests for AlyxClient authentication, token storage, login/out methods and user prompts.
- test_authentication()[source]
Test for AlyxClient.authenticate and AlyxClient.is_logged_in property.
- test_authenticate_with_token()[source]
Test authenticating with a token in place of a password.
Accounts that sign in through an identity provider have no password at all, so /auth-token is closed to them and a token is the only credential they have.
- test_authenticate_with_token_not_cached()[source]
A token passed with cache_token=False should not be written to the params.
- test_authenticate_token_prompt()[source]
A blank password at the prompt should fall through to asking for a token.
- test_verify_token_rejects_bad_token()[source]
A token the database refuses must be discarded rather than cached.
- test_verify_token_tolerates_unreachable_database()[source]
A network failure while checking must not reject a token that may be perfectly good.
- test_verify_token_checks_the_me_endpoint()[source]
The token is checked against /me, which also reports whose it is.
- test_token_username_wins_over_the_one_supplied()[source]
The database knows whose token it is; caching it under another name would lie.
- test_token_alone_identifies_the_user()[source]
A token is the one credential that can name its owner, so no username is needed.
- test_a_token_is_never_asked_who_it_belongs_to()[source]
A token names its own owner, so neither the prompt nor the stored login applies.
- test_the_api_version_survives_every_authentication_path()[source]
A database can only see how old its clients are if they all say so.
authenticate rebuilds the header dict, so the version was previously sent only by a client that authenticated through the constructor, and dropped by one that authenticated lazily or from a cached token - the common case by far.
- test_the_api_version_is_sent_with_the_request()[source]
The header must reach the wire, not merely sit in the client’s dict.
- test_no_username_is_an_error_rather_than_a_prompt_loop()[source]
With a blank default login and no token, there is nothing to authenticate as.
- test_a_token_alone_needs_a_database_that_names_its_owner()[source]
An Alyx too old to serve /me as an API cannot say whose token it is.
With a token alone there is no name to cache it under and no way to tell whether it is even the intended account, so it is refused.
- test_a_token_alone_is_refused_when_the_database_is_unreachable()[source]
The other way the check comes back empty: it never reached the database.
- test_a_username_resolved_once_is_remembered()[source]
Otherwise the cached token, which is keyed by username, could never be found again.
- test_auth_methods()[source]
Test behaviour when calling AlyxClient._generic_request when logged out.
- class TestJsonFieldMethods(methodName='runTest')[source]
Bases:
TestCaseTests for AlyxClient methods that modify the JSON field of a REST endpoint.
These tests are over-engineered in order to test Alyx Django queries with JSON fields. Django queries are also tested in TestRemote.test_search.
- class TestRestCache(methodName='runTest')[source]
Bases:
TestCaseTests for REST caching system, the cache decorator and cache flags.
- test_loads_cached()[source]
Test for one.webclient._cache_response decorator, checks returns cached result.
- class TestThrottleBackoff(methodName='runTest')[source]
Bases:
TestCaseTest behaviour when AlyxClient receives a 429 Too Many Requests response.
- test_backoff_with_retry_after(sleep_mock)[source]
Test that AlyxClient respects Retry-After header.
- test_backoff_without_retry_after(sleep_mock)[source]
Test that AlyxClient uses exponential backoff when Retry-After header is missing.
- class TestDownloadHTTP(methodName='runTest')[source]
Bases:
TestCase- test_download_creates_a_missing_target_directory()[source]
The default target is ~/Downloads, which plenty of machines do not have.
- class TestMisc(methodName='runTest')[source]
Bases:
TestCase- test_alyx_advice_header()[source]
Test that the Alyx-API-Notice response header is logged or raised as a warning.
- test_paginated_response_count_changed()[source]
Test _PaginatedResponse when records are added/removed by another process.
The remote count is fixed at instantiation, so a -ve index is resolved against a count that may be stale by the time the page is fetched. Previously this left None values in the cache when records were removed.