Ejemplo n.º 1
0
 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"
         )
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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"
Ejemplo n.º 4
0
 def test_default_base_url_parameter(self, mock_token):
     assert (
         PlatformSession(authorization=mock_token).base_url
         == "https://platform.nypl.org/api/v0.1"
     )
Ejemplo n.º 5
0
 def test_default_agent_parameter(self, mock_token):
     with PlatformSession(authorization=mock_token) as session:
         assert session.headers["User-Agent"] == f"{__title__}/{__version__}"
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 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")
Ejemplo n.º 12
0
 def test_prep_sierra_numbers(self, mock_token, arg, expectation):
     with PlatformSession(authorization=mock_token) as session:
         assert session._prep_sierra_numbers(arg) == expectation
Ejemplo n.º 13
0
 def test_prep_multi_keywords(self, mock_token, arg, expectation):
     with PlatformSession(authorization=mock_token) as session:
         assert session._prep_multi_keywords(arg) == expectation
Ejemplo n.º 14
0
 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"
         )
Ejemplo n.º 15
0
 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
Ejemplo n.º 16
0
 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")
Ejemplo n.º 17
0
 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")
Ejemplo n.º 18
0
 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)
Ejemplo n.º 19
0
 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
Ejemplo n.º 20
0
 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")
Ejemplo n.º 21
0
 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)
Ejemplo n.º 22
0
 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")
Ejemplo n.º 23
0
 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")
Ejemplo n.º 24
0
 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)
Ejemplo n.º 25
0
 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")
Ejemplo n.º 26
0
 def test_target_argument(self, arg, expectation, mock_token):
     assert (
         PlatformSession(authorization=mock_token, target=arg).base_url
         == expectation
     )
Ejemplo n.º 27
0
 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
Ejemplo n.º 28
0
 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)
Ejemplo n.º 29
0
 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")
Ejemplo n.º 30
0
 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"
         )