Esempio n. 1
0
def test_get_entry_type(bibtex_records):
    """Test."""
    (record_good, record_bad, record_empty, test_record) = bibtex_records

    for rec, in RecordMetadata.query.values(RecordMetadata.id):
        if rec != record_bad.record.id:
            r = Record.get_record(id_=rec)
            b = Bibtex(r)
            assert r['resource_type']['type'] == b._get_entry_type()

    assert test_record['resource_type']['type'] == \
        record_good._get_entry_type()
    assert 'default' == record_bad._get_entry_type()
Esempio n. 2
0
def bibtex_records(app, db, full_record):
    """Create some records for bibtex serializer."""
    test_bad_record = dict(recid='12345')

    r_good = ZenodoRecord.create(full_record,
                                 UUID("24029cb9-f0f8-4b72-94a7-bdf746f9d075"))
    r_bad = ZenodoRecord.create(test_bad_record,
                                UUID("0281c22c-266a-499b-8446-e12eff2f79b8"))
    db.session.commit()

    record_good = Bibtex(r_good)
    record_bad = Bibtex(r_bad)
    record_empty = Bibtex({})

    return (record_good, record_bad, record_empty, r_good)
Esempio n. 3
0
def test_format_long_title(full_record):
    """Test."""
    full_record['title'] = ("This is a very long title with whitespaces at "
                            "the end that used to bring us discomfort")
    full_record['resource_type']['subtype'] = 'article'
    bibtex = ("""@article{doe_2014_12345,\n"""
              """  author       = {Doe, John and\n"""
              """                  Doe, Jane and\n"""
              """                  Smith, John and\n"""
              """                  Nowak, Jack},\n"""
              """  title        = {{This is a very long title """
              """with whitespaces at the \n"""
              """                   end that used to """
              """bring us discomfort}},\n"""
              """  journal      = {Bam},\n"""
              """  year         = 2014,\n"""
              """  volume       = 20,\n"""
              """  number       = 2,\n"""
              """  pages        = 20,\n"""
              """  month        = feb,\n"""
              """  note         = {notes},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()
Esempio n. 4
0
def test_format_unpublished(full_record):
    """Test."""
    full_record['resource_type']['subtype'] = 'preprint'
    bibtex = ("""@unpublished{doe_2014_12345,\n"""
              """  author       = {Doe, John and\n"""
              """                  Doe, Jane and\n"""
              """                  Smith, John and\n"""
              """                  Nowak, Jack},\n"""
              """  title        = {Test title},\n"""
              """  note         = {notes},\n"""
              """  month        = feb,\n"""
              """  year         = 2014,\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()
    full_record['resource_type']['subtype'] = 'workingpaper'
    assert bibtex == Bibtex(full_record).format()
Esempio n. 5
0
def test_format_proceedings(full_record):
    """Test."""
    full_record['resource_type']['subtype'] = 'conferencepaper'
    del full_record['part_of']
    bibtex = ("""@proceedings{doe_2014_12345,\n"""
              """  title        = {Test title},\n"""
              """  year         = 2014,\n"""
              """  publisher    = {Jol},\n"""
              """  address      = {Staszkowka},\n"""
              """  month        = feb,\n"""
              """  note         = {notes},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()
Esempio n. 6
0
def test_format_default_type(full_record):
    """Test."""
    full_record['resource_type']['type'] = 'undefined_type'
    bibtex = ("""@misc{doe_2014_12345,\n"""
              """  author       = {Doe, John and\n"""
              """                  Doe, Jane and\n"""
              """                  Smith, John and\n"""
              """                  Nowak, Jack},\n"""
              """  title        = {Test title},\n"""
              """  month        = feb,\n"""
              """  year         = 2014,\n"""
              """  note         = {notes},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()
Esempio n. 7
0
def test_format_booklet(full_record):
    """Test."""
    full_record['resource_type']['subtype'] = 'book'
    del full_record['publication_date']
    bibtex = ("""@booklet{doe_12345,\n"""
              """  title        = {Test title},\n"""
              """  author       = {Doe, John and\n"""
              """                  Doe, Jane and\n"""
              """                  Smith, John and\n"""
              """                  Nowak, Jack},\n"""
              """  address      = {Staszkowka},\n"""
              """  note         = {notes},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()
Esempio n. 8
0
def test_format_dataset_type(full_record):
    """Test."""
    full_record['resource_type']['type'] = 'dataset'
    bibtex = ("""@dataset{doe_2014_12345,\n"""
              """  author       = {Doe, John and\n"""
              """                  Doe, Jane and\n"""
              """                  Smith, John and\n"""
              """                  Nowak, Jack},\n"""
              """  title        = {Test title},\n"""
              """  month        = feb,\n"""
              """  year         = 2014,\n"""
              """  note         = {notes},\n"""
              """  publisher    = {Jol},\n"""
              """  version      = {1.2.5},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()
Esempio n. 9
0
def test_format_book(full_record):
    """Test."""
    full_record['resource_type']['subtype'] = 'book'
    bibtex = ("""@book{doe_2014_12345,\n"""
              """  author       = {Doe, John and\n"""
              """                  Doe, Jane and\n"""
              """                  Smith, John and\n"""
              """                  Nowak, Jack},\n"""
              """  title        = {Test title},\n"""
              """  publisher    = {Jol},\n"""
              """  year         = 2014,\n"""
              """  volume       = 20,\n"""
              """  address      = {Staszkowka},\n"""
              """  month        = feb,\n"""
              """  note         = {notes},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()
Esempio n. 10
0
def test_format_article(full_record):
    """Test."""
    full_record['resource_type']['subtype'] = 'article'
    bibtex = ("""@article{doe_2014_12345,\n"""
              """  author       = {Doe, John and\n"""
              """                  Doe, Jane and\n"""
              """                  Smith, John and\n"""
              """                  Nowak, Jack},\n"""
              """  title        = {Test title},\n"""
              """  journal      = {Bam},\n"""
              """  year         = 2014,\n"""
              """  volume       = 20,\n"""
              """  number       = 2,\n"""
              """  pages        = 20,\n"""
              """  month        = feb,\n"""
              """  note         = {notes},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()
Esempio n. 11
0
def test_format_manual(full_record):
    """Test."""
    full_record['resource_type']['subtype'] = 'technicalnote'
    bibtex = ("""@manual{doe_2014_12345,\n"""
              """  title        = {Test title},\n"""
              """  author       = {Doe, John and\n"""
              """                  Doe, Jane and\n"""
              """                  Smith, John and\n"""
              """                  Nowak, Jack},\n"""
              """  address      = {Staszkowka},\n"""
              """  month        = feb,\n"""
              """  year         = 2014,\n"""
              """  note         = {notes},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()

    full_record['creators'].append({
        'name': 'Bar, Fuu',
        'affiliation': 'CERN',
        'orcid': '',
        'familyname': 'Bar',
        'givennames': 'Fuu'
    })
    bibtex = ("""@manual{doe_2014_12345,\n"""
              """  title        = {Test title},\n"""
              """  author       = {Doe, John and\n"""
              """                  Doe, Jane and\n"""
              """                  Smith, John and\n"""
              """                  Nowak, Jack and\n"""
              """                  Bar, Fuu},\n"""
              """  address      = {Staszkowka},\n"""
              """  month        = feb,\n"""
              """  year         = 2014,\n"""
              """  note         = {notes},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()

    authors = ""
    for i in range(0, 50):
        full_record['creators'].append({
            'name': 'Bar, Fuu{0}'.format(i),
            'affiliation': 'CERN',
            'orcid': '',
            'familyname': 'Bar',
            'givennames': 'Fuu{0}'.format(i)
        })
        authors += "                  Bar, Fuu{0}".format(i)
        if i != 49:
            authors += " and\n"

    bibtex = ("@manual{doe_2014_12345,\n"
              "  title        = {Test title},\n"
              "  author       = {Doe, John and\n"
              "                  Doe, Jane and\n"
              "                  Smith, John and\n"
              "                  Nowak, Jack and\n"
              "                  Bar, Fuu and\n" + authors + "},\n"
              "  address      = {Staszkowka},\n"
              "  month        = feb,\n"
              "  year         = 2014,\n"
              "  note         = {notes},\n"
              "  doi          = {10.1234/foo.bar},\n"
              "  url          = {https://doi.org/10.1234/foo.bar}\n"
              "}")
    assert bibtex == Bibtex(full_record).format()

    full_record['creators'] = full_record['creators'][:1]
    bibtex = ("""@manual{doe_2014_12345,\n"""
              """  title        = {Test title},\n"""
              """  author       = {Doe, John},\n"""
              """  address      = {Staszkowka},\n"""
              """  month        = feb,\n"""
              """  year         = 2014,\n"""
              """  note         = {notes},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()
Esempio n. 12
0
def test_format_inproceedings(full_record):
    """Test."""
    full_record['resource_type']['subtype'] = 'conferencepaper'
    bibtex = ("""@inproceedings{doe_2014_12345,\n"""
              """  author       = {Doe, John and\n"""
              """                  Doe, Jane and\n"""
              """                  Smith, John and\n"""
              """                  Nowak, Jack},\n"""
              """  title        = {Test title},\n"""
              """  booktitle    = {Bum},\n"""
              """  year         = 2014,\n"""
              """  pages        = 20,\n"""
              """  publisher    = {Jol},\n"""
              """  address      = {Staszkowka},\n"""
              """  month        = feb,\n"""
              """  note         = {notes},\n"""
              """  venue        = """
              """{Harvard-Smithsonian Center for Astrophysics},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()

    del full_record['journal']
    full_record['part_of']['pages'] = "30"
    bibtex = ("""@inproceedings{doe_2014_12345,\n"""
              """  author       = {Doe, John and\n"""
              """                  Doe, Jane and\n"""
              """                  Smith, John and\n"""
              """                  Nowak, Jack},\n"""
              """  title        = {Test title},\n"""
              """  booktitle    = {Bum},\n"""
              """  year         = 2014,\n"""
              """  pages        = 30,\n"""
              """  publisher    = {Jol},\n"""
              """  address      = {Staszkowka},\n"""
              """  month        = feb,\n"""
              """  note         = {notes},\n"""
              """  venue        = """
              """{Harvard-Smithsonian Center for Astrophysics},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()

    del full_record['imprint']
    full_record['part_of']['publisher'] = "hello"
    bibtex = ("""@inproceedings{doe_2014_12345,\n"""
              """  author       = {Doe, John and\n"""
              """                  Doe, Jane and\n"""
              """                  Smith, John and\n"""
              """                  Nowak, Jack},\n"""
              """  title        = {Test title},\n"""
              """  booktitle    = {Bum},\n"""
              """  year         = 2014,\n"""
              """  pages        = 30,\n"""
              """  publisher    = {hello},\n"""
              """  month        = feb,\n"""
              """  note         = {notes},\n"""
              """  venue        = """
              """{Harvard-Smithsonian Center for Astrophysics},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()

    del full_record['meeting']
    bibtex = ("""@inproceedings{doe_2014_12345,\n"""
              """  author       = {Doe, John and\n"""
              """                  Doe, Jane and\n"""
              """                  Smith, John and\n"""
              """                  Nowak, Jack},\n"""
              """  title        = {Test title},\n"""
              """  booktitle    = {Bum},\n"""
              """  year         = 2014,\n"""
              """  pages        = 30,\n"""
              """  publisher    = {hello},\n"""
              """  month        = feb,\n"""
              """  note         = {notes},\n"""
              """  doi          = {10.1234/foo.bar},\n"""
              """  url          = {https://doi.org/10.1234/foo.bar}\n"""
              """}""")
    assert bibtex == Bibtex(full_record).format()