Esempio n. 1
0
    def test_isbns(self):
        work = make_work(editions=[
                    make_edition(isbn_10=["123456789X"])])
        d = build_data(work)
        assert d['isbn'] == ['123456789X', '9781234567897']

        work = make_work(editions=[
                    make_edition(isbn_10=["9781234567897"])])
        d = build_data(work)
        assert d['isbn'] == ['123456789X', '9781234567897']
Esempio n. 2
0
    def test_ia_boxid(self):
        w = make_work()
        update_work.data_provider = FakeDataProvider([w, make_edition(w)])
        d = build_data(w)
        assert 'ia_box_id' not in d

        w = make_work()
        update_work.data_provider = FakeDataProvider([w, make_edition(w, ia_box_id='foo')])
        d = build_data(w)
        assert 'ia_box_id' in d
        assert d['ia_box_id'] == ['foo']
Esempio n. 3
0
    def test_ia_boxid(self):
        e = make_edition()
        w = make_work(editions=[e])
        d = build_data(w)
        assert 'ia_box_id' not in d

        e = make_edition(ia_box_id='foo')
        w = make_work(editions=[e])
        d = build_data(w)
        assert 'ia_box_id' in d
        assert d['ia_box_id'] == ['foo']
Esempio n. 4
0
    def test_edition_count_when_editions_on_work(self):
        work = make_work()

        d = build_data(work)
        assert d['edition_count'] == 0

        work['editions'] = [make_edition()]
        d = build_data(work)
        assert d['edition_count'] == 1

        work['editions'] = [make_edition(), make_edition()]
        d = build_data(work)
        assert d['edition_count'] == 2
Esempio n. 5
0
    def test_isbns(self):
        work = make_work()
        update_work.data_provider = FakeDataProvider([
            work,
            make_edition(work, isbn_10=["123456789X"])
        ])
        d = build_data(work)
        assert d['isbn'] == ['123456789X', '9781234567897']

        update_work.data_provider = FakeDataProvider([
            work,
            make_edition(work, isbn_10=["9781234567897"])
        ])
        d = build_data(work)
        assert d['isbn'] == ['123456789X', '9781234567897']
Esempio n. 6
0
 def test_identifiers(self):
     work = make_work(editions=[
                 make_edition(identifiers={"librarything": ["lt-1"]}),
                 make_edition(identifiers={"librarything": ["lt-2"]})
     ])
     d = build_data(work)
     assert sorted(d['id_librarything']) == ['lt-1', 'lt-2']
Esempio n. 7
0
    def test_edition_key(self):
        work = make_work(editions=[
            make_edition(key="/books/OL1M"),
            make_edition(key="/books/OL2M"),
            make_edition(key="/books/OL3M")])

        d = build_data(work)
        assert d['edition_key'] == ["OL1M", "OL2M", "OL3M"]
Esempio n. 8
0
 def test_other_identifiers(self):
     work = make_work(editions=[
                 make_edition(oclc_numbers=["123"], lccn=["lccn-1", "lccn-2"]),
                 make_edition(oclc_numbers=["234"], lccn=["lccn-2", "lccn-3"]),
     ])
     d = build_data(work)
     assert sorted(d['oclc']) == ['123', '234']
     assert sorted(d['lccn']) == ['lccn-1', 'lccn-2', 'lccn-3']
Esempio n. 9
0
 def test_identifiers(self):
     work = make_work()
     update_work.data_provider = FakeDataProvider([
         work,
         make_edition(work, identifiers={"librarything": ["lt-1"]}),
         make_edition(work, identifiers={"librarything": ["lt-2"]})
     ])
     d = build_data(work)
     assert sorted(d['id_librarything']) == ['lt-1', 'lt-2']
Esempio n. 10
0
 def test_other_identifiers(self):
     work = make_work()
     update_work.data_provider = FakeDataProvider([
         work,
         make_edition(work, oclc_numbers=["123"], lccn=["lccn-1", "lccn-2"]),
         make_edition(work, oclc_numbers=["234"], lccn=["lccn-2", "lccn-3"]),
     ])
     d = build_data(work)
     assert sorted(d['oclc']) == ['123', '234']
     assert sorted(d['lccn']) == ['lccn-1', 'lccn-2', 'lccn-3']
