def test_get_bib_is_reasearch(self, mock_token): with PlatformSession(authorization=mock_token) as session: assert ( session._check_bib_is_research_url("1234567", "sierra-nypl") == "https://platform.nypl.org/api/v0.1/bibs/sierra-nypl/1234567/is-research" )
def test_search_controlNos_argument_errors(self, mock_token, arg): err_msg = "Missing required positional argument `keywords`." with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError) as exc: session.search_controlNos(arg) assert err_msg in str(exc.value)
def test_custom_agent_argument(self, mock_token): with PlatformSession(authorization=mock_token, agent="my_app") as session: assert session.headers["User-Agent"] == "my_app"
def test_default_base_url_parameter(self, mock_token): assert ( PlatformSession(authorization=mock_token).base_url == "https://platform.nypl.org/api/v0.1" )
def test_default_agent_parameter(self, mock_token): with PlatformSession(authorization=mock_token) as session: assert session.headers["User-Agent"] == f"{__title__}/{__version__}"
def test_target_argument_exception(self, mock_token): err_msg = "Invalid `target` argument passed into a Platform session." with pytest.raises(BookopsPlatformError) as exc: PlatformSession(authorization=mock_token, target=None) assert err_msg in str(exc.value)
def test_check_bib_is_research_without_id(self, mock_token, arg_id, arg_src): err_msg = "Both arguments `id` and `nyplSource` are required." with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError) as exc: session.check_bib_is_research(arg_id, nyplSource=arg_src) assert err_msg in str(exc.value)
def test_authorization_invalid_argument(self): err_msg = "Invalid authorization. Argument must be an instance of `PlatformToken` obj." with pytest.raises(BookopsPlatformError) as exc: PlatformSession("my_token") assert err_msg in str(exc.value)
def test_get_bib_list_successful_request( self, mock_token, mock_successful_session_get_response ): with PlatformSession(authorization=mock_token) as session: response = session.get_bib_list(standardNumber=[12345, 12346]) assert response.status_code == 200
def test_prep_sierra_numbers_exceptions(self, mock_token, arg): err_msg = "Invalid Sierra number passed." with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError) as exc: session._prep_sierra_numbers(arg) assert err_msg in str(exc.value)
def test_get_bib_BookopsPlatformError_exception( self, mock_token, mock_bookopsplatformerror ): with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError): session.get_bib("12345678")
def test_prep_sierra_numbers(self, mock_token, arg, expectation): with PlatformSession(authorization=mock_token) as session: assert session._prep_sierra_numbers(arg) == expectation
def test_prep_multi_keywords(self, mock_token, arg, expectation): with PlatformSession(authorization=mock_token) as session: assert session._prep_multi_keywords(arg) == expectation
def test_get_item_list_url(self, mock_token): with PlatformSession(authorization=mock_token) as session: assert ( session._get_item_list_url() == "https://platform.nypl.org/api/v0.1/items" )
def test_get_item_list_successful_request( self, mock_token, mock_successful_session_get_response ): with PlatformSession(authorization=mock_token) as session: response = session.get_item_list(id=["i304400737,i304400750"]) assert response.status_code == 200
def test_get_bib_list_Connection_exception(self, mock_token, mock_connectionerror): with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError): session.get_bib_list(id="12345678")
def test_get_item_list_unexpected_exception( self, mock_token, mock_unexpected_error ): with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError): session.get_item_list(id="i304400737")
def test_get_bib_items_with_invalid_bibNo(self, mock_token): err_msg = "Invalid Sierra number passed." with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError) as exc: session.get_bib_items("a12345678") assert err_msg in str(exc.value)
def test_check_bib_is_research_success( self, mock_token, mock_successful_session_get_response ): with PlatformSession(authorization=mock_token) as session: response = session.check_bib_is_research("12345678") assert response.status_code == 200
def test_get_bib_itmes_Timeout_exception(self, mock_token, mock_timeout): with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError): session.get_bib_items("12345678")
def test_check_bib_is_research_with_invald_id(self, mock_token): err_msg = "Invalid Sierra number passed." with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError) as exc: session.check_bib_is_research("a12345678") assert err_msg in str(exc.value)
def test_get_bib_items_unexpected_exception( self, mock_token, mock_unexpected_error ): with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError): session.get_bib_items("12345678")
def test_check_bib_is_research_unexpected_exception( self, mock_token, mock_unexpected_error ): with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError): session.check_bib_is_research("12345678")
def test_get_item_list_arguments_errors(self, mock_token, id_arg, ba_arg, bi_arg): err_msg = "Missing required positional argument." with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError) as exc: session.get_item_list(id_arg, ba_arg, bi_arg) assert err_msg in str(exc.value)
def test_search_standardNos_unexpected_exception( self, mock_token, mock_unexpected_error ): with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError): session.search_standardNos(keywords="12345678")
def test_target_argument(self, arg, expectation, mock_token): assert ( PlatformSession(authorization=mock_token, target=arg).base_url == expectation )
def test_search_controlNos_successful_request( self, mock_token, mock_successful_session_get_response ): with PlatformSession(authorization=mock_token) as session: response = session.search_controlNos(keywords=[12345, 12346]) assert response.status_code == 200
def test_get_item_list_correct_ids( self, mock_token, id_arg, ba_arg, bi_arg, mock_successful_session_get_response ): with PlatformSession(authorization=mock_token) as session: with does_not_raise(): session.get_item_list(id_arg, ba_arg, bi_arg)
def test_search_controlNos_BookopsPlatformError_exception( self, mock_token, mock_bookopsplatformerror ): with PlatformSession(authorization=mock_token) as session: with pytest.raises(BookopsPlatformError): session.search_controlNos(keywords="12345678")
def test_get_bib_items_url(self, mock_token): with PlatformSession(authorization=mock_token) as session: assert ( session._get_bib_items_url(1234567, "sierra-nypl") == "https://platform.nypl.org/api/v0.1/bibs/sierra-nypl/1234567/items" )