From 1334778634c22d2709834971a7f8d0a791a21e2b Mon Sep 17 00:00:00 2001 From: Koursaros93 Date: Tue, 14 Mar 2017 15:58:37 +0100 Subject: [PATCH] added book submission in literature suggest --- inspirehep/bat/pages/create_literature.py | 78 +++++++++++- inspirehep/modules/literaturesuggest/forms.py | 110 +++++++++++++++-- inspirehep/modules/literaturesuggest/tasks.py | 13 +- .../test_literature_suggestion_form.py | 32 +++++ tests/integration/fixtures/book_expected.json | 116 ++++++++++++++++++ tests/integration/fixtures/book_input.json | 60 +++++++++ tests/integration/test_formdata_to_model.py | 25 ++++ 7 files changed, 419 insertions(+), 15 deletions(-) create mode 100644 tests/integration/fixtures/book_expected.json create mode 100644 tests/integration/fixtures/book_input.json diff --git a/inspirehep/bat/pages/create_literature.py b/inspirehep/bat/pages/create_literature.py index d00444ebe1..1d48bc53e0 100644 --- a/inspirehep/bat/pages/create_literature.py +++ b/inspirehep/bat/pages/create_literature.py @@ -70,6 +70,35 @@ def _submit_thesis(): return ArsenicResponse(_submit_thesis) +def submit_book(input_data): + def _submit_book(): + return ( + 'The INSPIRE staff will review it and your changes will be added ' + 'to INSPIRE.' + ) in WebDriverWait(Arsenic(), 10).until( + EC.visibility_of_element_located( + ( + By.XPATH, + '(//div[@class="alert alert-success alert-form-success"])', + ) + ) + ).text + + _skip_import_data() + Arsenic().hide_title_bar() + _select_book() + _links_population(input_data) + _basic_info_population(input_data) + _book_info_population(input_data) + _references_comment_population(input_data) + Arsenic().find_element_by_xpath( + '//div[@id="webdeposit_form_accordion"]/div[4]/span/button' + ).click() + Arsenic().show_title_bar() + + return ArsenicResponse(_submit_book) + + def submit_journal_article_with_proceeding(input_data): def _submit_journal_article_with_proceeding(): return ( @@ -148,6 +177,36 @@ def _thesis_info_population(input_data): ) +def _book_info_population(input_data): + WebDriverWait(Arsenic(), 10).until( + EC.visibility_of_element_located((By.ID, 'publisher_name')) + ) + Arsenic().find_element_by_id('publisher_name').send_keys( + input_data['publisher-name'] + ) + Arsenic().find_element_by_id('publication_date').send_keys( + input_data['publication-date'] + ) + Arsenic().find_element_by_id('publication_place').send_keys( + input_data['publication-place'] + ) + Arsenic().find_element_by_id('book_edition').send_keys( + input_data['book-edition'] + ) + Arsenic().find_element_by_id('series_title').send_keys( + input_data['book-title'] + ) + Arsenic().find_element_by_id('series_volume').send_keys( + input_data['book-volume'] + ) + Arsenic().find_element_by_id('isbn-0-code').send_keys( + input_data['isbn'] + ) + Select(Arsenic().find_element_by_id('isbn-0-type_of_isbn')).select_by_value( + input_data['isbn_type'] + ) + + def _links_population(input_data): Arsenic().find_element_by_id('url').send_keys(input_data['pdf-1']) Arsenic().find_element_by_id('additional_url').send_keys( @@ -235,9 +294,7 @@ def _references_comment_population(input_data): ).send_keys(input_data['references']) WebDriverWait(Arsenic(), 10).until( - EC.visibility_of_element_located( - (By.ID, 'extra_comments') - ) + EC.visibility_of_element_located((By.ID, 'extra_comments')) ).send_keys(input_data['extra-comments']) @@ -500,6 +557,15 @@ def _skip_import_data(): null ).singleNodeValue.click()""" ) + Arsenic().execute_script( + """document.evaluate( + "//div[@id='webdeposit_form_accordion']/div[3]/div[10]/div[1]", + document, + null, + XPathResult.FIRST_ORDERED_NODE_TYPE, + null + ).singleNodeValue.click()""" + ) Arsenic().show_title_bar() @@ -507,3 +573,9 @@ def _select_thesis(): Select(Arsenic().find_element_by_id('type_of_doc')).select_by_value( 'thesis' ) + + +def _select_book(): + Select(Arsenic().find_element_by_id('type_of_doc')).select_by_value( + 'book' + ) diff --git a/inspirehep/modules/literaturesuggest/forms.py b/inspirehep/modules/literaturesuggest/forms.py index a63857c8fb..f5a0c0aa15 100644 --- a/inspirehep/modules/literaturesuggest/forms.py +++ b/inspirehep/modules/literaturesuggest/forms.py @@ -142,6 +142,18 @@ def defensedate_widget(field, **kwargs): return HTMLString(u''.join(html)) +def bookdate_widget(field, **kwargs): + """Date widget fot thesis.""" + field_id = kwargs.pop('id', field.id) + html = [u'
\ + \ +
' + % (BOOK_CLASS, html_params(id=field_id, + name=field_id, + value=field.data or ''))] + return HTMLString(u''.join(html)) + + class CheckboxButton(object): """Checkbox button.""" @@ -195,6 +207,29 @@ class AuthorInlineForm(INSPIREForm): ) +types_of_isbn = [("hardcover", _("Hardcover")), + ("online", _("Online")), + ("print", _("Print")), + ('softcover', _('Softcover')), + ('unknown', _('Unknown'))] + + +class BookInlineForm(INSPIREForm): + + code = fields.TextField( + widget_classes='form-control', + widget=ColumnInput(class_="col-xs-6", description="ISBN code"), + + export_key='full_name', + ) + + type_of_isbn = fields.SelectField( + label='type', + choices=types_of_isbn, + description=_('type'), + ) + + class UrlInlineForm(INSPIREForm): """Url inline form.""" @@ -254,22 +289,14 @@ class LiteratureForm(INSPIREForm): export_key='categories', ) - # isbn = ISBNField( - # label=_('ISBN'), - # widget_classes='form-control', - # ) - import_buttons = fields.SubmitField( label=_(' '), widget=import_buttons_widget ) types_of_doc = [("article", _("Article/Conference paper")), - ("thesis", _("Thesis"))] - - # ("chapter", _("Book Chapter")), - # ("book", _("Book")), - # ("proceedings", _("Proceedings"))] + ("thesis", _("Thesis")), + ('book', _('Book'))] type_of_doc = fields.SelectField( label='Type of Document', @@ -414,7 +441,6 @@ def _is_other_language(language): widget_classes='', widget=UnsortedDynamicListWidget(), ) - # ============== # Thesis related # ============== @@ -457,6 +483,63 @@ def _is_other_language(language): # default='', # widget_classes="form-control" + THESIS_CLASS, # ) + # ============ + # Book Info + # ============ + + publisher_name = fields.TextField( + label=_('Publisher Name'), + export_key='publisher_name', + widget_classes="form-control" + BOOK_CLASS, + ) + + publication_place = fields.TextField( + label=_('Place of Publication'), + export_key='publication_place', + widget_classes="form-control" + BOOK_CLASS, + ) + + book_edition = fields.TextField( + label=_('Book edition'), + export_key='book_edition', + widget_classes="form-control" + BOOK_CLASS, + ) + + series_title = fields.TextField( + label=_('Book series title'), + export_key='series_title', + widget_classes="form-control" + BOOK_CLASS, + ) + + series_volume = fields.TextField( + label=_('Book series volume'), + export_key='series_volume', + widget_classes="form-control" + BOOK_CLASS, + ) + + publication_date = fields.TextField( + label=_('Publication Date'), + description='Format: YYYY-MM-DD, YYYY-MM or YYYY.', + validators=[date_validator], + widget=bookdate_widget, + export_key='publication_date', + widget_classes="" + BOOK_CLASS, + ) + + isbn = fields.DynamicFieldList( + fields.FormField( + BookInlineForm, + widget=ExtendedListWidget( + item_widget=ItemWidget(), + html_tag='div', + ), + ), + label='ISBN', + add_label='Add another ISBN', + min_entries=1, + widget_classes="" + BOOK_CLASS, + export_key='isbn', + ) # ============ # Journal Info @@ -603,6 +686,9 @@ def _is_other_language(language): ('Thesis Information', ['degree_type', 'thesis_date', 'institution', 'supervisors', 'license_url']), + ('Book Information', + ['publisher_name', 'publication_date', 'publication_place', + 'book_edition', 'series_title', 'series_volume', 'isbn']), # ('Licenses and copyright', # ['license', 'license_url'], {'classes': 'collapse'}), ('Journal Information', @@ -623,6 +709,8 @@ def _is_other_language(language): field_sizes = { 'type_of_doc': 'col-xs-12 col-md-3', 'wrap_nonpublic_note': 'col-md-9', + 'publisher_name': 'col-xs-12 col-md-9', + 'publication_date': 'col-xs-12 col-md-4', 'thesis_date': 'col-xs-12 col-md-4', 'degree_type': 'col-xs-12 col-md-3', } diff --git a/inspirehep/modules/literaturesuggest/tasks.py b/inspirehep/modules/literaturesuggest/tasks.py index 555b45edee..dcd3837d62 100644 --- a/inspirehep/modules/literaturesuggest/tasks.py +++ b/inspirehep/modules/literaturesuggest/tasks.py @@ -58,7 +58,7 @@ def _is_arxiv_url(url): form_fields = copy.deepcopy(formdata) filter_empty_elements( - form_fields, ['authors', 'supervisors', 'report_numbers'] + form_fields, ['authors', 'supervisors', 'report_numbers', 'isbn'] ) builder = LiteratureBuilder(source='submitter') @@ -153,6 +153,17 @@ def _is_arxiv_url(url): date=form_fields.get('thesis_date') ) + if form_fields.get('type_of_doc') == 'book': + builder.add_book( + publisher=form_fields.get('publisher_name'), + place=form_fields.get('publication_place'), + date=form_fields.get('publication_date')) + builder.add_book_edition(edition=form_fields.get('book_edition')) + builder.add_book_series(title=form_fields.get('series_title'), + volume=form_fields.get('series_volume')) + for isbn_single in form_fields.get('isbn', []): + builder.add_isbns(isbn_single) + builder.add_accelerator_experiments_legacy_name( legacy_name=form_fields.get('experiment') ) diff --git a/tests/acceptance/test_literature_suggestion_form.py b/tests/acceptance/test_literature_suggestion_form.py index f54434e6b4..0703270102 100644 --- a/tests/acceptance/test_literature_suggestion_form.py +++ b/tests/acceptance/test_literature_suggestion_form.py @@ -30,6 +30,38 @@ holding_panel_literature_list, ) +def test_literature_create_book_manually(login): + input_data = { + 'pdf-1': 'pdf_url_correct', + 'pdf-2': 'pdf_another_url_correct', + 'title': 'My Title For Test', + 'language': 'ru', + 'title_translation': 'My Title was in Russian', + 'subject': 'Computing', + 'author-0': 'Mister White', + 'author-0-affiliation': 'Wisconsin U., Madison', + 'author-1': 'Mister Brown', + 'author-1-affiliation': 'CERN', + 'collaboration': 'This is a collaboration', + 'experiment': 'This is an experiment', + 'abstract': 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr.', + 'report-number-0': '100', + 'report-number-1': '101', + 'publisher-name': 'Oxford University', + 'publication-date': '2001-01-01', + 'publication-place': 'Oxford', + 'book-edition': 'No 2', + 'book-title': 'Astrowars', + 'book-volume': 'Andromeda', + 'isbn': '152865466211', + 'isbn_type': 'online', + 'references': 'references', + 'extra-comments': 'comments about the document' + } + + create_literature.go_to() + assert create_literature.submit_book(input_data).has_error() + _check_back_office(input_data) def test_literature_create_thesis_manually(login): input_data = { diff --git a/tests/integration/fixtures/book_expected.json b/tests/integration/fixtures/book_expected.json new file mode 100644 index 0000000000..cebae111a8 --- /dev/null +++ b/tests/integration/fixtures/book_expected.json @@ -0,0 +1,116 @@ +{ + "report_numbers": + [ + { + "source": "submitter", + "value": "89001" + } + ], + "acquisition_source": + { + "email": "test_orcid_user@inspirehep.net", + "source": "submitter", + "submission_number": "1", + "date": "1993-02-02T06:00:00", + "orcid": "0000-0001-9412-8627", + "method": "submitter" + }, + "accelerator_experiments": + [ + { + "legacy_name": "ATCA" + } + ], + "imprints": + [ + { + "date":"2014-12-17", + "place":"Harvard", + "publisher":"LAP Lambert Academic Publishing" + } + ], + "inspire_categories": + [ + { + "source": "user", + "term": "Astrophysics" + }, + { + "source": "user", + "term": "Computing" + }, + { + "source": "user", + "term": "Gravitation and Cosmology" + } + ], + "languages": ["en"], + "editions": ["The best edition"], + "titles": + [ + { + "source": "submitter", + "title": "Cosmological dynamical systems" + }, + { + "source": "arXiv", + "title": "Cosmological dynamical systems" + } + ], + "_private_notes": + [ + { + "source": "submitter", + "value": "321 pages, 41 figures. Draft of our book Cosmological Dynamical Systems: And their Applications, LAP LAMBERT Academic Publishing. 416 pp. ISBN:978-3-8473-0233-9. https://www.lap-publishing.com/catalog/details/store/gb/book/978-3-8473-0233-9/cosmological-dynamical-systems. arXiv admin note: text overlap with arXiv:astro-ph/0401547, arXiv:1101.0300, arXiv:hep-ph/0604152, arXiv:0911.1435, arXiv:1004.2474, arXiv:gr-qc/9910074, arXiv:gr-qc/9908067, arXiv:1001.1251, arXiv:1003.5637, arXiv:0707.2089 by other authors" + } + ], + "authors": + [ + { + "affiliations": + [ + { + "value": "Valparaiso U., Catolica" + } + ], + "full_name": "León Torres, Genly", + "inspire_roles": + [ + "author" + ] + }, + { + "affiliations": + [ + { + "value": "Havana, Central de Las Villas U" + } + ], + "full_name": "Fadragas, Carlos R.", + "inspire_roles": + [ + "author" + ] + } + ], + "isbns":[ + { + "medium":"online", + "value":"15242565" + } + ], + "book_series": [ + { + "title": "Astrophysics" + , "volume": "Universe" + } + ], + "document_type": ["book"], + "abstracts":[ + { + "source": "submitter", + "value":"In this book are studied, from the perspective of the dynamical systems, several Universe models. In chapter 1 we give a bird's eye view on cosmology and cosmological problems. Chapter 2 is devoted to a brief review on some results and useful tools from the qualitative theory of dynamical systems. They provide the theoretical basis for the qualitative study of concrete cosmological models. Chapters 1 and 2 are a review of well-known results. Chapters 3, 4, 5 and 6 are devoted to our main results. In these chapters are extended and settled in a substantially different, more strict mathematical language, several results obtained by one of us in arXiv:0812.1013 [gr-qc]; arXiv:1009.0689 [gr-qc]; arXiv:0904.1577[gr-qc]; and arXiv:0909.3571 [hep-th]. In chapter 6, we provide a different approach to the subject discussed in astro-ph/0503478. Additionally, we perform a Poincare compactification process allowing to construct a global phase space containing all the cosmological information in both finite and infinite regions for all the models." + } + ] + + } diff --git a/tests/integration/fixtures/book_input.json b/tests/integration/fixtures/book_input.json new file mode 100644 index 0000000000..ed408b5bc1 --- /dev/null +++ b/tests/integration/fixtures/book_input.json @@ -0,0 +1,60 @@ +{ "abstract":"In this book are studied, from the perspective of the dynamical systems, several Universe models. In chapter 1 we give a bird's eye view on cosmology and cosmological problems. Chapter 2 is devoted to a brief review on some results and useful tools from the qualitative theory of dynamical systems. They provide the theoretical basis for the qualitative study of concrete cosmological models. Chapters 1 and 2 are a review of well-known results. Chapters 3, 4, 5 and 6 are devoted to our main results. In these chapters are extended and settled in a substantially different, more strict mathematical language, several results obtained by one of us in arXiv:0812.1013 [gr-qc]; arXiv:1009.0689 [gr-qc]; arXiv:0904.1577[gr-qc]; and arXiv:0909.3571 [hep-th]. In chapter 6, we provide a different approach to the subject discussed in astro-ph/0503478. Additionally, we perform a Poincare compactification process allowing to construct a global phase space containing all the cosmological information in both finite and infinite regions for all the models.", + "extra_comments":"321 pages, 41 figures. Draft of our book Cosmological Dynamical Systems: And their Applications, LAP LAMBERT Academic Publishing. 416 pp. ISBN:978-3-8473-0233-9. https://www.lap-publishing.com/catalog/details/store/gb/book/978-3-8473-0233-9/cosmological-dynamical-systems. arXiv admin note: text overlap with arXiv:astro-ph/0401547, arXiv:1101.0300, arXiv:hep-ph/0604152, arXiv:0911.1435, arXiv:1004.2474, arXiv:gr-qc/9910074, arXiv:gr-qc/9908067, arXiv:1001.1251, arXiv:1003.5637, arXiv:0707.2089 by other authors", + "title_crossref":"", + "journal_title":"", + "conf_name":"", + "title_arXiv":"Cosmological dynamical systems", + "import_buttons":false, + "collaboration":"", + "subject_term":[ + "Astrophysics", + "Computing", + "Gravitation and Cosmology" + ], + "doi":"", + "references":"", + "year":"", + "categories":"", + "nonpublic_note":"", + "volume":"", + "book_edition":"The best edition", + "report_numbers":[ + { + "report_number":"89001" + } + ], + "language":"en", + "title":"Cosmological dynamical systems", + "type_of_doc":"book", + "isbn":[ + { + "type_of_isbn":"online", + "code":"15242565" + } + ], + "page_range_article_id":"", + "arxiv_id":"", + "title_translation":"", + "note":"", + "authors":[ + { + "affiliation":["Valparaiso U., Catolica"], + "full_name":"León Torres, Genly" + }, + { + "affiliation":["Havana, Central de Las Villas U"], + "full_name":"Fadragas, Carlos R." + } + ], + "publication_date":"2014-12-17", + "publication_place":"Harvard", + "publisher_name":"LAP Lambert Academic Publishing", + "series_title":"Astrophysics", + "series_volume":"Universe", + "experiment":"ATCA", + "license_url":"", + "preprint_created":"", + "conference_id":"", + "other_language":"", + "issue":"" +} diff --git a/tests/integration/test_formdata_to_model.py b/tests/integration/test_formdata_to_model.py index 1a655321bb..59a2730715 100644 --- a/tests/integration/test_formdata_to_model.py +++ b/tests/integration/test_formdata_to_model.py @@ -81,6 +81,16 @@ def record_thesis_expected(): yield load_record_dict('thesis_expected') +@pytest.fixture(scope='function') +def record_book_input(): + yield load_record_dict('book_input') + + +@pytest.fixture(scope='function') +def record_book_expected(): + yield load_record_dict('book_expected') + + @freeze_time('1993-02-02 06:00:00') def test_formdata_to_model_journal_article(record_journal_article_input, record_journal_article_expected, @@ -124,3 +134,18 @@ def test_formdata_to_model_thesis(record_thesis_input, output_data = formdata_to_model(workflow_obj, input_data) assert expected_data == output_data + + +@freeze_time('1993-02-02 06:00:00') +def test_formdata_to_model_book(record_book_input, + record_book_expected, + mock_user): + workflow_obj = WorkflowMockObj(1, mock_user.id) + + input_data = record_book_input + + expected_data = record_book_expected + + output_data = formdata_to_model(workflow_obj, input_data) + + assert expected_data == output_data