Esempio n. 11
0
 def test_author_info(self):
     w = make_work(authors=[
             {"author": make_author(key="/authors/OL1A", name="Author One", alternate_names=["Author 1"])},
             {"author": make_author(key="/authors/OL2A", name="Author Two")}
         ])
     d = build_data(w)
     assert d['author_name'] == ["Author One", "Author Two"]
     assert d['author_key'] == ['OL1A', 'OL2A']
     assert d['author_facet'] == ['OL1A Author One', 'OL2A Author Two']
     assert d['author_alternative_name'] == ["Author 1"]
Esempio n. 12
0
    def test_edition_key(self):
        work = make_work()
        update_work.data_provider = FakeDataProvider([
            work,
            make_edition(work, key="/books/OL1M"),
            make_edition(work, key="/books/OL2M"),
            make_edition(work, key="/books/OL3M")
        ])

        d = build_data(work)
        assert d['edition_key'] == ["OL1M", "OL2M", "OL3M"]
Esempio n. 13
0
 def test_with_one_printdisabled_edition(self):
     e = make_edition(key="/books/OL1M", ocaid='foo00bar', _ia_meta={"collection":['printdisabled', 'americana']})
     w = make_work(editions=[e])
     d = build_data(w)
     assert d['has_fulltext'] == True
     assert d['public_scan_b'] == False
     assert d['printdisabled_s'] == 'OL1M'
     assert 'lending_edition_s' not in d
     assert d['ia'] == ['foo00bar']
     assert d['ia_collection_s'] == "printdisabled;americana"
     assert d['edition_count'] == 1
     assert d['ebook_count_i'] == 1
Esempio n. 14
0
    def test_simple_work(self):
        work = {
            "key": "/works/OL1M",
            "type": {"key": "/type/work"},
            "title": "Foo"
        }

        d = build_data(work)
        assert d["key"] == "/works/OL1M"
        assert d["title"] == "Foo"
        assert d["has_fulltext"] == False
        assert d["edition_count"] == 0
Esempio n. 15
0
    def test_edition_count_when_editions_in_data_provider(self):
        work = make_work()
        d = build_data(work)
        assert d['edition_count'] == 0

        update_work.data_provider = FakeDataProvider([
            work,
            make_edition(work)
        ])

        d = build_data(work)
        assert d['edition_count'] == 1

        update_work.data_provider = FakeDataProvider([
            work,
            make_edition(work),
            make_edition(work)
        ])

        d = build_data(work)
        assert d['edition_count'] == 2
Esempio n. 16
0
 def test_with_two_lending_editions(self):
     e1 = make_edition(key="/books/OL1M", ocaid='foo01bar', _ia_meta={"collection":['lendinglibrary', 'americana']})
     e2 = make_edition(key="/books/OL2M", ocaid='foo02bar', _ia_meta={"collection":['lendinglibrary', 'internetarchivebooks']})
     w = make_work(editions=[e1, e2])
     d = build_data(w)
     assert d['has_fulltext'] == True
     assert d['public_scan_b'] == False
     assert 'printdisabled_s' not in d
     assert d['lending_edition_s'] == 'OL1M'
     assert d['ia'] == ['foo01bar', 'foo02bar']
     assert d['ia_collection_s'] == "lendinglibrary;americana;internetarchivebooks"
     assert d['edition_count'] == 2
     assert d['ebook_count_i'] == 2
Esempio n. 17
0
    def test_subjects(self):
        w = make_work(subjects=["a", "b c"])
        d = build_data(w)

        assert d['subject'] == ['a', "b c"]
        assert d['subject_facet'] == ['a', "b c"]
        assert d['subject_key'] == ['a', "b_c"]

        assert "people" not in d
        assert "place" not in d
        assert "time" not in d

        w = make_work(
                subjects=["a", "b c"],
                subject_places=["a", "b c"],
                subject_people=["a", "b c"],
                subject_times=["a", "b c"])
        d = build_data(w)

        for k in ['subject', 'person', 'place', 'time']:
            assert d[k] == ['a', "b c"]
            assert d[k + '_facet'] == ['a', "b c"]
            assert d[k + '_key'] == ['a', "b_c"]
Esempio n. 18
0
    def test_simple(self):
        work = {
            "key": "/works/OL1M",
            "type": {"key": "/type/work"},
            "title": "Foo"
        }

        d = build_data(work)
        assert self.match_dicts(self.strip_empty_lists(d), {
            "key": "OL1M",
            "title": "Foo",
            "has_fulltext": False,
            "edition_count": 0,
        })
