From e8704a8d7a2478f98be093df3ac67aca58e53926 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Sat, 4 Mar 2023 19:55:13 +0100 Subject: [PATCH 1/8] in tests no more use the reload argument in the exist? method --- test/models/notes/test_note.rb | 6 +++--- test/models/test_ontology.rb | 12 ++++++------ test/models/test_provisional_class.rb | 6 +++--- test/test_case.rb | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/test/models/notes/test_note.rb b/test/models/notes/test_note.rb index 6fb20171..ecc3cde6 100644 --- a/test/models/notes/test_note.rb +++ b/test/models/notes/test_note.rb @@ -67,11 +67,11 @@ def test_note_lifecycle relatedOntology: [@@ontology], }) - assert_equal false, n.exist?(reload=true) + assert_equal false, n.exist? n.save - assert_equal true, n.exist?(reload=true) + assert_equal true, n.exist? n.delete - assert_equal false, n.exist?(reload=true) + assert_equal false, n.exist? ensure n.delete if !n.nil? && n.persistent? end diff --git a/test/models/test_ontology.rb b/test/models/test_ontology.rb index b3f055a7..96ec14f0 100644 --- a/test/models/test_ontology.rb +++ b/test/models/test_ontology.rb @@ -308,11 +308,11 @@ def test_ontology_delete }) assert pc.valid? pc.save - assert_equal true, pc.exist?(reload=true) + assert_equal true, pc.exist? assert n.valid? n.save() - assert_equal true, n.exist?(reload=true) + assert_equal true, n.exist? review_params = { :creator => u, @@ -329,12 +329,12 @@ def test_ontology_delete r = LinkedData::Models::Review.new(review_params) r.save() - assert_equal true, r.exist?(reload=true) + assert_equal true, r.exist? o1.delete() - assert_equal false, n.exist?(reload=true) - assert_equal false, r.exist?(reload=true) - assert_equal false, o1.exist?(reload=true) + assert_equal false, n.exist? + assert_equal false, r.exist? + assert_equal false, o1.exist? o2.delete() end diff --git a/test/models/test_provisional_class.rb b/test/models/test_provisional_class.rb index 5c06539c..75e52cba 100644 --- a/test/models/test_provisional_class.rb +++ b/test/models/test_provisional_class.rb @@ -37,19 +37,19 @@ def test_provisional_class_lifecycle # Before save assert_equal LinkedData::Models::ProvisionalClass.where(label: label).all.count, 0 - assert_equal false, pc.exist?(reload=true) + assert_equal false, pc.exist? pc.save # After save assert_equal LinkedData::Models::ProvisionalClass.where(label: label).all.count, 1 - assert_equal true, pc.exist?(reload=true) + assert_equal true, pc.exist? pc.delete # After delete assert_equal LinkedData::Models::ProvisionalClass.where(label: label).all.count, 0 - assert_equal false, pc.exist?(reload=true) + assert_equal false, pc.exist? end def test_provisional_class_valid diff --git a/test/test_case.rb b/test/test_case.rb index 5ae5abd8..df7d5b76 100644 --- a/test/test_case.rb +++ b/test/test_case.rb @@ -218,11 +218,11 @@ def model_created_test(m) def model_lifecycle_test(m) assert_equal(true, m.is_a?(LinkedData::Models::Base), 'Expected is_a?(LinkedData::Models::Base).') assert_equal(true, m.valid?, "Expected valid model: #{m.errors}") - assert_equal(false, m.exist?(reload=true), 'Given model is already saved, expected one that is not.') + assert_equal(false, m.exist?, 'Given model is already saved, expected one that is not.') m.save - assert_equal(true, m.exist?(reload=true), 'Failed to save model.') + assert_equal(true, m.exist?, 'Failed to save model.') m.delete - assert_equal(false, m.exist?(reload=true), 'Failed to delete model.') + assert_equal(false, m.exist?, 'Failed to delete model.') end def self.count_pattern(pattern) From 45c16f66a69e29161d9cb20a1c6461c9152a8010 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Sat, 4 Mar 2023 19:56:18 +0100 Subject: [PATCH 2/8] rename the INRAETHES test file name --- ...v_structure.rdf => thesaurusINRAE_nouv_structure.skos} | 0 test/models/skos/test_collections.rb | 4 ++-- test/models/skos/test_schemes.rb | 2 +- test/models/skos/test_skos_xl.rb | 8 ++------ 4 files changed, 5 insertions(+), 9 deletions(-) rename test/data/ontology_files/{thesaurusINRAE_nouv_structure.rdf => thesaurusINRAE_nouv_structure.skos} (100%) diff --git a/test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf b/test/data/ontology_files/thesaurusINRAE_nouv_structure.skos similarity index 100% rename from test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf rename to test/data/ontology_files/thesaurusINRAE_nouv_structure.skos diff --git a/test/models/skos/test_collections.rb b/test/models/skos/test_collections.rb index 6d719063..9a1993a7 100644 --- a/test/models/skos/test_collections.rb +++ b/test/models/skos/test_collections.rb @@ -10,7 +10,7 @@ def self.before_suite def test_collections_all submission_parse('INRAETHES', 'Testing skos', - 'test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf', + 'test/data/ontology_files/thesaurusINRAE_nouv_structure.skos', 1, process_rdf: true, index_search: false, run_metrics: false, reasoning: false) @@ -31,7 +31,7 @@ def test_collections_all def test_collection_members submission_parse('INRAETHES', 'Testing skos', - 'test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf', + 'test/data/ontology_files/thesaurusINRAE_nouv_structure.skos', 1, process_rdf: true, index_search: false, run_metrics: false, reasoning: false) diff --git a/test/models/skos/test_schemes.rb b/test/models/skos/test_schemes.rb index 4960c33b..9f52e303 100644 --- a/test/models/skos/test_schemes.rb +++ b/test/models/skos/test_schemes.rb @@ -10,7 +10,7 @@ def self.before_suite def test_schemes_all submission_parse('INRAETHES', 'Testing skos', - 'test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf', + 'test/data/ontology_files/thesaurusINRAE_nouv_structure.skos', 1, process_rdf: true, index_search: false, run_metrics: false, reasoning: false) diff --git a/test/models/skos/test_skos_xl.rb b/test/models/skos/test_skos_xl.rb index f0643317..aa781a4c 100644 --- a/test/models/skos/test_skos_xl.rb +++ b/test/models/skos/test_skos_xl.rb @@ -9,7 +9,7 @@ def self.before_suite def test_skos_xl_label_all submission_parse('INRAETHES', 'Testing skos', - 'test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf', + 'test/data/ontology_files/thesaurusINRAE_nouv_structure.skos', 1, process_rdf: true, index_search: false, run_metrics: false, reasoning: false) @@ -27,7 +27,7 @@ def test_skos_xl_label_all def test_class_skos_xl_label submission_parse('INRAETHES', 'Testing skos', - 'test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf', + 'test/data/ontology_files/thesaurusINRAE_nouv_structure.skos', 1, process_rdf: true, index_search: false, run_metrics: false, reasoning: false) @@ -35,10 +35,6 @@ def test_class_skos_xl_label ont = LinkedData::Models::Ontology.find(ont).first sub = ont.latest_submission - sub.bring_remaining - sub.hasOntologyLanguage = LinkedData::Models::OntologyFormat.find('SKOS').first - sub.save - class_test = LinkedData::Models::Class.find('http://opendata.inrae.fr/thesaurusINRAE/c_16193') .in(sub).include(:prefLabel, altLabelXl: [:literalForm], From c2f28891aa758aac50c40a202c1596bf409c04cd Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Sat, 4 Mar 2023 20:03:29 +0100 Subject: [PATCH 3/8] fix mappings test test_external_mapping_with_no_source_ids validity --- .../concerns/mappings/mapping_creator.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ontologies_linked_data/concerns/mappings/mapping_creator.rb b/lib/ontologies_linked_data/concerns/mappings/mapping_creator.rb index bbd4281d..600ed13a 100644 --- a/lib/ontologies_linked_data/concerns/mappings/mapping_creator.rb +++ b/lib/ontologies_linked_data/concerns/mappings/mapping_creator.rb @@ -81,8 +81,8 @@ def create_mapping_process(mapping_process_hash, source_uri, object_uri, user) process.relation = relations_array process.creator = user - process.subject_source_id = RDF::URI.new(source_uri || mapping_process_hash[:subject_source_id]) - process.object_source_id = RDF::URI.new(object_uri || mapping_process_hash[:object_source_id]) + process.subject_source_id = create_uri(source_uri || mapping_process_hash[:subject_source_id]) + process.object_source_id = create_uri(object_uri || mapping_process_hash[:object_source_id]) process.date = mapping_process_hash[:date] ? DateTime.parse(mapping_process_hash[:date]) : DateTime.now process_fields = %i[source source_name comment name source_contact_info] process_fields.each do |att| @@ -92,6 +92,9 @@ def create_mapping_process(mapping_process_hash, source_uri, object_uri, user) end private + def create_uri(value) + RDF::URI.new(value) unless value.nil? + end def save_rest_mapping(classes, process) LinkedData::Mappings.create_rest_mapping(classes, process) From c5919e4838ce39ccc5c0174a75def18395e8b047 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Sat, 4 Mar 2023 20:04:00 +0100 Subject: [PATCH 4/8] handle users with no username to_string --- lib/ontologies_linked_data/models/users/user.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ontologies_linked_data/models/users/user.rb b/lib/ontologies_linked_data/models/users/user.rb index 038ba5c6..03798362 100644 --- a/lib/ontologies_linked_data/models/users/user.rb +++ b/lib/ontologies_linked_data/models/users/user.rb @@ -90,7 +90,11 @@ def custom_ontology_id_set end def to_s - self.username.to_s + if bring?(:username) + self.id.to_s + else + self.username.to_s + end end private From 428edfbd20b29cc1e902c6995a69836f087b8621 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Sat, 4 Mar 2023 20:06:26 +0100 Subject: [PATCH 5/8] add requested language tests --- test/models/test_class_main_lang.rb | 28 +++++----- test/models/test_class_request_lang.rb | 75 ++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 15 deletions(-) create mode 100644 test/models/test_class_request_lang.rb diff --git a/test/models/test_class_main_lang.rb b/test/models/test_class_main_lang.rb index 352dbe7f..7676d08f 100644 --- a/test/models/test_class_main_lang.rb +++ b/test/models/test_class_main_lang.rb @@ -10,25 +10,25 @@ def self.after_suite end def test_map_attribute_found - cls = parse_and_get_class lang: ['fr'] + cls = parse_and_get_class lang: [:FR] cls.bring :unmapped LinkedData::Models::Class.map_attributes(cls) - assert_equal 'entité matérielle detaillée', cls.label.first - assert_equal 'skos prefLabel fr', cls.prefLabel + assert_equal ['entité matérielle detaillée'], cls.label + assert_includes ['skos prefLabel fr', 'skos prefLabel rien'], cls.prefLabel assert_equal ['entité fra', 'entite rien'], cls.synonym end def test_map_attribute_not_found - cls = parse_and_get_class lang: ['es'] + cls = parse_and_get_class lang: [:ES] cls.bring :unmapped LinkedData::Models::Class.map_attributes(cls) assert_equal ['material detailed entity', 'entité matérielle detaillée'], cls.label assert_equal 'skos prefLabel rien', cls.prefLabel - assert_equal ['entita esp' , 'entite rien' ], cls.synonym + assert_equal ['entita esp', 'entite rien'], cls.synonym end def test_map_attribute_secondary_lang - cls = parse_and_get_class lang: %w[es fr] + cls = parse_and_get_class lang: %i[ES FR] cls.bring :unmapped LinkedData::Models::Class.map_attributes(cls) assert_equal ['entité matérielle detaillée'], cls.label @@ -38,14 +38,14 @@ def test_map_attribute_secondary_lang def test_label_main_lang_fr_found - cls = parse_and_get_class lang: ['fr'] - assert_equal 'entité matérielle detaillée', cls.label.first + cls = parse_and_get_class lang: [:FR] + assert_equal ['entité matérielle detaillée'], cls.label assert_equal 'skos prefLabel fr', cls.prefLabel assert_equal ['entité fra', 'entite rien'], cls.synonym end def test_label_main_lang_not_found - cls = parse_and_get_class lang: ['es'] + cls = parse_and_get_class lang: [:ES] assert_equal ['material detailed entity', 'entité matérielle detaillée'], cls.label assert_equal 'skos prefLabel rien', cls.prefLabel @@ -54,7 +54,7 @@ def test_label_main_lang_not_found def test_label_secondary_lang # 'es' will not be found so will take 'fr' if fond or anything else - cls = parse_and_get_class lang: %w[es fr] + cls = parse_and_get_class lang: %i[ES FR] assert_equal ['entité matérielle detaillée'], cls.label assert_equal 'skos prefLabel rien', cls.prefLabel @@ -62,7 +62,7 @@ def test_label_secondary_lang end def test_label_main_lang_en_found - cls = parse_and_get_class lang: ['en'] + cls = parse_and_get_class lang: [:EN] assert_equal 'material detailed entity', cls.label.first assert_equal 'skos prefLabel en', cls.prefLabel assert_equal ['entity eng', 'entite rien'], cls.synonym @@ -72,7 +72,7 @@ def test_label_main_lang_en_found private def parse_and_get_class(lang:, klass: 'http://lirmm.fr/2015/resource/AGROOE_c_03') - lang_set lang + lang_set portal_languages: lang submission_parse('AGROOE', 'AGROOE Test extract metadata ontology', './test/data/ontology_files/agrooeMappings-05-05-2016.owl', 1, process_rdf: true, index_search: false, @@ -85,9 +85,7 @@ def parse_and_get_class(lang:, klass: 'http://lirmm.fr/2015/resource/AGROOE_c_03 cls end - def lang_set(lang) - Goo.main_languages = lang - end + def get_ontology_last_submission(ont) LinkedData::Models::Ontology.find(ont).first.latest_submission() diff --git a/test/models/test_class_request_lang.rb b/test/models/test_class_request_lang.rb new file mode 100644 index 00000000..2513afe6 --- /dev/null +++ b/test/models/test_class_request_lang.rb @@ -0,0 +1,75 @@ +require_relative './test_ontology_common' + +class TestClassMainLang < LinkedData::TestOntologyCommon + + def self.after_suite + Goo.requested_language = nil + end + + def test_requested_language_found + + parse + + cls = get_class_by_lang('http://opendata.inrae.fr/thesaurusINRAE/c_22817', + requested_lang: :FR, portal_languages: %i[EN FR ES]) + assert_equal 'industrialisation', cls.prefLabel + assert_equal ['développement industriel'], cls.synonym + + properties = cls.properties + assert_equal ['développement industriel'], properties.select { |x| x.to_s['altLabel'] }.values.first.map(&:to_s) + assert_equal ['industrialisation'], properties.select { |x| x.to_s['prefLabel'] }.values.first.map(&:to_s) + + cls = get_class_by_lang('http://opendata.inrae.fr/thesaurusINRAE/c_22817', + requested_lang: :EN, portal_languages: %i[FR EN ES]) + assert_equal 'industrialization', cls.prefLabel + assert_equal ['industrial development'], cls.synonym + + properties = cls.properties + assert_equal ['industrial development'], properties.select { |x| x.to_s['altLabel'] }.values.first.map(&:to_s) + assert_equal ['industrialization'], properties.select { |x| x.to_s['prefLabel'] }.values.first.map(&:to_s) + + end + + def test_requested_language_not_found + parse + + cls = get_class_by_lang('http://opendata.inrae.fr/thesaurusINRAE/c_22817', + requested_lang: :ES, portal_languages: %i[EN FR ES]) + assert_nil cls.prefLabel + assert_empty cls.synonym + + properties = cls.properties + assert_empty properties.select { |x| x.to_s['altLabel'] }.values + assert_empty properties.select { |x| x.to_s['prefLabel'] }.values + + end + + private + + def parse + submission_parse('INRAETHES', 'Testing skos', + 'test/data/ontology_files/thesaurusINRAE_nouv_structure.skos', + 1, + process_rdf: true, index_search: false, + run_metrics: false, reasoning: false) + end + + def lang_set(requested_lang: nil, portal_languages: nil) + Goo.main_languages = portal_languages if portal_languages + Goo.requested_language = requested_lang + end + + def get_class(cls, ont) + sub = LinkedData::Models::Ontology.find(ont).first.latest_submission + LinkedData::Models::Class.find(cls).in(sub).first + end + + def get_class_by_lang(cls, requested_lang:, portal_languages: []) + lang_set requested_lang: requested_lang, portal_languages: portal_languages + cls = get_class(cls, 'INRAETHES') + refute_nil cls + cls.bring_remaining + cls.bring :unmapped + cls + end +end \ No newline at end of file From 043afa9125c0ca872aa755da37db08567131b532 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Sat, 4 Mar 2023 20:07:02 +0100 Subject: [PATCH 6/8] use for Goo the language filter feature branch --- Gemfile | 2 +- Gemfile.lock | 53 ++++++++++++++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Gemfile b/Gemfile index ce9364a8..a24ac208 100644 --- a/Gemfile +++ b/Gemfile @@ -35,5 +35,5 @@ group :development do end # NCBO gems (can be from a local dev path or from rubygems/git) -gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development' +gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'feature/support-multilingual-read-one-language-from-request-parameter' gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'master' diff --git a/Gemfile.lock b/Gemfile.lock index 71b88638..b584e2f5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GIT remote: https://github.com/ontoportal-lirmm/goo.git - revision: 3d5bbe1db4a6aca2ff621ccfcdb85a32dbe9704e - branch: development + revision: d30c5748f27c05d88d5db423f7c4b2355412483b + branch: feature/support-multilingual-read-one-language-from-request-parameter specs: goo (0.0.2) addressable (~> 2.8) @@ -39,11 +39,11 @@ GEM bcrypt (3.1.18) builder (3.2.4) coderay (1.1.3) - concurrent-ruby (1.1.10) + concurrent-ruby (1.2.2) connection_pool (2.3.0) cube-ruby (0.0.3) daemons (1.4.1) - date (3.3.2) + date (3.3.3) docile (1.4.0) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) @@ -52,7 +52,7 @@ GEM launchy (~> 2.1) mail (~> 2.7) eventmachine (1.2.7) - faraday (1.10.2) + faraday (1.10.3) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) faraday-excon (~> 1.1) @@ -85,13 +85,13 @@ GEM concurrent-ruby (~> 1.0) json (2.6.3) json_pure (2.6.3) - launchy (2.5.0) - addressable (~> 2.7) + launchy (2.5.2) + addressable (~> 2.8) libxml-ruby (2.9.0) logger (1.5.3) macaddr (1.7.2) systemu (~> 2.6.5) - mail (2.8.0) + mail (2.8.1) mini_mime (>= 0.1.1) net-imap net-pop @@ -99,7 +99,7 @@ GEM method_source (1.0.0) mime-types (3.4.1) mime-types-data (~> 3.2015) - mime-types-data (3.2022.0105) + mime-types-data (3.2023.0218.1) mini_mime (1.1.2) minitest (4.7.5) minitest-reporters (0.14.24) @@ -108,9 +108,9 @@ GEM minitest (>= 2.12, < 5.0) powerbar multi_json (1.15.0) - multipart-post (2.2.3) + multipart-post (2.3.0) net-http-persistent (2.9.4) - net-imap (0.3.2) + net-imap (0.3.4) date net-protocol net-pop (0.1.2) @@ -124,13 +124,13 @@ GEM omni_logger (0.1.4) logger parallel (1.22.1) - parser (3.1.3.0) + parser (3.2.1.0) ast (~> 2.4.1) pony (1.13.1) mail (>= 2.0) powerbar (2.0.1) hashie (>= 1.1.0) - pry (0.14.1) + pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) public_suffix (5.0.1) @@ -141,11 +141,11 @@ GEM rake (10.5.0) rdf (1.0.8) addressable (>= 2.2) - redis (5.0.5) + redis (5.0.6) redis-client (>= 0.9.0) - redis-client (0.11.2) + redis-client (0.13.0) connection_pool - regexp_parser (2.6.1) + regexp_parser (2.7.0) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) @@ -154,22 +154,22 @@ GEM rexml (3.2.5) rsolr (1.1.2) builder (>= 2.1.2) - rubocop (1.40.0) + rubocop (1.47.0) json (~> 2.3) parallel (~> 1.10) - parser (>= 3.1.2.1) + parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.23.0, < 2.0) + rubocop-ast (>= 1.26.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.24.0) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.27.0) + parser (>= 3.2.1.0) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) rubyzip (1.3.0) - simplecov (0.21.2) + simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) @@ -186,17 +186,18 @@ GEM eventmachine (~> 1.0, >= 1.0.4) rack (>= 1, < 3) thread_safe (0.3.6) - timeout (0.3.1) + timeout (0.3.2) tzinfo (0.3.61) unf (0.1.4) unf_ext unf_ext (0.0.8.2) - unicode-display_width (2.3.0) + unicode-display_width (2.4.2) uuid (2.3.9) macaddr (~> 1.0) PLATFORMS x86_64-darwin-21 + x86_64-linux DEPENDENCIES activesupport (~> 4) From 7514480b1da5d6008f9162fd10f991f96522f789 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Sat, 4 Mar 2023 23:14:43 +0100 Subject: [PATCH 7/8] add request_store gem --- Gemfile | 1 + Gemfile.lock | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index a24ac208..3b10ee49 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,7 @@ gem 'rest-client' gem 'rsolr', '~> 1.0' gem 'rubyzip', '~> 1.0' gem 'thin' +gem 'request_store' # Testing group :test do diff --git a/Gemfile.lock b/Gemfile.lock index b584e2f5..e8815a3f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/ontoportal-lirmm/goo.git - revision: d30c5748f27c05d88d5db423f7c4b2355412483b + revision: 92bed925de041eb5a40adbe8788a74c6c7cb1020 branch: feature/support-multilingual-read-one-language-from-request-parameter specs: goo (0.0.2) @@ -146,6 +146,8 @@ GEM redis-client (0.13.0) connection_pool regexp_parser (2.7.0) + request_store (1.5.1) + rack (>= 1.4) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) @@ -219,6 +221,7 @@ DEPENDENCIES rack (~> 1.0) rack-test (~> 0.6) rake (~> 10.0) + request_store rest-client rsolr (~> 1.0) rubocop From f8c8f569cc282ec31ad181cdbe355f7899983b3f Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Sat, 4 Mar 2023 23:15:19 +0100 Subject: [PATCH 8/8] update requested language tests to use RequestStore gem --- Gemfile | 2 +- Gemfile.lock | 6 +++--- test/models/test_class_main_lang.rb | 8 ++++++- test/models/test_class_request_lang.rb | 30 +++++++++++++++++++------- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index 3b10ee49..f2fe2945 100644 --- a/Gemfile +++ b/Gemfile @@ -36,5 +36,5 @@ group :development do end # NCBO gems (can be from a local dev path or from rubygems/git) -gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'feature/support-multilingual-read-one-language-from-request-parameter' +gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development' gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'master' diff --git a/Gemfile.lock b/Gemfile.lock index e8815a3f..96718e3c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GIT remote: https://github.com/ontoportal-lirmm/goo.git - revision: 92bed925de041eb5a40adbe8788a74c6c7cb1020 - branch: feature/support-multilingual-read-one-language-from-request-parameter + revision: b769c165906163e30a026dba511ae1069c4eed3d + branch: development specs: goo (0.0.2) addressable (~> 2.8) @@ -156,7 +156,7 @@ GEM rexml (3.2.5) rsolr (1.1.2) builder (>= 2.1.2) - rubocop (1.47.0) + rubocop (1.48.0) json (~> 2.3) parallel (~> 1.10) parser (>= 3.2.0.0) diff --git a/test/models/test_class_main_lang.rb b/test/models/test_class_main_lang.rb index 7676d08f..b5f9be40 100644 --- a/test/models/test_class_main_lang.rb +++ b/test/models/test_class_main_lang.rb @@ -3,10 +3,12 @@ class TestClassMainLang < LinkedData::TestOntologyCommon def self.before_suite @@old_main_languages = Goo.main_languages + RequestStore.store[:requested_lang] = nil end def self.after_suite Goo.main_languages = @@old_main_languages + RequestStore.store[:requested_lang] = nil end def test_map_attribute_found @@ -72,7 +74,7 @@ def test_label_main_lang_en_found private def parse_and_get_class(lang:, klass: 'http://lirmm.fr/2015/resource/AGROOE_c_03') - lang_set portal_languages: lang + portal_lang_set portal_languages: lang submission_parse('AGROOE', 'AGROOE Test extract metadata ontology', './test/data/ontology_files/agrooeMappings-05-05-2016.owl', 1, process_rdf: true, index_search: false, @@ -86,6 +88,10 @@ def parse_and_get_class(lang:, klass: 'http://lirmm.fr/2015/resource/AGROOE_c_03 end + def portal_lang_set(portal_languages: nil) + Goo.main_languages = portal_languages if portal_languages + RequestStore.store[:requested_lang] = nil + end def get_ontology_last_submission(ont) LinkedData::Models::Ontology.find(ont).first.latest_submission() diff --git a/test/models/test_class_request_lang.rb b/test/models/test_class_request_lang.rb index 2513afe6..f7856d7f 100644 --- a/test/models/test_class_request_lang.rb +++ b/test/models/test_class_request_lang.rb @@ -1,17 +1,25 @@ require_relative './test_ontology_common' +require 'request_store' -class TestClassMainLang < LinkedData::TestOntologyCommon +class TestClassRequestedLang < LinkedData::TestOntologyCommon + + + def self.before_suite + @@old_main_languages = Goo.main_languages + RequestStore.store[:requested_lang] = nil + end def self.after_suite - Goo.requested_language = nil + Goo.main_languages = @@old_main_languages + RequestStore.store[:requested_lang] = nil end - def test_requested_language_found + def test_requested_language_found parse cls = get_class_by_lang('http://opendata.inrae.fr/thesaurusINRAE/c_22817', - requested_lang: :FR, portal_languages: %i[EN FR ES]) + requested_lang: :FR) assert_equal 'industrialisation', cls.prefLabel assert_equal ['développement industriel'], cls.synonym @@ -20,7 +28,7 @@ def test_requested_language_found assert_equal ['industrialisation'], properties.select { |x| x.to_s['prefLabel'] }.values.first.map(&:to_s) cls = get_class_by_lang('http://opendata.inrae.fr/thesaurusINRAE/c_22817', - requested_lang: :EN, portal_languages: %i[FR EN ES]) + requested_lang: :EN) assert_equal 'industrialization', cls.prefLabel assert_equal ['industrial development'], cls.synonym @@ -28,13 +36,14 @@ def test_requested_language_found assert_equal ['industrial development'], properties.select { |x| x.to_s['altLabel'] }.values.first.map(&:to_s) assert_equal ['industrialization'], properties.select { |x| x.to_s['prefLabel'] }.values.first.map(&:to_s) + reset_lang end def test_requested_language_not_found parse cls = get_class_by_lang('http://opendata.inrae.fr/thesaurusINRAE/c_22817', - requested_lang: :ES, portal_languages: %i[EN FR ES]) + requested_lang: :ES) assert_nil cls.prefLabel assert_empty cls.synonym @@ -42,6 +51,7 @@ def test_requested_language_not_found assert_empty properties.select { |x| x.to_s['altLabel'] }.values assert_empty properties.select { |x| x.to_s['prefLabel'] }.values + reset_lang end private @@ -56,7 +66,11 @@ def parse def lang_set(requested_lang: nil, portal_languages: nil) Goo.main_languages = portal_languages if portal_languages - Goo.requested_language = requested_lang + RequestStore.store[:requested_lang] = requested_lang + end + + def reset_lang + lang_set requested_lang: nil, portal_languages: @@old_main_languages end def get_class(cls, ont) @@ -64,7 +78,7 @@ def get_class(cls, ont) LinkedData::Models::Class.find(cls).in(sub).first end - def get_class_by_lang(cls, requested_lang:, portal_languages: []) + def get_class_by_lang(cls, requested_lang:, portal_languages: nil) lang_set requested_lang: requested_lang, portal_languages: portal_languages cls = get_class(cls, 'INRAETHES') refute_nil cls