<commit_before>require 'test_helper'


class SpecialAuthCodesAccessTest < ActionController::IntegrationTest
  ASSETS_WITH_AUTH_CODES = %w[data_files events models sops samples specimens presentations]

  def setup
    User.current_user = Factory(:user, :login => 'test')
    post '/sessions/create', :login => 'test', :password => '<PASSWORD>'
    Seek::Config.is_virtualliver = true
  end

  test 'form allows creating temporary access links' do
    ASSETS_WITH_AUTH_CODES.each do |type_name|
      p type_name
      get "/#{type_name}/new"
      assert_select "form div#temporary_links"

      get "/#{type_name}/#{Factory(type_name.singularize.to_sym, :policy => Factory(:public_policy)).id}/edit"
        assert_select "form div#temporary_links"
    end
  end

  test 'anonymous visitors can use access codes to show or download an item' do
    ASSETS_WITH_AUTH_CODES.each do |type_name|
      item = Factory(type_name.singularize.to_sym, :contributor => User.current_user)
      item.special_auth_codes << Factory(:special_auth_code, :asset => item)
      p type_name
      get "/sessions/destroy"

      get "/#{type_name}/show/#{item.id}?code=#{item.special_auth_codes.first.code}"
      assert_response :success

      if item.is_downloadable?
        get "/#{type_name}/download/#{item.id}?code=#{item.special_auth_codes.first.code}"
        assert_response :success
      end
    end
  end
end
<commit_msg>should keep the Seek::Config.is_virtualliver as it is after running the test<commit_after>require 'test_helper'


class SpecialAuthCodesAccessTest < ActionController::IntegrationTest
  ASSETS_WITH_AUTH_CODES = %w[data_files events models sops samples specimens presentations]

  def setup
    User.current_user = Factory(:user, :login => 'test')
    post '/sessions/create', :login => 'test', :password => '<PASSWORD>'
    @val = Seek::Config.is_virtualliver
    Seek::Config.is_virtualliver = true
  end

  def teardown
    Seek::Config.is_virtualliver = @val
  end

  test 'form allows creating temporary access links' do
    ASSETS_WITH_AUTH_CODES.each do |type_name|
      p type_name
      get "/#{type_name}/new"
      assert_select "form div#temporary_links"

      get "/#{type_name}/#{Factory(type_name.singularize.to_sym, :policy => Factory(:public_policy)).id}/edit"
        assert_select "form div#temporary_links"
    end
  end

  test 'anonymous visitors can use access codes to show or download an item' do
    ASSETS_WITH_AUTH_CODES.each do |type_name|
      item = Factory(type_name.singularize.to_sym, :contributor => User.current_user)
      item.special_auth_codes << Factory(:special_auth_code, :asset => item)
      p type_name
      get "/sessions/destroy"

      get "/#{type_name}/show/#{item.id}?code=#{item.special_auth_codes.first.code}"
      assert_response :success

      if item.is_downloadable?
        get "/#{type_name}/download/#{item.id}?code=#{item.special_auth_codes.first.code}"
        assert_response :success
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.11044377711044377, 'fraction_numerical': 0.0, 'mean_word_length': 3.8511326860841426, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7243601', 'n_tokens_mistral': 971, 'n_tokens_neox': 951, 'n_words': 213}