Esempio n. 19
0
    def test_publish_year(self):
        work = make_work(editions=[
                    make_edition(publish_date="2000"),
                    make_edition(publish_date="Another 2000"),

                    ## Doesn't seems to be handling this case
                    make_edition(publish_date="2001-01-02"),

                    make_edition(publish_date="01-02-2003"),
                    make_edition(publish_date="Jan 2002"),
                    make_edition(publish_date="Bad date 12")])

        d = build_data(work)
        assert set(d['publish_year']) == set(["2000", "2002", "2003"])
        assert d["first_publish_year"] == 2000
Esempio n. 20
0
 def test_with_one_inlibrary_edition(self):
     w = make_work()
     update_work.data_provider = FakeDataProvider([
         w,
         make_edition(w, key="/books/OL1M", ocaid='foo00bar',
                      _ia_meta={"collection": ['printdisabled', 'inlibrary']})
     ])
     d = build_data(w)
     assert d['has_fulltext'] == True
     assert d['public_scan_b'] == False
     assert d['printdisabled_s'] == 'OL1M'
     assert d['lending_edition_s'] == 'OL1M'
     assert d['ia'] == ['foo00bar']
     assert d['ia_collection_s'] == "printdisabled;inlibrary"
     assert d['edition_count'] == 1
     assert d['ebook_count_i'] == 1
Esempio n. 21
0
    def test_with_multliple_editions(self):
        e1 = make_edition(key="/books/OL1M")
        e2 = make_edition(key="/books/OL2M", ocaid='foo00bar', _ia_meta={"collection":['americana']})
        e3 = make_edition(key="/books/OL3M", ocaid='foo01bar', _ia_meta={"collection":['lendinglibrary', 'americana']})
        e4 = make_edition(key="/books/OL4M", ocaid='foo02bar', _ia_meta={"collection":['printdisabled', 'inlibrary']})
        w = make_work(editions=[e1, e2, e3, e4])
        d = build_data(w)
        assert d['has_fulltext'] == True
        assert d['public_scan_b'] == True
        assert d['printdisabled_s'] == 'OL4M'
        assert d['lending_edition_s'] == 'OL3M'
        assert d['ia'] == ['foo00bar', 'foo01bar', 'foo02bar']
        assert sorted(d['ia_collection_s'].split(";")) == ["americana", "inlibrary", "lendinglibrary", "printdisabled"]

        assert d['edition_count'] == 4
        assert d['ebook_count_i'] == 3
Esempio n. 22
0
    def test_publish_year(self):
        test_dates = [
            "2000",
            "Another 2000",
            "2001-01-02",  # Doesn't seems to be handling this case
            "01-02-2003",
            "Jan 2002",
            "Bad date 12"
        ]
        work = make_work()
        update_work.data_provider = FakeDataProvider(
            [work] +
            [make_edition(work, publish_date=date) for date in test_dates])

        d = build_data(work)
        assert sorted(d['publish_year']) == ["2000", "2002", "2003"]
        assert d["first_publish_year"] == 2000
Esempio n. 23
0
    def test_with_multiple_editions(self):
        w = make_work()
        update_work.data_provider = FakeDataProvider([
            w,
            make_edition(w, key="/books/OL1M"),
            make_edition(w, key="/books/OL2M", ocaid='foo00bar', _ia_meta={"collection": ['americana']}),
            make_edition(w, key="/books/OL3M", ocaid='foo01bar', _ia_meta={"collection": ['lendinglibrary', 'americana']}),
            make_edition(w, key="/books/OL4M", ocaid='foo02bar', _ia_meta={"collection": ['printdisabled', 'inlibrary']})
        ])
        d = build_data(w)
        assert d['has_fulltext'] == True
        assert d['public_scan_b'] == True
        assert d['printdisabled_s'] == 'OL4M'
        assert d['lending_edition_s'] == 'OL3M'
        assert d['ia'] == ['foo00bar', 'foo01bar', 'foo02bar']
        assert sorted(d['ia_collection_s'].split(";")) == ["americana", "inlibrary", "lendinglibrary", "printdisabled"]

        assert d['edition_count'] == 4
        assert d['ebook_count_i'] == 3
