-
Notifications
You must be signed in to change notification settings - Fork 1
Batch tutorial: create placements directly #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,21 @@ bacillus_subtilis: | |
| rank: species | ||
| status: 20 # ICNP | ||
|
|
||
| nanobdellaceae: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel some tension between using fixtures with names that describe the fixture (e.g.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think mixing them up is ok, depending on the aim of the test(s) using the fixture |
||
| name: Nanobdellaceae | ||
| rank: family | ||
| status: 15 # SeqCode | ||
|
|
||
| nanoclepta_minutus: | ||
| name: Nanoclepta minutus | ||
| rank: species | ||
| status: 15 # SeqCode | ||
|
|
||
| luteria_ianthellae: | ||
| name: Luteria ianthellae | ||
| rank: species | ||
| status: 15 # SeqCode | ||
|
|
||
| type_genome_with_locations: | ||
| name: Testimonas mappensis | ||
| rank: species | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,153 @@ | ||
| require 'test_helper' | ||
|
|
||
| class TutorialTest < ActiveSupport::TestCase | ||
| # test "the truth" do | ||
| # assert true | ||
| # end | ||
| test 'batch parses a name' do | ||
| tutorial = upload_batch_spreadsheet('SCR_UploadBatch-Nanoclepta.xlsx') | ||
| name = tutorial.ephemeral_names.first | ||
| placement = name.placements.first | ||
|
|
||
| assert_equal 1, tutorial.step | ||
| assert_empty tutorial.value(:genomes) | ||
| assert_equal 1, tutorial.value(:names).size | ||
| assert_equal 'Nanoclepta', tutorial.value(:names).first['name'] | ||
| assert_equal 'Nanobdellaceae', tutorial.value(:names).first['parent'] | ||
| assert_nil name.parent | ||
| assert_nil name[:incertae_sedis] | ||
| assert_same name, placement.name | ||
| assert_equal 'Nanobdellaceae', placement.parent.name | ||
| assert_nil placement.incertae_sedis | ||
| assert_empty placement.incertae_sedis_text.to_plain_text | ||
| end | ||
|
|
||
| test 'batch parses an incertae sedis name' do | ||
| tutorial = upload_batch_spreadsheet( | ||
| 'SCR_UploadBatch-Luteria-Incertae_sedis.xlsx' | ||
| ) | ||
| name = tutorial.ephemeral_names.first | ||
| placement = name.placements.first | ||
|
|
||
| assert_equal 1, tutorial.step | ||
| assert_empty tutorial.value(:genomes) | ||
| assert_equal 1, tutorial.value(:names).size | ||
| assert_equal 'Luteria', tutorial.value(:names).first['name'] | ||
| assert_equal( | ||
| 'incertae sedis (Bacteria)', tutorial.value(:names).first['parent'] | ||
| ) | ||
| assert_nil name.parent | ||
| assert_nil name[:incertae_sedis] | ||
| assert_nil placement.parent | ||
| assert_equal 'incertae sedis (Bacteria)', placement.incertae_sedis | ||
| assert_equal( | ||
| tutorial.value(:names).first['description'], | ||
| placement.incertae_sedis_text.to_plain_text | ||
| ) | ||
| end | ||
|
|
||
| test 'batch creates a parent placement' do | ||
| tutorial = upload_batch_spreadsheet('SCR_UploadBatch-Nanoclepta.xlsx') | ||
| parent = names(:nanobdellaceae) | ||
|
|
||
| assert tutorial.batch_step_01({}, users(:contributor)) | ||
|
|
||
| name = Name.find_by!(name: 'Nanoclepta') | ||
| placement = name.placement | ||
|
|
||
| assert_not_nil placement | ||
| assert_predicate placement, :preferred? | ||
| assert_equal parent, placement.parent | ||
| assert_equal parent, name.parent | ||
| assert_nil placement.incertae_sedis | ||
| end | ||
|
|
||
| test 'batch updates a claimable name with a preferred placement' do | ||
| parent = names(:nanobdellaceae) | ||
| name = Name.create!( | ||
| name: 'Nanoclepta', rank: 'genus', status: 5, | ||
| created_by: users(:contributor), parent: parent | ||
| ) | ||
| placement = name.placement | ||
| tutorial = upload_batch_spreadsheet('SCR_UploadBatch-Nanoclepta.xlsx') | ||
|
|
||
| assert_no_difference('Placement.count') do | ||
| assert tutorial.batch_step_01({}, users(:contributor)) | ||
| end | ||
|
|
||
| assert_equal placement, name.reload.placement | ||
| assert_equal parent, name.parent | ||
| end | ||
|
|
||
| test 'batch replaces a claimable name preferred placement' do | ||
| old_parent = Name.create!( | ||
| name: 'Nanoarchaeaceae', rank: 'family', status: 15 | ||
| ) | ||
| name = Name.create!( | ||
| name: 'Nanoclepta', rank: 'genus', status: 5, | ||
| created_by: users(:contributor), parent: old_parent | ||
| ) | ||
| old_placement = name.placement | ||
| tutorial = upload_batch_spreadsheet('SCR_UploadBatch-Nanoclepta.xlsx') | ||
|
|
||
| assert_difference('Placement.count', 1) do | ||
| assert tutorial.batch_step_01({}, users(:contributor)) | ||
| end | ||
|
|
||
| name = Name.find(name.id) | ||
| assert_equal names(:nanobdellaceae), name.placement.parent | ||
| assert_not old_placement.reload.preferred? | ||
| assert_includes name.alt_placements, old_placement | ||
| end | ||
|
|
||
| test 'batch creates an incertae sedis placement' do | ||
| tutorial = upload_batch_spreadsheet( | ||
| 'SCR_UploadBatch-Luteria-Incertae_sedis.xlsx' | ||
| ) | ||
| explanation = tutorial.value(:names).first['description'] | ||
|
|
||
| assert tutorial.batch_step_01({}, users(:contributor)) | ||
|
|
||
| name = Name.find_by!(name: 'Luteria') | ||
| placement = name.placement | ||
|
|
||
| assert_not_nil placement | ||
| assert_predicate placement, :preferred? | ||
| assert_nil placement.parent | ||
| assert_nil name.parent | ||
| assert_equal 'incertae sedis (Bacteria)', placement.incertae_sedis | ||
| assert_equal explanation, placement.incertae_sedis_text.to_plain_text | ||
| assert_nil name[:incertae_sedis] | ||
| end | ||
|
|
||
| test 'batch replaces a claimable name placement with incertae sedis' do | ||
| old_parent = names(:escherichia) | ||
| name = Name.create!( | ||
| name: 'Luteria', rank: 'genus', status: 5, | ||
| created_by: users(:contributor), parent: old_parent | ||
| ) | ||
| old_placement = name.placement | ||
| tutorial = upload_batch_spreadsheet( | ||
| 'SCR_UploadBatch-Luteria-Incertae_sedis.xlsx' | ||
| ) | ||
|
|
||
| assert_difference('Placement.count', 1) do | ||
| assert tutorial.batch_step_01({}, users(:contributor)) | ||
| end | ||
|
|
||
| name = Name.find(name.id) | ||
| assert_equal 'incertae sedis (Bacteria)', name.placement.incertae_sedis | ||
| assert_not_predicate old_placement.reload, :preferred? | ||
| assert_includes name.alt_placements, old_placement | ||
| assert_nil name[:incertae_sedis] | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def upload_batch_spreadsheet(filename) | ||
| tutorial = Tutorial.create!( | ||
| pipeline: 'batch', user: users(:contributor), step: 0, ongoing: true | ||
| ) | ||
| File.open(Rails.root.join('test/fixtures/files', filename)) do |file| | ||
| assert tutorial.batch_step_00({ file: file }, users(:contributor)) | ||
| end | ||
| tutorial | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will go away in #337