From 7c88bd482ae9c38080dcfe2098c3b0838dc14b6e Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Thu, 17 Aug 2023 07:43:33 -0400 Subject: [PATCH] First steps to extracting the search engine into it's own object. --- .../api/v1/clone/tries_controller.rb | 23 ++- app/controllers/api/v1/tries_controller.rb | 32 +++- app/models/search_endpoint.rb | 34 ++++ app/models/try.rb | 39 ++-- app/views/api/v1/tries/_try.json.jbuilder | 8 +- .../20230816172133_extract_search_endpoint.rb | 16 ++ .../20230816173857_create_join_to_teams.rb | 7 + ...3004_create_search_endpoints_from_tries.rb | 22 +++ ...33_drop_search_endpoint_fields_from_try.rb | 10 + db/schema.rb | 23 ++- .../api/v1/clone/cases_controller_test.rb | 6 +- .../api/v1/clone/tries_controller_test.rb | 8 +- .../api/v1/tries_controller_test.rb | 28 +-- test/controllers/core_controller_test.rb | 2 +- test/fixtures/search_endpoints.yml | 178 ++++++++++++++++++ test/fixtures/tries.yml | 134 ++++--------- test/integration/tls_flow_test.rb | 4 +- test/models/case_test.rb | 12 +- test/models/try_test.rb | 27 ++- 19 files changed, 432 insertions(+), 181 deletions(-) create mode 100644 app/models/search_endpoint.rb create mode 100644 db/migrate/20230816172133_extract_search_endpoint.rb create mode 100644 db/migrate/20230816173857_create_join_to_teams.rb create mode 100644 db/migrate/20230816183004_create_search_endpoints_from_tries.rb create mode 100644 db/migrate/20230816195233_drop_search_endpoint_fields_from_try.rb create mode 100644 test/fixtures/search_endpoints.yml diff --git a/app/controllers/api/v1/clone/tries_controller.rb b/app/controllers/api/v1/clone/tries_controller.rb index b34f7c183..d97b90849 100644 --- a/app/controllers/api/v1/clone/tries_controller.rb +++ b/app/controllers/api/v1/clone/tries_controller.rb @@ -11,14 +11,12 @@ class TriesController < Api::ApiController # rubocop:disable Metrics/MethodLength def create new_try_params = { - escape_query: @try.escape_query, - api_method: @try.api_method, - custom_headers: @try.custom_headers, - field_spec: @try.field_spec, - number_of_rows: @try.number_of_rows, - query_params: @try.query_params, - search_engine: @try.search_engine, - search_url: @try.search_url, + escape_query: @try.escape_query, + search_endpoint: @try.search_endpoint, + field_spec: @try.field_spec, + number_of_rows: @try.number_of_rows, + query_params: @try.query_params, + } @new_try = @case.tries.build new_try_params @@ -49,15 +47,16 @@ def set_try end def try_params + # Eric: I think we don't need to have all of these unless cloning a try chagnes the search end point..' params.require(:try).permit( :name, - :search_url, + # :search_url, :field_spec, :query_params, - :search_engine, + # :search_engine, :escape_query, - :api_method, - :custom_headers, + # :api_method, + # :custom_headers, :number_of_rows ) end diff --git a/app/controllers/api/v1/tries_controller.rb b/app/controllers/api/v1/tries_controller.rb index a2b972cc6..f12b666a3 100644 --- a/app/controllers/api/v1/tries_controller.rb +++ b/app/controllers/api/v1/tries_controller.rb @@ -22,8 +22,20 @@ def create if params[:parent_try_number] # We need special translation from try_number to the try.id parameters_to_use[:parent_id] = @case.tries.where(try_number: params[:parent_try_number]).first.id end + @try = @case.tries.build parameters_to_use + search_endpoint_params_to_use = search_endpoint_params + puts 'Here are the search_endpoint_params_to_use' + # not quite right because it could be via team, needs to be a scope. + search_endpoint_params_to_use['owner_id'] = @case.owner_id + puts search_endpoint_params_to_use + + unless search_endpoint_params_to_use['search_engine'].nil? + search_endpoint = SearchEndpoint.find_or_create_by search_endpoint_params_to_use + @try.search_endpoint = search_endpoint + end + try_number = @case.last_try_number + 1 @try.try_number = try_number @@ -76,17 +88,29 @@ def set_try def try_params params.require(:try).permit( :escape_query, - :api_method, - :custom_headers, + # :api_method, + # :custom_headers, :field_spec, :name, :number_of_rows, :query_params, - :search_engine, - :search_url, + # :search_engine, + # :search_url, :parent_id ) end + + def search_endpoint_params + params_to_return = params.require(:try).permit( + :api_method, + :custom_headers, + :search_engine, + :search_url + ) + # map from the old name to the new name + params_to_return['endpoint_url'] = params_to_return.delete 'search_url' + params_to_return + end end end end diff --git a/app/models/search_endpoint.rb b/app/models/search_endpoint.rb new file mode 100644 index 000000000..babc94557 --- /dev/null +++ b/app/models/search_endpoint.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: search_endpoints +# +# id :bigint not null, primary key +# api_method :string(255) +# custom_headers :string(1000) +# endpoint_url :string(500) +# name :string(255) +# search_engine :string(50) +# created_at :datetime not null +# updated_at :datetime not null +# owner_id :integer +# + +class SearchEndpoint < ApplicationRecord + # Associations + # too late now! + # rubocop:disable Rails/HasAndBelongsToMany + has_and_belongs_to_many :teams, + join_table: 'teams_search_endpoints' + # rubocop:enable Rails/HasAndBelongsToMany + + belongs_to :owner, + class_name: 'User', optional: true + + has_many :tries, dependent: :nullify, inverse_of: :search_endpoint + + # Validations + # validates :case_name, presence: true + # validates_with ScorerExistsValidator +end diff --git a/app/models/try.rb b/app/models/try.rb index aad8f34be..6a5a85076 100644 --- a/app/models/try.rb +++ b/app/models/try.rb @@ -4,21 +4,18 @@ # # Table name: tries # -# id :integer not null, primary key -# ancestry :string(3072) -# api_method :string(255) -# escape_query :boolean default(TRUE) -# field_spec :string(500) -# name :string(50) -# custom_headers :string(1000) -# number_of_rows :integer default(10) -# query_params :string(20000) -# search_engine :string(50) default("solr") -# search_url :string(500) -# try_number :integer -# created_at :datetime not null -# updated_at :datetime not null -# case_id :integer +# id :integer not null, primary key +# ancestry :string(3072) +# escape_query :boolean default(TRUE) +# field_spec :string(500) +# name :string(50) +# number_of_rows :integer default(10) +# query_params :string(20000) +# try_number :integer +# created_at :datetime not null +# updated_at :datetime not null +# case_id :integer +# search_endpoint_id :bigint # # Indexes # @@ -40,7 +37,9 @@ class Try < ApplicationRecord scope :latest, -> { order(id: :desc).first } # The try created the most recently # Associations - belongs_to :case, optional: true # shouldn't be optional, but was in rails 4 + belongs_to :case, optional: true # shouldn't be optional, but was in rails 4 + + belongs_to :search_endpoint, optional: true # see above too!#dependent: :nullify has_many :curator_variables, dependent: :destroy, @@ -53,7 +52,9 @@ class Try < ApplicationRecord before_create :set_defaults def args - case search_engine + return unless search_endpoint + + case search_endpoint.search_engine when 'solr' solr_args when 'es' @@ -124,9 +125,9 @@ def id_from_field_spec def index_name_from_search_url # NOTE: currently all supported engines have the index name as second to last element, refactor when this changes - case search_engine + case search_endpoint.search_engine when 'solr', 'es', 'os' - search_url.split('/')[-2] + search_endpoint.endpoint_url.split('/')[-2] end end diff --git a/app/views/api/v1/tries/_try.json.jbuilder b/app/views/api/v1/tries/_try.json.jbuilder index 07abc5792..e954cf4a0 100644 --- a/app/views/api/v1/tries/_try.json.jbuilder +++ b/app/views/api/v1/tries/_try.json.jbuilder @@ -1,14 +1,14 @@ # frozen_string_literal: true json.args try.args -json.custom_headers try.custom_headers +json.custom_headers try.search_endpoint&.custom_headers json.curator_vars try.curator_vars_map json.escape_query try.escape_query -json.api_method try.api_method +json.api_method try.search_endpoint&.api_method json.field_spec try.field_spec json.name try.name json.number_of_rows try.number_of_rows json.query_params try.query_params -json.search_engine try.search_engine -json.search_url try.search_url +json.search_engine try.search_endpoint&.search_engine +json.search_url try.search_endpoint&.endpoint_url json.try_number try.try_number diff --git a/db/migrate/20230816172133_extract_search_endpoint.rb b/db/migrate/20230816172133_extract_search_endpoint.rb new file mode 100644 index 000000000..382c88b0f --- /dev/null +++ b/db/migrate/20230816172133_extract_search_endpoint.rb @@ -0,0 +1,16 @@ +class ExtractSearchEndpoint < ActiveRecord::Migration[7.0] + def change + + create_table :search_endpoints do |t| + t.string "name", limit: 255 + t.integer "owner_id" + t.string "search_engine", limit: 50 + t.string "endpoint_url", limit: 500 + t.string "api_method" + t.string "custom_headers", limit: 1000 + t.timestamps + end + + add_column :tries, :search_endpoint_id, :bigint, foreign_key: true + end +end diff --git a/db/migrate/20230816173857_create_join_to_teams.rb b/db/migrate/20230816173857_create_join_to_teams.rb new file mode 100644 index 000000000..f67ccc13f --- /dev/null +++ b/db/migrate/20230816173857_create_join_to_teams.rb @@ -0,0 +1,7 @@ +class CreateJoinToTeams < ActiveRecord::Migration[7.0] + def change + create_join_table :search_endpoints, :teams, table_name: :teams_search_endpoints do |t| + end + + end +end diff --git a/db/migrate/20230816183004_create_search_endpoints_from_tries.rb b/db/migrate/20230816183004_create_search_endpoints_from_tries.rb new file mode 100644 index 000000000..5c81c3b9d --- /dev/null +++ b/db/migrate/20230816183004_create_search_endpoints_from_tries.rb @@ -0,0 +1,22 @@ +class CreateSearchEndpointsFromTries < ActiveRecord::Migration[7.0] + def change + Try.all.each do |try| + + # Go through and find each unique set of values from all the tries, + # and create a single end point that is used by multiple tries where it + # doesn't change. + search_endpoint = SearchEndpoint.find_or_create_by search_engine: try.search_engine, + endpoint_url: try.search_url, + api_method: try.api_method, + custom_headers: try.custom_headers, + owner_id: try.case.owner_id, + name: "#{try.search_engine} #{try.search_url}" + + try.search_endpoint = search_endpoint + + search_endpoint.save! + try.save! + + end + end +end diff --git a/db/migrate/20230816195233_drop_search_endpoint_fields_from_try.rb b/db/migrate/20230816195233_drop_search_endpoint_fields_from_try.rb new file mode 100644 index 000000000..93db05905 --- /dev/null +++ b/db/migrate/20230816195233_drop_search_endpoint_fields_from_try.rb @@ -0,0 +1,10 @@ +class DropSearchEndpointFieldsFromTry < ActiveRecord::Migration[7.0] + def change + # Now that we've moved all the fields over to SearchEndpoint, lets + # clean up after ourselves. + remove_column :tries, :search_engine + remove_column :tries, :search_url + remove_column :tries, :api_method + remove_column :tries, :custom_headers + end +end diff --git a/db/schema.rb b/db/schema.rb index ffe7b6721..b971ea134 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_06_30_124311) do +ActiveRecord::Schema[7.0].define(version: 2023_08_16_195233) do create_table "annotations", id: :integer, charset: "utf8mb3", force: :cascade do |t| t.text "message" t.string "source" @@ -153,6 +153,17 @@ t.boolean "communal", default: false end + create_table "search_endpoints", charset: "utf8mb4", collation: "utf8mb4_bin", force: :cascade do |t| + t.string "name" + t.integer "owner_id" + t.string "search_engine", limit: 50 + t.string "endpoint_url", limit: 500 + t.string "api_method" + t.string "custom_headers", limit: 1000 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "selection_strategies", charset: "utf8mb3", collation: "utf8mb3_unicode_ci", force: :cascade do |t| t.string "name" t.datetime "created_at", null: false @@ -222,21 +233,23 @@ t.index ["team_id"], name: "index_teams_scorers_on_team_id" end + create_table "teams_search_endpoints", id: false, charset: "utf8mb4", collation: "utf8mb4_bin", force: :cascade do |t| + t.bigint "search_endpoint_id", null: false + t.bigint "team_id", null: false + end + create_table "tries", id: :integer, charset: "latin1", force: :cascade do |t| t.integer "try_number" t.string "query_params", limit: 20000 t.integer "case_id" t.string "field_spec", limit: 500 - t.string "search_url", limit: 500 t.string "name", limit: 50 - t.string "search_engine", limit: 50, default: "solr" t.boolean "escape_query", default: true t.integer "number_of_rows", default: 10 t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "ancestry", limit: 3072 - t.string "api_method" - t.string "custom_headers", limit: 1000 + t.bigint "search_endpoint_id" t.index ["case_id"], name: "case_id" t.index ["try_number"], name: "ix_queryparam_tryNo" end diff --git a/test/controllers/api/v1/clone/cases_controller_test.rb b/test/controllers/api/v1/clone/cases_controller_test.rb index 8218ae6f8..dcb992359 100644 --- a/test/controllers/api/v1/clone/cases_controller_test.rb +++ b/test/controllers/api/v1/clone/cases_controller_test.rb @@ -62,11 +62,11 @@ class CasesControllerTest < ActionController::TestCase assert_equal the_try.query_params, cloned_try.query_params assert_equal 'id:id title:title', cloned_try.field_spec - assert_equal the_try.search_url, cloned_try.search_url + assert_equal the_try.search_endpoint, cloned_try.search_endpoint assert_equal 'Try 0', cloned_try.name - assert_equal the_try.search_engine, cloned_try.search_engine + # assert_equal the_try.search_engine, cloned_try.search_engine assert_equal the_try.escape_query, cloned_try.escape_query - assert_equal the_try.api_method, cloned_try.api_method + # assert_equal the_try.api_method, cloned_try.api_method assert_equal the_try.curator_variables.size, cloned_try.curator_variables.size end end diff --git a/test/controllers/api/v1/clone/tries_controller_test.rb b/test/controllers/api/v1/clone/tries_controller_test.rb index 7f1448abc..eaf147c62 100644 --- a/test/controllers/api/v1/clone/tries_controller_test.rb +++ b/test/controllers/api/v1/clone/tries_controller_test.rb @@ -17,12 +17,12 @@ class TriesControllerTest < ActionController::TestCase def assert_try_matches_response response, try assert_equal try.query_params, response['query_params'] assert_nil_or_equal try.field_spec, response['field_spec'] - assert_equal try.search_url, response['search_url'] + assert_equal try.search_endpoint.endpoint_url, response['search_url'] assert_equal try.try_number, response['try_number'] assert_equal try.name, response['name'] assert_equal try.solr_args, response['args'] assert_equal try.escape_query, response['escape_query'] - assert_equal try.api_method, response['api_method'] + assert_equal try.search_endpoint.api_method, response['api_method'] assert_curator_vars_equal try.curator_vars_map, response['curator_vars'] end @@ -30,9 +30,9 @@ def assert_try_matches_response response, try def assert_tries_match a_try, try assert_equal try.case_id, a_try.case_id assert_equal try.query_params, a_try.query_params - assert_equal try.search_url, a_try.search_url + assert_equal try.search_endpoint, a_try.search_endpoint assert_equal try.escape_query, a_try.escape_query - assert_equal try.api_method, a_try.api_method + # assert_equal try.api_method, a_try.api_method end def assert_curator_vars_equal vars, response_vars diff --git a/test/controllers/api/v1/tries_controller_test.rb b/test/controllers/api/v1/tries_controller_test.rb index d6ab3b293..35f042fca 100644 --- a/test/controllers/api/v1/tries_controller_test.rb +++ b/test/controllers/api/v1/tries_controller_test.rb @@ -13,26 +13,28 @@ class TriesControllerTest < ActionController::TestCase login_user joey end + # rubocop:disable Metrics/AbcSize def assert_try_matches_response response, try assert_equal try.query_params, response['query_params'] assert_equal try.field_spec, response['field_spec'] if response['field_spec'] - assert_nil_or_equal try.search_url, response['search_url'] + assert_nil_or_equal try.search_endpoint.endpoint_url, response['search_url'] assert_equal try.try_number, response['try_number'] assert_equal try.name, response['name'] if response['name'] assert_equal try.solr_args, response['args'] assert_equal try.escape_query, response['escape_query'] - assert_nil_or_equal try.api_method, response['api_method'] + assert_nil_or_equal try.search_endpoint.api_method, response['api_method'] assert_curator_vars_equal try.curator_vars_map, response['curator_vars'] end + # rubocop:enable Metrics/AbcSize def assert_try_matches_params params, try assert_equal try.query_params, params[:query_params] if params[:query_params] assert_equal try.field_spec, params[:field_spec] if params[:field_spec] - assert_equal try.search_url, params[:search_url] if params[:search_url] + assert_equal try.search_endpoint.endpoint_url, params[:search_url] if params[:search_url] assert_equal try.name, params[:name] if params[:name] assert_equal try.escape_query, params[:escape_query] if params[:escape_query] - assert_equal try.api_method, params[:api_method] if params[:api_method] + assert_equal try.search_endpoint.api_method, params[:api_method] if params[:api_method] end def assert_curator_vars_equal vars, response_vars @@ -289,7 +291,7 @@ def assert_curator_vars_equal vars, response_vars end test 'sets api_method param' do - post :create, params: { case_id: the_case.id, try: { api_method: 'get' } } + post :create, params: { case_id: the_case.id, try: { search_engine: 'es', api_method: 'get' } } assert_response :ok @@ -297,7 +299,7 @@ def assert_curator_vars_equal vars, response_vars created_try = the_case.tries.where(try_number: json_response['try_number']).first assert_equal 'get', json_response['api_method'] - assert_equal 'get', created_try.api_method + assert_equal 'get', created_try.search_endpoint.api_method end test 'sets number of rows' do @@ -326,9 +328,9 @@ def assert_curator_vars_equal vars, response_vars assert_match( /#{the_case.last_try_number}/, created_try.name ) assert_match( /#{created_try.try_number}/, created_try.name ) - assert_not_nil created_try.search_engine + assert_nil created_try.search_endpoint assert_nil created_try.field_spec - assert_nil created_try.search_url + assert_nil created_try.search_endpoint assert_nil created_try.query_params assert created_try.escape_query @@ -387,7 +389,7 @@ def assert_curator_vars_equal vars, response_vars describe 'Solr' do test 'sets the proper default values' do - post :create, params: { case_id: the_case.id, try: { name: '' } } + post :create, params: { case_id: the_case.id, try: { name: '', search_engine: 'solr' } } assert_response :ok # should be :created, # but there's a bug currently in the responders gem @@ -400,7 +402,7 @@ def assert_curator_vars_equal vars, response_vars assert_match( /#{the_case.last_try_number}/, created_try.name ) assert_match( /#{created_try.try_number}/, created_try.name ) - assert_not_nil created_try.search_engine + assert_not_nil created_try.search_endpoint.search_engine assert_equal created_try.escape_query, true end end @@ -420,11 +422,11 @@ def assert_curator_vars_equal vars, response_vars assert_match( /#{the_case.last_try_number}/, created_try.name ) assert_match( /#{created_try.try_number}/, created_try.name ) - assert_not_nil created_try.search_engine + assert_not_nil created_try.search_endpoint.search_engine assert_not_nil created_try.escape_query - assert_equal created_try.search_engine, 'es' - assert_equal created_try.escape_query, true + assert_equal created_try.search_endpoint.search_engine, 'es' + assert_equal created_try.escape_query, true end test 'parses args properly' do diff --git a/test/controllers/core_controller_test.rb b/test/controllers/core_controller_test.rb index e60fb8cfa..bb521aaec 100755 --- a/test/controllers/core_controller_test.rb +++ b/test/controllers/core_controller_test.rb @@ -43,7 +43,7 @@ class CoreControllerTest < ActionController::TestCase # We used to redirect the browser to match the # search engine URL, but don't do that anymore.' test 'bootstraps case with HTTPS search_engine ' do - the_try.search_url = 'https://somesearch.com' + the_try.search_endpoint.endpoint_url = 'https://somesearch.com' the_try.save! get :index diff --git a/test/fixtures/search_endpoints.yml b/test/fixtures/search_endpoints.yml new file mode 100644 index 000000000..1023ba3c6 --- /dev/null +++ b/test/fixtures/search_endpoints.yml @@ -0,0 +1,178 @@ +# == Schema Information +# +# Table name: search_endpoints +# +# id :bigint not null, primary key +# api_method :string(255) +# custom_headers :string(1000) +# endpoint_url :string(500) +# name :string(255) +# search_engine :string(50) +# created_at :datetime not null +# updated_at :datetime not null +# owner_id :integer +# + +one: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: GET + +two: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +for_shared_team_case: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +for_shared_case: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +archived: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +for_metadata_case: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +for_case_with_scorer: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +for_case_with_one_try: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +first_for_case_with_two_tries: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +second_for_case_with_two_tries: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +first_try_for_score_case: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +second_try_for_score_case: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +first_try_for_other_score_case: + name: Solr test.com + endpoint_url: test.com + search_engine: solr + api_method: JSONP + +second_try_for_other_score_case: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +try_without_curator_vars: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +try_with_curator_vars: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +es_try: + name: Es http://test.com:9200/tmdb/_search + endpoint_url: http://test.com:9200/tmdb/_search + search_engine: es + +es_try_with_curator_vars: + name: Es http://test.com:9200/tmdb/_search + endpoint_url: http://test.com:9200/tmdb/_search + search_engine: es + +try_with_headers: + name: Solr http://test.com:9200/tmdb/_search + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + custom_headers: '{"Authorization": "ApiKey TEF5QkFJUUJVUnRsNG1fekNCR3E6WmRYUFJRRVdTMHlBVWotWFdqQWxuUQ=="}' + + +bootstrap_try_1: + name: Solr https://test.com + endpoint_url: https://test.com + search_engine: solr + +bootstrap_try_2: + name: Es http://test.com:9200/tmdb/_search + endpoint_url: http://test.com:9200/tmdb/_search + search_engine: es + +for_case_without_score_try_1: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +for_case_with_score_for_first_try_try_1: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + +for_case_with_score_for_first_try_try_2: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +for_case_with_score_try_1: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + +for_case_with_score_try_2: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +for_case_with_score_try_3: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP + +for_case_queries_case: + name: Solr http://test.com/solr/tmdb/select + endpoint_url: http://test.com/solr/tmdb/select + search_engine: solr + api_method: JSONP diff --git a/test/fixtures/tries.yml b/test/fixtures/tries.yml index 6043b5733..36457bbf3 100644 --- a/test/fixtures/tries.yml +++ b/test/fixtures/tries.yml @@ -2,21 +2,18 @@ # # Table name: tries # -# id :integer not null, primary key -# ancestry :string(3072) -# api_method :string(255) -# custom_headers :string(1000) -# escape_query :boolean default(TRUE) -# field_spec :string(500) -# name :string(50) -# number_of_rows :integer default(10) -# query_params :string(20000) -# search_engine :string(50) default("solr") -# search_url :string(500) -# try_number :integer -# created_at :datetime not null -# updated_at :datetime not null -# case_id :integer +# id :integer not null, primary key +# ancestry :string(3072) +# escape_query :boolean default(TRUE) +# field_spec :string(500) +# name :string(50) +# number_of_rows :integer default(10) +# query_params :string(20000) +# try_number :integer +# created_at :datetime not null +# updated_at :datetime not null +# case_id :integer +# search_endpoint_id :bigint # # Indexes # @@ -32,227 +29,176 @@ one: case: :one try_number: 1 query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select - search_engine: solr - api_method: GET field_spec: id:id title:title + search_endpoint: :one two: case: :two try_number: 2 query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select - search_engine: solr - api_method: JSONP + search_endpoint: :two for_shared_team_case: case: :shared_team_case try_number: 1 query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select - search_engine: solr - api_method: JSONP + search_endpoint: :for_shared_team_case for_shared_case: case: :shared_case try_number: 1 query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select - search_engine: solr - api_method: JSONP + search_endpoint: :for_shared_case archived: case: :archived try_number: 1 query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select - search_engine: solr - api_method: JSONP + search_endpoint: :archived for_metadata_case: case: :with_metadata try_number: 2 query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select - search_engine: solr - api_method: JSONP + search_endpoint: :for_metadata_case for_case_with_scorer: case: :with_scorer try_number: 2 query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select - search_engine: solr - api_method: JSONP + search_endpoint: :for_case_with_scorer for_case_with_one_try: case: :case_with_one_try query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 1 - search_engine: solr - api_method: JSONP + search_endpoint: :for_case_with_one_try first_for_case_with_two_tries: case: :case_with_two_tries query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 1 - search_engine: solr - api_method: JSONP name: Try 1 + search_endpoint: :first_for_case_with_two_tries second_for_case_with_two_tries: case: :case_with_two_tries query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 2 - search_engine: solr - api_method: JSONP name: Second Try ancestry: '<%= ActiveRecord::FixtureSet.identify(:first_for_case_with_two_tries) %>' + search_endpoint: :second_for_case_with_two_tries first_try_for_score_case: case: :score_case query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 1 - search_engine: solr - api_method: JSONP + search_endpoint: :first_try_for_score_case second_try_for_score_case: case: :score_case query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 2 - search_engine: solr - api_method: JSONP + search_endpoint: :second_try_for_score_case first_try_for_other_score_case: case: :other_score_case query_params: 'q=#$query##' - search_url: test.com try_number: 1 - search_engine: solr - api_method: JSONP + search_endpoint: :first_try_for_other_score_case second_try_for_other_score_case: case: :other_score_case query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 2 - search_engine: solr - api_method: JSONP + search_endpoint: :second_try_for_other_score_case try_without_curator_vars: case: :random_case query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 2 - search_engine: solr - api_method: JSONP field_spec: id:id title:title + search_endpoint: :try_without_curator_vars try_with_curator_vars: case: :random_case query_params: 'q=#$query##&defType=edismax&qf=text^##one## catch_line^##two##' - search_url: http://test.com/solr/tmdb/select try_number: 3 - search_engine: solr - api_method: JSONP field_spec: id:id title:title + search_endpoint: :try_with_curator_vars es_try: case: :random_case query_params: '{ "query": { "match": { "text": "#$query##" } } }' - search_url: http://test.com:9200/tmdb/_search try_number: 4 - search_engine: es field_spec: id:_id title:title + search_endpoint: :es_try es_try_with_curator_vars: case: :random_case query_params: '{ "query": { "multi_match": { "fields": "title, overview", "query": "#$query##", "tie_breaker": "##tieBreaker##" } } }' - search_url: http://test.com:9200/tmdb/_search try_number: 5 - search_engine: es field_spec: id:_id title:title + search_endpoint: :es_try_with_curator_vars try_with_headers: case: :random_case query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 6 - search_engine: solr - api_method: JSONP field_spec: id:id title:title - custom_headers: '{"Authorization": "ApiKey TEF5QkFJUUJVUnRsNG1fekNCR3E6WmRYUFJRRVdTMHlBVWotWFdqQWxuUQ=="}' + search_endpoint: :try_with_headers bootstrap_try_1: case: :bootstrap_case query_params: 'q=#$query##' - search_url: https://test.com try_number: 1 - search_engine: solr + search_endpoint: :bootstrap_try_1 bootstrap_try_2: case: :bootstrap_case query_params: '{ "query": { "match": { "text": "#$query##" } } }' - search_url: http://test.com:9200/tmdb/_search try_number: 2 - search_engine: es + search_endpoint: :bootstrap_try_2 for_case_without_score_try_1: case: :case_without_score query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 1 - search_engine: solr - api_method: JSONP + search_endpoint: :for_case_without_score_try_1 for_case_with_score_for_first_try_try_1: case: :case_with_score_for_first_try query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 1 - search_engine: solr + search_endpoint: :for_case_with_score_for_first_try_try_1 for_case_with_score_for_first_try_try_2: case: :case_with_score_for_first_try query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 2 - search_engine: solr - api_method: JSONP + search_endpoint: :for_case_with_score_for_first_try_try_2 for_case_with_score_try_1: case: :case_with_score query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 1 - search_engine: solr + search_endpoint: :for_case_with_score_try_1 for_case_with_score_try_2: case: :case_with_score query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 2 - search_engine: solr - api_method: JSONP + search_endpoint: :for_case_with_score_try_2 for_case_with_score_try_3: case: :case_with_score query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 2 - search_engine: solr - api_method: JSONP + search_endpoint: :for_case_with_score_try_3 for_case_queries_case: case: :queries_case query_params: 'q=#$query##' - search_url: http://test.com/solr/tmdb/select try_number: 1 - search_engine: solr - api_method: JSONP + search_endpoint: :for_case_queries_case diff --git a/test/integration/tls_flow_test.rb b/test/integration/tls_flow_test.rb index 4e1ddf072..480b6188a 100644 --- a/test/integration/tls_flow_test.rb +++ b/test/integration/tls_flow_test.rb @@ -15,8 +15,8 @@ class TlsFlowTest < ActionDispatch::IntegrationTest try_http = kase.tries.first try_https = kase.tries.second - assert_not try_http.search_url.starts_with?('https') - assert try_https.search_url.starts_with?('https') + assert_not try_http.search_endpoint.endpoint_url.starts_with?('https') + assert try_https.search_endpoint.endpoint_url.starts_with?('https') # Navigate to a try that is http TLS protocol get case_core_url(id: kase.id, try_number: try_http.try_number) diff --git a/test/models/case_test.rb b/test/models/case_test.rb index eda9157eb..228167d28 100644 --- a/test/models/case_test.rb +++ b/test/models/case_test.rb @@ -157,13 +157,15 @@ class CaseTest < ActiveSupport::TestCase assert_equal the_try.query_params, cloned_try.query_params assert_equal the_try.field_spec, cloned_try.field_spec - assert_equal the_try.search_url, cloned_try.search_url assert_equal 'Try 0', cloned_try.name - assert_equal 0, cloned_case.tries.first.try_number - assert_equal the_try.search_engine, cloned_try.search_engine assert_equal the_try.escape_query, cloned_try.escape_query - assert cloned_try.custom_headers.present? - assert_equal the_try.custom_headers, cloned_try.custom_headers + assert_equal 0, cloned_case.tries.first.try_number + assert_equal the_try.search_endpoint, cloned_try.search_endpoint + # don't need these asserts once we assert same end point' + # assert_equal the_try.search_engine, cloned_try.search_engine + + # assert cloned_try.custom_headers.present? + # assert_equal the_try.custom_headers, cloned_try.custom_headers end end end diff --git a/test/models/try_test.rb b/test/models/try_test.rb index 63220ad20..b01a378e0 100644 --- a/test/models/try_test.rb +++ b/test/models/try_test.rb @@ -4,21 +4,18 @@ # # Table name: tries # -# id :integer not null, primary key -# ancestry :string(3072) -# api_method :string(255) -# custom_headers :string(1000) -# escape_query :boolean default(TRUE) -# field_spec :string(500) -# name :string(50) -# number_of_rows :integer default(10) -# query_params :string(20000) -# search_engine :string(50) default("solr") -# search_url :string(500) -# try_number :integer -# created_at :datetime not null -# updated_at :datetime not null -# case_id :integer +# id :integer not null, primary key +# ancestry :string(3072) +# escape_query :boolean default(TRUE) +# field_spec :string(500) +# name :string(50) +# number_of_rows :integer default(10) +# query_params :string(20000) +# try_number :integer +# created_at :datetime not null +# updated_at :datetime not null +# case_id :integer +# search_endpoint_id :bigint # # Indexes #