Esempio n. 24
0
 def test_with_one_printdisabled_edition(self):
     w = make_work()
     update_work.data_provider = FakeDataProvider([
         w,
         make_edition(
             w,
             key="/books/OL1M",
             ocaid='foo00bar',
             _ia_meta={"collection": ['printdisabled', 'americana']})
     ])
     d = build_data(w)
     assert d['has_fulltext'] == True
     assert d['public_scan_b'] == False
     assert d['printdisabled_s'] == 'OL1M'
     assert 'lending_edition_s' not in d
     assert d['ia'] == ['foo00bar']
     assert d['ia_collection_s'] == "printdisabled;americana"
     assert d['edition_count'] == 1
     assert d['ebook_count_i'] == 1
Esempio n. 25
0
 def test_with_one_inlibrary_edition(self):
     w = make_work()
     update_work.data_provider = FakeDataProvider([
         w,
         make_edition(
             w,
             key="/books/OL1M",
             ocaid='foo00bar',
             _ia_meta={"collection": ['printdisabled', 'inlibrary']})
     ])
     d = build_data(w)
     assert d['has_fulltext'] is True
     assert d['public_scan_b'] is False
     assert d['printdisabled_s'] == 'OL1M'
     assert d['lending_edition_s'] == 'OL1M'
     assert d['ia'] == ['foo00bar']
     assert sss(d['ia_collection_s']) == sss("printdisabled;inlibrary")
     assert d['edition_count'] == 1
     assert d['ebook_count_i'] == 1
Esempio n. 26
0
 def test_with_two_lending_editions(self):
     w = make_work()
     update_work.data_provider = FakeDataProvider([
         w,
         make_edition(w, key="/books/OL1M", ocaid='foo01bar',
                      _ia_meta={"collection": ['lendinglibrary', 'americana']}),
         make_edition(w, key="/books/OL2M", ocaid='foo02bar',
                      _ia_meta={"collection": ['lendinglibrary', 'internetarchivebooks']})
     ])
     d = build_data(w)
     assert d['has_fulltext'] is True
     assert d['public_scan_b'] is False
     assert 'printdisabled_s' not in d
     assert d['lending_edition_s'] == 'OL1M'
     assert sorted(d['ia']) == ['foo01bar', 'foo02bar']
     assert sss(d['ia_collection_s']) == sss(
         "lendinglibrary;americana;internetarchivebooks"
     )
     assert d['edition_count'] == 2
     assert d['ebook_count_i'] == 2
Esempio n. 27
0
    def test_with_multiple_editions(self):
        w = make_work()
        update_work.data_provider = FakeDataProvider([
            w,
            make_edition(w, key="/books/OL1M"),
            make_edition(w, key="/books/OL2M", ocaid='foo00bar', _ia_meta={"collection": ['americana']}),
            make_edition(w, key="/books/OL3M", ocaid='foo01bar', _ia_meta={"collection": ['lendinglibrary', 'americana']}),
            make_edition(w, key="/books/OL4M", ocaid='foo02bar', _ia_meta={"collection": ['printdisabled', 'inlibrary']})
        ])
        d = build_data(w)
        assert d['has_fulltext'] is True
        assert d['public_scan_b'] is True
        assert d['printdisabled_s'] == 'OL4M'
        assert d['lending_edition_s'] == 'OL3M'
        assert sorted(d['ia']) == ['foo00bar', 'foo01bar', 'foo02bar']
        assert sss(d['ia_collection_s']) == sss(
            "americana;inlibrary;lendinglibrary;printdisabled"
        )

        assert d['edition_count'] == 4
        assert d['ebook_count_i'] == 3
Esempio n. 28
0
 def test_with_two_lending_editions(self):
     e1 = make_edition(
         key="/books/OL1M",
         ocaid='foo01bar',
         _ia_meta={"collection": ['lendinglibrary', 'americana']})
     e2 = make_edition(key="/books/OL2M",
                       ocaid='foo02bar',
                       _ia_meta={
                           "collection":
                           ['lendinglibrary', 'internetarchivebooks']
                       })
     w = make_work(editions=[e1, e2])
     d = build_data(w)
     assert d['has_fulltext'] == True
     assert d['public_scan_b'] == False
     assert 'printdisabled_s' not in d
     assert d['lending_edition_s'] == 'OL1M'
     assert d['ia'] == ['foo01bar', 'foo02bar']
     assert d[
         'ia_collection_s'] == "lendinglibrary;americana;internetarchivebooks"
     assert d['edition_count'] == 2
     assert d['ebook_count_i'] == 2