Skip to content

Commit

Permalink
Merge pull request #901 from ElixirTeSS/check-source-params
Browse files Browse the repository at this point in the history
Source testing fix
  • Loading branch information
fbacall authored Oct 30, 2023
2 parents 1bbfc99 + 03759e9 commit 9513afb
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ gem 'sitemap-parser'
gem 'slim'
gem 'sunspot_rails', github: 'sunspot/sunspot', branch: 'master' # Contains Ruby 3 fixes that are not released
gem 'terser'
gem 'tess_rdf_extractors', git: 'https://github.com/ElixirTeSS/TeSS_RDF_Extractors', tag: '1.0.0'
gem 'tess_rdf_extractors', git: 'https://github.com/ElixirTeSS/TeSS_RDF_Extractors', tag: '1.0.1'
gem 'turbolinks'
gem 'tzinfo'
gem 'tzinfo-data'
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
GIT
remote: https://github.com/ElixirTeSS/TeSS_RDF_Extractors
revision: f2f5173736d97166f7dc255ea3be4d749882a960
tag: 1.0.0
revision: e941e5f706e849eef36d33fb702282576c00f21d
tag: 1.0.1
specs:
tess_rdf_extractors (1.0.0)
tess_rdf_extractors (1.0.1)
linkeddata (~> 3.2.0)

GIT
Expand Down
7 changes: 7 additions & 0 deletions app/models/concerns/has_test_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def test_results=(results)
end
end

class_methods do
def get_test_resource(type, params, **extras)
klass = type.singularize.capitalize.constantize
klass.new(params.with_indifferent_access.slice(*klass.attribute_names).merge(extras))
end
end

private

def test_job_id_key
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_providers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<!-- Nodes: check feature enabled -->
<% if TeSS::Config.feature['nodes'] %>
<%= f.input :node_id, label: 'ELIXIR node', collection: Node.all, label_method: :title %>
<%= f.input :node_id, label: 'ELIXIR node', collection: Node.order(:name).all, label_method: :name %>
<% end %>

<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

<!-- Field: Timezone -->
<%= f.input :timezone, as: :time_zone, field_lock: true, priority: priority_time_zones,
input_html: { title: t('events.hints.timezone') } %>
input_html: { class: 'js-select2', title: t('events.hints.timezone') } %>

<!-- Field: Duration -->
<%= f.input :duration, as: :string, input_html: { title: t('events.hints.duration') } %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/sources/_test_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
Showing <%= pluralize(sample.count, 'sample') %>
<% end %>
<% sample.each do |resource_params| %>
<% resource = type.singularize.capitalize.constantize.new(resource_params.merge(user: User.get_default_user,
content_provider: @content_provider)) %>
<% resource = Source.get_test_resource(type, resource_params, user: User.get_default_user,
content_provider: @content_provider) %>
<% existing = klass.check_exists(resource) %>
<div class="list-card bulk-import-row<%= ' new' unless existing -%>">
<h4>
Expand Down
2 changes: 1 addition & 1 deletion lib/ingestors/event_ingestion.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Ingestors
module EventIngestion
def add_event(event)
event = OpenStruct.new(event) if event.is_a?(Hash)
event = OpenStruct.new(event.with_indifferent_access.slice(*Event.attribute_names)) if event.is_a?(Hash)
@events << event unless event.nil?
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ingestors/material_ingestion.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Ingestors
module MaterialIngestion
def add_material(material)
material = OpenStruct.new(material) if material.is_a?(Hash)
material = OpenStruct.new(material.with_indifferent_access.slice(*Material.attribute_names)) if material.is_a?(Hash)
@materials << material unless material.nil?
end
end
Expand Down
23 changes: 23 additions & 0 deletions test/controllers/sources_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,27 @@ class SourcesControllerTest < ActionController::TestCase

refute source.reload.approval_requested?
end

test 'ignores unrecognized fields when displaying test results' do
source = sources(:unapproved_source)
user = source.user
sign_in user
source.test_results = {
events: [{ title: 'test 123', url: 'https://tess.elixir-europe.org', some_random_field: 'hello' }],
materials: [],
messages: [], run_time: 120, finished_at: Time.now }
assert source.test_results

get :test_results, params: { id: source }, xhr: true

assert_response :success
assert_select 'h4', text: 'Last Test Results'
assert_select '#events' do
assert_select 'h4', text: 'test 123'
assert_select 'a[href=?]', 'https://tess.elixir-europe.org'
end
ensure
path = source.send(:test_results_path)
FileUtils.rm(path) if File.exist?(path)
end
end
130 changes: 130 additions & 0 deletions test/fixtures/files/ingestion/sib_course.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions test/unit/ingestors/bioschemas_ingestor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ class BioschemasIngestorTest < ActiveSupport::TestCase
refute File.exist?(file)
end

test 'filters unrecognized fields when scraping' do
mock_bioschemas('https://website.org/courseinstances.json', 'sib_course.json')
@ingestor.stub(:convert_params, -> (p) { p[:blabla_123] = 'woowoo'; p }) do
@ingestor.read('https://website.org/courseinstances.json')
assert_difference('Event.count', 2) do
@ingestor.write(@user, @content_provider)
end
end

sample = @ingestor.events.detect { |e| e.url == 'https://webapp2.vital-it.ch/courseadmin/website/course/20221010_XXX12' }
assert sample.persisted?
assert_includes sample.description, 'This course is now full with a long waiting list.'
assert_equal @content_provider, sample.content_provider
end

private

def mock_bioschemas(url, filename)
Expand Down

0 comments on commit 9513afb

Please sign in to comment.