def citeas_product_get(id): if id.endswith('.pdf'): return jsonify({'error_message': 'PDF documents are not supported.'}) elif id.endswith(('.doc', 'docx')): return jsonify({'error_message': 'Word documents are not supported.'}) else: my_software = Software(id) my_software.find_metadata() return jsonify(my_software.to_dict())
def test_source_preview(): my_software = Software('https://cran.r-project.org/web/packages/stringr') my_software.find_metadata() resp = my_software.to_dict() provenance = resp['provenance'][8]['source_preview'] assert provenance['title'] == '<i>Snapshot of title data found at https://cran.r-project.org/web/packages/stringr/DESCRIPTION.</i><br>Package: stringr<br />Title: <span class="highlight">' \ 'Simple, Consistent Wrappers for Common String Operations</span><br />Version: 1.4.0<br />Authors@R: <br /> c(person(given = "Hadley",<br />' \ ' family = "Wickham",<br /> role = c("aut", "cre", "cph"),<br /> ' \ 'email = "[email protected]"),<br /> person(given = "RStudio",<br /> role = c("cph", "fnd")))<br />' \ 'Description: A consistent, simple and easy to use set of<br /> wrappers around the fantastic 'stringi' assert provenance['author'] == '<i>Snapshot of author data found at https://cran.r-project.org/web/packages/stringr/DESCRIPTION.</i><br>Package: ' \ 'stringr<br />Title: Simple, Consistent Wrappers for Common String Operations<br />Version: 1.4.0<br />Authors@R: <br /> ' \ 'c(person(given = "<span class="highlight">Hadley</span>",<br /> family = "<span class="highlight">Wickham</span>",<br /> ' \ 'role = c("aut", "cre", "cph"),<br /> email = "*****@*****.**"),<br /> person(given = "RStudio",<br /> ' \ 'role = c("cph", "fnd")))<br />Description: A consistent, simple and easy to use set of<br /> wrappers around the fantastic stringi package. All function and<br /> ' \ 'argument names (and positions) are consistent, all functions deal with<br /> "NA"s and zero length vectors in the same way, and the output from<br /> one function is easy t' assert provenance['year'] == '<i>Snapshot of year data found at https://cran.r-project.org/web/packages/stringr/DESCRIPTION.</i><br>tringr<br />BugReports: ' \ 'https://github.com/tidyverse/stringr/issues<br />Depends: R (>= 3.1)<br />Imports: glue (>= 1.2.0), magrittr, stringi (>= 1.1.7)<br />Suggests: covr, htmltools, ' \ 'htmlwidgets, knitr, rmarkdown, testthat<br />VignetteBuilder: knitr<br />Encoding: UTF-8<br />LazyData: true<br />RoxygenNote: 6.1.1<br />' \ 'NeedsCompilation: no<br />Packaged: 2019-02-09 16:03:19 UTC; hadley<br />Author: Hadley Wickham [aut, cre, cph],<br /> RStudio [cph, fnd]<br />' \ 'Maintainer: Hadley Wickham <[email protected]><br />Repository: CRAN<br />Date/Publication: <span class="highlight">2019-02-10 03:40:03 UTC</span><br />'
def test_provenance(): my_software = Software('http://yt-project.org') my_software.find_metadata() resp = my_software.to_dict() provenance = resp['provenance'] steps_with_content = [ { 'step_name': 'UserInputStep', 'parent_step_name': 'NoneType' }, { 'step_name': 'WebpageStep', 'parent_step_name': 'UserInputStep' }, { 'step_name': 'GithubRepoStep', 'parent_step_name': 'WebpageStep' }, { 'step_name': 'GithubCitationFileStep', 'parent_step_name': 'GithubRepoStep' }, { 'step_name': 'CrossrefResponseStep', 'parent_step_name': 'GithubCitationFileStep' }, { 'step_name': 'CrossrefResponseMetadataStep', 'parent_step_name': 'CrossrefResponseStep' }, ] steps_without_content = [{ 'step_name': 'CrossrefResponseStep', 'parent_step_name': 'UserInputStep' }, { 'step_name': 'ArxivResponseStep', 'parent_step_name': 'UserInputStep' }, { 'step_name': 'GithubRepoStep', 'parent_step_name': 'UserInputStep' }, { 'step_name': 'BitbucketRepoStep', 'parent_step_name': 'UserInputStep' }, { 'step_name': 'CranLibraryStep', 'parent_step_name': 'UserInputStep' }, { 'step_name': 'PypiLibraryStep', 'parent_step_name': 'UserInputStep' }, { 'step_name': 'RelationHeaderStep', 'parent_step_name': 'WebpageStep' }, { 'step_name': 'CrossrefResponseStep', 'parent_step_name': 'WebpageStep' }, { 'step_name': 'GithubCodemetaFileStep', 'parent_step_name': 'GithubRepoStep' }] for step in steps_with_content: for p in provenance: if p['name'] == step['step_name'] and p[ 'parent_step_name'] == step['parent_step_name']: assert p['has_content'] is True for step in steps_without_content: for p in provenance: if p['name'] == step['step_name'] and p[ 'parent_step_name'] == step['parent_step_name']: assert p['has_content'] is False
def test_citations(url, expected): my_software = Software(url) my_software.find_metadata() assert my_software.citation_plain == expected
def citeas_product_get(id): my_software = Software(id) my_software.find_metadata() return jsonify(my_software.to_dict())
def test_the_dois(self, test_data): (url, doi, expected) = test_data if doi: my_software = Software(doi) my_software.find_metadata() assert_equals(my_software.citation_plain, expected)