Sha256: a4c676a140d25fc90461008545dba381ea47c470fdb5cd111c54f927b2447091

Contents?: true

Size: 1.93 KB

Versions: 367

Compression:

Stored size: 1.93 KB

Contents

require '../lib/files.com'
require 'tempfile'

def assert(value)
  raise "failed assertion" unless value
end

Files.api_key = File.read(File.expand_path("../../../.test_credentials", __dir__)).strip
Files.base_url = "https://sdk.filesstaging.av"
Files.logger = Logger.new($stdout)
Files.log_level = 'debug'

def test_user_list_and_update
  user = Files::User.all.first
  user = Files::User.find(user.id)
  user.name = name = "Name #{Time.now.to_i}"
  user.save
  sleep 0.5
  user = Files::User.find(user.id)
  assert(name == user.name)
end

def test_user_create_and_delete
  name = "Test User #{Time.now.to_i}"
  user = Files::User.new(name: name, username: "test_user_#{Time.now.to_i}")
  user.save
  sleep 0.5
  user = Files::User.find(user.id)
  assert(name == user.name)
  user.destroy
end

def test_folder_operations
  name = "folder_#{Time.now.to_i}"
  Files::Folder.create(name)
  file = Files::File.find(name)
  file.copy("#{name}_copy")
  file.delete
  file = Files::File.find("#{name}_copy")
  file.move("#{name}_moved_copy")
  file = Files::File.find("#{name}_moved_copy")
  Files::Folder.create("#{file.path}/child")
  Files::FileUtils.rm_r(file.path)
end

def test_file_operations
  name = "file_#{Time.now.to_i}.txt"
  Files::File.upload_file(File.expand_path("../README.md", __dir__), name)
  file = Files::Folder.find(name) # also finds files
  file.delete
end

def test_file_ruby_emulation
  data_string = "File contents - #{Time.now}"
  name = "file_#{Time.now.to_i}.txt"
  Files::File.open(name, 'w') do |f|
    f.write(data_string)
  end
  file = Files::File.find(name)
  assert(file.read == data_string)
  file.delete
end

def test_sessions
  session = Files::Session.create(username: "sessionuser", password: "sessionuserpassword")
  Files::ApiKey.list({ user_id: 0 }, session: session)
  session.destroy
end

#test_user_list_and_update
#test_user_create_and_delete
#test_folder_operations
#test_file_operations
#test_file_ruby_emulation
test_sessions

Version data entries

367 entries across 367 versions & 1 rubygems

Version Path
files.com-1.1.100 test/test.rb
files.com-1.1.99 test/test.rb
files.com-1.1.98 test/test.rb
files.com-1.1.97 test/test.rb
files.com-1.1.96 test/test.rb
files.com-1.1.95 test/test.rb
files.com-1.1.94 test/test.rb
files.com-1.1.93 test/test.rb
files.com-1.1.92 test/test.rb
files.com-1.1.91 test/test.rb
files.com-1.1.90 test/test.rb
files.com-1.1.89 test/test.rb
files.com-1.1.88 test/test.rb
files.com-1.1.87 test/test.rb
files.com-1.1.66 test/test.rb
files.com-1.1.65 test/test.rb
files.com-1.1.64 test/test.rb
files.com-1.1.63 test/test.rb
files.com-1.1.62 test/test.rb
files.com-1.1.61 test/test.rb