Skip to content

Commit

Permalink
update requested language tests to use RequestStore gem
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Mar 6, 2023
1 parent 7514480 commit fd0cb79
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/ontoportal-lirmm/goo.git
revision: 92bed925de041eb5a40adbe8788a74c6c7cb1020
revision: ac8709a86a4c4d2178d34de0e18367bcd131ebed
branch: feature/support-multilingual-read-one-language-from-request-parameter
specs:
goo (0.0.2)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion test/models/test_class_main_lang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand Down
30 changes: 22 additions & 8 deletions test/models/test_class_request_lang.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -20,28 +28,30 @@ 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

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)

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

properties = cls.properties
assert_empty properties.select { |x| x.to_s['altLabel'] }.values
assert_empty properties.select { |x| x.to_s['prefLabel'] }.values

reset_lang
end

private
Expand All @@ -56,15 +66,19 @@ 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)
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: [])
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
Expand Down

0 comments on commit fd0cb79

Please sign in to comment.