<commit_before>require 'test/unit'
require 'tempfile'
require 'filepicker_client'

class TestFilepickerClient < Test::Unit::TestCase
  def setup
    @api_key = ENV['FPAPIKEY']
    @api_secret = ENV['FPAPISECRET']
  end

  def test_file_uri
    client = FilepickerClient.new 'fake-key', 'fake-secret'
    uri = client.file_uri('fake-handle')
    assert_equal "https://www.filepicker.io/api/file/fake-handle", uri.to_s
  end

  def test_client_file_client_required
    begin
      client_file = FilepickerClientFile.new({}, nil)
    rescue FilepickerClientError => e
      assert_equal "FilepickerClientFile client required", e.message
      error_fired = true
    end

    assert error_fired, "FilepickerClientFile did not require a client as it should"
  end

  def test_file
    assert @api_key, "Must set FPAPIKEY for this test"
    assert @api_secret, "Must set FPAPISECRET for this test"

    client = FilepickerClient.new @api_key, @api_secret

    content = "test file content\n" * 10

    store_file = Tempfile.new('test.txt')
    store_file.write content
    store_file.rewind

    write_content = "write content\n" * 10

    write_file = Tempfile.new('test-write.txt')
    write_file.write write_content
    write_file.rewind

    begin
      # store
      file = client.store(store_file, 'test')

      # file attributes
      assert_match /^test\.txt/, file.filename

      #file_uri
      file_uri = file.file_uri
      assert_equal "https://www.filepicker.io/api/file/#{file.handle}", file_uri.to_s

      # stat
      stats = file.stat
      assert_equal content.length, stats[:size]
      assert_equal 'text/plain', stats[:mimetype]

      # read
      downloaded_content = file.read
      assert_equal content, downloaded_content

      # store_url
      second_file = client.store_url file.file_read_uri_and_expiry[:uri], 'test'
      assert_not_equal second_file.handle, file.handle
      assert_equal second_file.read, content<commit_msg>updated test file to work with Minitest 5<commit_after>require 'minitest/autorun'
require 'tempfile'
require 'filepicker_client'

class TestFilepickerClient < Minitest::Test
  def setup
    @api_key = ENV['FPAPIKEY']
    @api_secret = ENV['FPAPISECRET']
  end

  def test_file_uri
    client = FilepickerClient.new 'fake-key', 'fake-secret'
    uri = client.file_uri('fake-handle')
    assert_equal "https://www.filepicker.io/api/file/fake-handle", uri.to_s
  end

  def test_client_file_client_required
    begin
      client_file = FilepickerClientFile.new({}, nil)
    rescue FilepickerClientError => e
      assert_equal "FilepickerClientFile client required", e.message
      error_fired = true
    end

    assert error_fired, "FilepickerClientFile did not require a client as it should"
  end

  def test_file
    assert @api_key, "Must set FPAPIKEY for this test"
    assert @api_secret, "Must set FPAPISECRET for this test"

    client = FilepickerClient.new @api_key, @api_secret

    content = "test file content\n" * 10

    store_file = Tempfile.new('test.txt')
    store_file.write content
    store_file.rewind

    write_content = "write content\n" * 10

    write_file = Tempfile.new('test-write.txt')
    write_file.write write_content
    write_file.rewind

    begin
      # store
      file = client.store(store_file, 'test')

      # file attributes
      assert_match /^test\.txt/, file.filename

      #file_uri
      file_uri = file.file_uri
      assert_equal "https://www.filepicker.io/api/file/#{file.handle}", file_uri.to_s

      # stat
      stats = file.stat
      assert_equal content.length, stats[:size]
      assert_equal 'text/plain', stats[:mimetype]

      # read
      downloaded_content = file.read
      assert_equal content, downloaded_content

      # store_url
      second_file = client.store_url file.file_read_uri_and_expiry[:uri], 'test'
      refute_equal second_file.handle, file.handle
      assert_equal second_file.read, content
{'fraction_non_alphanumeric': 0.09291698400609291, 'fraction_numerical': 0.002284843869002285, 'mean_word_length': 3.264069264069264, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '793955', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1236, 'n_words': 286}