示例#1
0
 def test_map_data(self, stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     meta = reader._map_data(reader.datas[0])
     assert meta.sbid == 22259002
     assert meta.sbn == "9781631491719,1631491719"
     assert meta.lcn == "2017022370"
     assert meta.did == "40CC3B3F-4C30-4685-B391-DB7B2EA91455"
     assert meta.sid == "1111111111,2222222222"
     assert meta.wcn is None
     assert (
         meta.title ==
         "saddest words electronic resource william faulkners civil war")
     assert meta.author == "gorra michael"
     assert meta.pubDate == "2020"
     assert meta.upgradeStamp is None
     assert meta.upgraded is False
     assert meta.upgradeSourceId is None
     assert meta.urls == [
         {
             "uTypeId": 1,
             "url": "http://link.overdrive.com/?content",
         },
         {
             "uTypeId": 2,
             "url": "https://samples.overdrive.com/?sample_url",
         },
         {
             "uTypeId": 3,
             "url": "https://img1.od-cdn.com/ImageType-100/image.jpg",
         },
         {
             "uTypeId": 4,
             "url": "https://img1.od-cdn.com/ImageType-200/thumbnail.jpg",
         },
     ]
示例#2
0
    def test_parse_urls(self, stub_nyp_platform_200_response):
        reader = PlatformResponseReader(stub_nyp_platform_200_response)
        urls = reader._parse_urls(reader.datas[0])

        loop = 1
        for u in urls:
            if loop == 1:
                assert u == {
                    "uTypeId": 1,
                    "url": "http://link.overdrive.com/?content",
                }
            elif loop == 2:
                assert u == {
                    "uTypeId": 2,
                    "url": "https://samples.overdrive.com/?sample_url",
                }
            elif loop == 3:
                assert u == {
                    "uTypeId": 3,
                    "url": "https://img1.od-cdn.com/ImageType-100/image.jpg",
                }
            elif loop == 4:
                assert u == {
                    "uTypeId": 4,
                    "url":
                    "https://img1.od-cdn.com/ImageType-200/thumbnail.jpg",
                }
            loop += 1
示例#3
0
 def test_generator(self, stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     loop = 0
     for record in reader:
         loop += 1
         if loop == 1:
             assert record.sbid == 22259002
             assert record.did == "40CC3B3F-4C30-4685-B391-DB7B2EA91455"
         elif loop == 2:
             assert record.sbid == 22259003
             assert record.did == "4E7547BF-6D42-43F4-9180-8FCF302497F3"
         elif loop == 3:
             assert record.sbid == 19099433
             assert record.did is None
     assert loop == 3
示例#4
0
 def test_other_error_response(self, stub_nyp_platform_401_response):
     err_msg = "Platform 401 error: {'statusCode': 401, 'type': 'unauthorized', 'message': 'Unauthorized'}"
     with pytest.raises(NightShiftError) as exc:
         PlatformResponseReader(stub_nyp_platform_401_response)
     assert err_msg in str(exc.value)
示例#5
0
 def test_determine_url_type_id(self, url, expectation,
                                stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._determine_url_type_id(url) == expectation
示例#6
0
 def test_parse_urls_no_urls(self, stub_nyp_platform_200_response,
                             stub_platform_record_missing):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._parse_urls(stub_platform_record_missing) == []
示例#7
0
 def test_parse_distributor_number_missing(self,
                                           stub_nyp_platform_200_response,
                                           stub_platform_record_missing):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._parse_distributor_number(
         stub_platform_record_missing) is None
示例#8
0
 def test_parse_control_number(self, stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._parse_control_number(reader.datas[0]) == "ODN0005077214"
示例#9
0
 def test_parse_distributor_number(self, stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert (reader._parse_distributor_number(
         reader.datas[0]) == "40CC3B3F-4C30-4685-B391-DB7B2EA91455")
示例#10
0
 def test_is_upgraded(self, arg, expectation,
                      stub_nyp_platform_200_response, mock_datetime_now):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._is_upgraded(arg) == expectation
示例#11
0
 def test_parse_isbns(self, stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._parse_isbns(
         reader.datas[0]) == "9781631491719,1631491719"
示例#12
0
 def test_parse_publication_date(self, stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._parse_publication_date(reader.datas[0]) == "2020"
示例#13
0
 def test_get_variable_field_content(self, tag, sub, expectation,
                                     stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert (reader._get_variable_field_content(
         tag, sub, reader.datas[0]) == expectation)
示例#14
0
 def test_parse_author(self, stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._parse_author(reader.datas[0]) == "gorra michael"
示例#15
0
 def test_parse_title(self, stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert (reader._parse_title(
         reader.datas[0]
     ) == "saddest words electronic resource william faulkners civil war")
示例#16
0
 def test_parse_worldcat_number(self, arg, expectation,
                                stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._parse_worldcat_number(arg) == expectation
示例#17
0
 def test_parse_standard_nubers_missing(self,
                                        stub_nyp_platform_200_response,
                                        stub_platform_record_missing):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._parse_standard_numbers(
         stub_platform_record_missing) is None
示例#18
0
 def test_parse_standard_nubers(self, stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert (reader._parse_standard_numbers(
         reader.datas[0]) == "1111111111,2222222222")
示例#19
0
 def test_is_deleted(self, stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._is_deleted(reader.datas[2]) is True
示例#20
0
 def test_successful_response(self, stub_nyp_platform_200_response,
                              stub_nyp_responses):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader.datas == stub_nyp_responses["data"]
示例#21
0
 def test_parse_bib_id(self, stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._parse_bib_id(reader.datas[0]) == 22259002
示例#22
0
 def test_parse_sierra_format_id(self, arg, expectation,
                                 stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._parse_sierra_format_id(arg) == expectation
示例#23
0
 def test_parse_isbns_no_field(self, stub_nyp_platform_200_response,
                               stub_platform_record_missing):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._parse_isbns(stub_platform_record_missing) is None
示例#24
0
 def test_404_response(self, stub_nyp_platform_404_response):
     reader = PlatformResponseReader(stub_nyp_platform_404_response)
     assert reader.datas == []
示例#25
0
 def test_parse_lccn(self, stub_nyp_platform_200_response):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._parse_lccn(reader.datas[0]) == "2017022370"
示例#26
0
 def test_parses_lccn_missing(self, stub_nyp_platform_200_response,
                              stub_platform_record_missing):
     reader = PlatformResponseReader(stub_nyp_platform_200_response)
     assert reader._parse_lccn(stub_platform_record_missing) is None