<commit_before># encoding: utf-8
require 'digest/md5'
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')

class RapidshareExtTest < Test::Unit::TestCase

  def setup
    FakeWeb.allow_net_connect = true
    @rs = Rapidshare::API.new :cookie =>  ENV['RAPIDSHARE_COOKIE']

    account = @rs.get_account_details

    # Check the account is the actually we wanted, because it will be erased in the next step
    assert_equal ENV['RAPIDSHARE_USERNAME'], account[:username]
    assert_equal ENV['RAPIDSHARE_EMAIL'], account[:email]
    assert_equal ENV['RAPIDSHARE_ACCOUNT_ID'], account[:accountid]

    @rs.erase_all_data!

    @download_dir = File.expand_path(File.dirname(__FILE__) + '/../../tmp')
    %w{file1.txt file2.txt file3.txt upload_file_1.txt}.each do |filename|
      File.delete "#@download_dir/#{filename}" if File.exist? "#@download_dir/#{filename}"
    end

    @upload_file_1 = File.expand_path(File.dirname(__FILE__) + '/../fixtures/files/upload1.txt')
    @upload_file_1_md5 = Digest::MD5.hexdigest(File.read(@upload_file_1))
    @upload_file_1_size = File.size @upload_file_1

    @upload_file_2 = File.expand_path(File.dirname(__FILE__) + '/../fixtures/files/upload2.txt')
    @upload_file_2_md5 = Digest::MD5.hexdigest(File.read(@upload_file_2))
    @upload_file_2_size = File.size @upload_file_2

    @upload_file_3 = File.expand_path(File.dirname(__FILE__) + '/../fixtures/files/upload3.txt')
    @upload_file_3_md5 = Digest::MD5.hexdigest(File.read(@upload_file_3))
    @upload_file_3_size = 102598 # 100 Kb
  end

  context 'Api' do
    should 'upload file' do
      upload_assertion = ->(resp, size_local, digest_local, remote_filename) do
        assert_instance_of Hash, resp
        assert_kind_of Integer, resp[:id]
        assert_kind_of Integer, resp[:size]
        assert_equal size_local, resp[:size]
        assert_instance_of String, resp[:checksum]
        assert_match /[a-z0-9]{32}/, resp[:checksum]<commit_msg>Starting of making gem standalone (it will not depend from the original rapidshare gem)<commit_after># encoding: utf-8
require 'digest/md5'
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')

class RapidshareExtTest < Test::Unit::TestCase

  def setup
    FakeWeb.allow_net_connect = true
    @rs = Rapidshare::API.new :cookie =>  ENV['RAPIDSHARE_COOKIE']

    account = @rs.get_account_details

    # Check the account is the actually we wanted, because it will be erased in the next step
    assert_equal ENV['RAPIDSHARE_USERNAME'], account[:username]
    assert_equal ENV['RAPIDSHARE_EMAIL'], account[:email]
    assert_equal ENV['RAPIDSHARE_ACCOUNT_ID'], account[:accountid]

    @rs.erase_all_data!

    @download_dir = File.expand_path(File.dirname(__FILE__) + '/../../tmp')
    %w{file1.txt file2.txt file3.txt upload_file_1.txt}.each do |filename|
      File.delete "#@download_dir/#{filename}" if File.exist? "#@download_dir/#{filename}"
    end

    @upload_file_1 = File.expand_path(File.dirname(__FILE__) + '/../fixtures/files/upload1.txt')
    @upload_file_1_md5 = Digest::MD5.hexdigest(File.read(@upload_file_1))
    @upload_file_1_size = File.size @upload_file_1

    @upload_file_2 = File.expand_path(File.dirname(__FILE__) + '/../fixtures/files/upload2.txt')
    @upload_file_2_md5 = Digest::MD5.hexdigest(File.read(@upload_file_2))
    @upload_file_2_size = File.size @upload_file_2

    @upload_file_3 = File.expand_path(File.dirname(__FILE__) + '/../fixtures/files/upload3.txt')
    @upload_file_3_md5 = Digest::MD5.hexdigest(File.read(@upload_file_3))
    @upload_file_3_size = 102598 # 100 Kb
  end

  context 'Api' do

    should 'initialize by login and password' do
      rs = Rapidshare::API.new :login => ENV['RAPIDSHARE_USERNAME'],
                               :password => ENV['<PASSWORD>']
      assert_equal ENV['RAPIDSHARE_COOKIE'], rs.cookie

      account = rs.get_account_details
      assert_equal ENV['RAPIDSHARE_USERNAME'], account[:username]
      assert_equal ENV['RAPIDSHARE_EMAIL'], account[:email]
      assert_equal ENV['RAPIDSHARE_ACCOUNT_ID'], account[:accountid]
    end

    should 'upload file' do
      upload_assertion = ->(resp, size_local, digest_local, remote_filename) do
        assert_instance_of Hash, resp
        assert_kind_of Integer, resp[:id]
        assert_kind_of Integer, resp[:size]
        assert_equal size_local, resp[:size]
        assert_instance_of String, resp[:checksum]
        assert_match /[a-z0-9]{32}/, resp[:checksum]
{'fraction_non_alphanumeric': 0.1282337198929527, 'fraction_numerical': 0.01873327386262266, 'mean_word_length': 4.13745704467354, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, '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': '3506033', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1515, 'n_words': 280}