<s> from datetime import datetime <EOL> from pytest import raises <EOL> from requests . exceptions import HTTPError <EOL> import pytest <EOL> from epo_ops . api import Client , RegisteredClient <EOL> from epo_ops . exceptions import InvalidNumberConversion <EOL> from epo_ops . middlewares . throttle . storages import sqlite <EOL> from . helpers . api_helpers import ( <EOL> assert_family_success , assert_number_service_success , <EOL> assert_published_data_search_success , <EOL> assert_published_data_search_with_range_success , <EOL> assert_published_data_success , assert_register_search_success , <EOL> assert_register_search_with_range_success , assert_register_success , <EOL> issue_number_request , issue_published_data_request <EOL> ) <EOL> def test_instantiate_simple_client ( ) : <EOL> client = Client ( ) <EOL> assert len ( client . middlewares ) == <NUM_LIT:1> <EOL> assert client . middlewares [ <NUM_LIT:0> ] . history . db_path == sqlite . DEFAULT_DB_PATH <EOL> client = RegisteredClient ( '<STR_LIT:key>' , '<STR_LIT>' ) <EOL> assert len ( client . middlewares ) == <NUM_LIT:1> <EOL> assert client . middlewares [ <NUM_LIT:0> ] . history . db_path == sqlite . DEFAULT_DB_PATH <EOL> def test_family ( all_clients ) : <EOL> assert_family_success ( all_clients ) <EOL> def test_published_data ( all_clients ) : <EOL> assert_published_data_success ( all_clients ) <EOL> def test_published_data_search ( all_clients ) : <EOL> assert_published_data_search_success ( all_clients ) <EOL> def test_published_data_search_with_range ( all_clients ) : <EOL> assert_published_data_search_with_range_success ( all_clients ) <EOL> def test_register ( all_clients ) : <EOL> assert_register_success ( all_clients ) <EOL> def test_register_search ( all_clients ) : <EOL> assert_register_search_success ( all_clients ) <EOL> def test_register_search_with_range ( all_clients ) : <EOL> assert_register_search_with_range_success ( all_clients ) <EOL> def test_number_service ( all_clients ) : <EOL> assert_number_service_success ( all_clients ) <EOL> def test_invalid_number_conversions ( default_client ) : <EOL> with raises ( InvalidNumberConversion ) : <EOL> issue_number_request ( default_client , '<STR_LIT>' ) <EOL> def test_get_access_token ( registered_clients ) : <EOL> assert '<STR_LIT>' in registered_clients . access_token . _content <EOL> def test_400_invalid_token ( default_registered_client ) : <EOL> token = '<STR_LIT>' <EOL> default_registered_client . access_token . token = token <EOL> with raises ( HTTPError ) : <EOL> issue_published_data_request ( default_registered_client ) <EOL> def test_400_expired_token ( default_registered_client ) : <EOL> token = '<STR_LIT>' <EOL> default_registered_client . access_token . token = token <EOL> assert_published_data_success ( default_registered_client ) <EOL> def test_self_check_expired_token ( registered_clients ) : <EOL> old_token = registered_clients . access_token . token <EOL> registered_clients . access_token . expiration = datetime . now ( ) <EOL> assert old_token != registered_clients . access_token . token <EOL> def test_caching ( cached_clients , monkeypatch ) : <EOL> assert_published_data_success ( cached_clients ) <EOL> monkeypatch . delattr ( '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:2> ) : <EOL> assert_published_data_success ( cached_clients ) <EOL> def test_throttling ( non_cached_clients , monkeypatch ) : <EOL> def mock_sleep ( service ) : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> assert_published_data_success ( non_cached_clients ) <EOL> monkeypatch . setattr ( '<STR_LIT>' , mock_sleep ) <EOL> with raises ( RuntimeError ) : <EOL> assert_published_data_success ( non_cached_clients ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> pytest . main ( ) </s>
