require File.dirname(__FILE__) + '/test_helper.rb'
require "test/unit"
require 'pit'
class Tumblr4rTest < Test::Unit::TestCase
include Tumblr4r
READ_TEST_HOST = "tumblr4rtest.tumblr.com"
WRITE_TEST_HOST = "tumblr4rwritetest.tumblr.com"
TOTAL_COUNT = 114
QUOTE_COUNT = 102
def setup
@site = Site.new(READ_TEST_HOST)
writetest_conf = Pit.get("tumblr4rwritetest",
:require => {"email" => "required email",
"password" => "required password"})
@write_site = Site.new(WRITE_TEST_HOST,
writetest_conf["email"],
writetest_conf["password"])
@large_site = Site.new("tumblr4rfindtest.tumblr.com")
end
def teardown
end
def test_initialize
assert_equal READ_TEST_HOST, @site.hostname
assert_nil @site.email
assert_nil @site.password
assert_equal "tumblr4rtest", @site.name
assert_equal "Asia/Tokyo", @site.timezone
assert_equal "tumblr4rテスト", @site.title
assert_nil @site.cname
assert_equal "tumblr4rのテスト用サイトです。\r\ntumblrサイコー", @site.description
# TODO: feeds は後回し
end
def test_count
total = @large_site.count
assert_equal TOTAL_COUNT, total
total = @large_site.count(:type => "quote")
assert_equal QUOTE_COUNT, total
total = @large_site.count(:filter => "text")
assert_equal TOTAL_COUNT, total
total = @large_site.count(:tagged => "test")
assert_equal TOTAL_COUNT, total
total = @large_site.count(:search => "test")
assert_equal TOTAL_COUNT, total
end
def test_find
posts = @site.find(:all)
assert_equal 8, posts.size
assert_equal Video, posts[0].class
end
def test_find_all
posts = @large_site.find(:all)
assert_equal TOTAL_COUNT, posts.size
end
def test_find_all_quote
posts = @large_site.find(:all, :type => "quote")
assert_equal QUOTE_COUNT, posts.size
end
# 実際に存在する件数より少なく指定した場合
def test_find_all_with_num
posts = @large_site.find(:all, :limit => 74)
assert_equal 74, posts.size
end
# 実際に存在する件数より多く指定した場合
def test_find_all_with_over_num
posts = @large_site.find(:all, :limit => 765)
assert_equal TOTAL_COUNT, posts.size
end
def test_find_all_with_offset
posts = @large_site.find(:all, :offset => 12)
assert_equal TOTAL_COUNT-12, posts.size
end
# 実際に存在するよりも多いoffsetを指定した場合
def test_find_all_over_offset
posts = @large_site.find(:all, :type => "quote", :offset => TOTAL_COUNT + 1)
assert_equal 0, posts.size
end
def test_find_with_type_regular
posts = @site.find(:all, :type => "regular")
assert_equal 2, posts.size
assert_equal Regular, posts[0].class
assert_equal 123459291, posts[0].post_id
assert_equal "http://tumblr4rtest.tumblr.com/post/123459291", posts[0].url
assert_equal "http://tumblr4rtest.tumblr.com/post/123459291/regular-test", posts[0].url_with_slug
assert_equal "regular", posts[0].type
assert_equal "2009-06-14 16:30:44 GMT", posts[0].date_gmt
assert_equal "Mon, 15 Jun 2009 01:30:44", posts[0].date
assert_equal 1244997044, posts[0].unix_timestamp
assert_equal "html", posts[0].format
assert_equal ["test", "regular"], posts[0].tags
assert_equal false, posts[0].bookmarklet
assert_equal "Text Postのテストです", posts[0].regular_title
assert_equal <
ボールドです。
イタリックです。
取り消し線です。
ここからインデント
インデント開始
ああああ
インデント終了
ここまでインデント
EOF assert_equal Regular, posts[1].class assert_equal 122871637, posts[1].post_id assert_equal "http://tumblr4rtest.tumblr.com/post/122871637", posts[1].url assert_equal "http://tumblr4rtest.tumblr.com/post/122871637/tumblr4r", posts[1].url_with_slug assert_equal "regular", posts[1].type assert_equal "2009-06-13 12:46:23 GMT", posts[1].date_gmt assert_equal "Sat, 13 Jun 2009 21:46:23", posts[1].date assert_equal 1244897183, posts[1].unix_timestamp assert_equal "html", posts[1].format assert_equal [], posts[1].tags assert_equal false, posts[1].bookmarklet assert_equal "", posts[1].regular_title assert_equal "Tumblr4rのテストです", posts[1].regular_body end def test_find_with_type_photo posts = @site.find(:all, :type => "photo") assert_equal 1, posts.size assert_equal Photo, posts[0].class assert_equal 123461063, posts[0].post_id assert_equal "http://tumblr4rtest.tumblr.com/post/123461063", posts[0].url assert_equal "http://tumblr4rtest.tumblr.com/post/123461063/photo", posts[0].url_with_slug assert_equal "photo", posts[0].type assert_equal "2009-06-14 16:34:50 GMT", posts[0].date_gmt assert_equal "Mon, 15 Jun 2009 01:34:50", posts[0].date assert_equal 1244997290, posts[0].unix_timestamp assert_equal "html", posts[0].format assert_equal ["test", "photo"], posts[0].tags assert_equal false, posts[0].bookmarklet assert_equal "Photoのテストです。
\n\nギコです。
", posts[0].photo_caption assert_equal "http://www.google.co.jp/", posts[0].photo_link_url assert_equal "http://5.media.tumblr.com/GyEYZujUYopiula4XKmXhCgmo1_250.jpg", posts[0].photo_url end def test_find_with_type_quote posts = @site.find(:all, :type => "quote") assert_equal 1, posts.size assert_equal Quote, posts[0].class assert_equal 123470309, posts[0].post_id assert_equal "http://tumblr4rtest.tumblr.com/post/123470309", posts[0].url assert_equal "http://tumblr4rtest.tumblr.com/post/123470309/wikipedia-tumblr", posts[0].url_with_slug assert_equal "quote", posts[0].type assert_equal "2009-06-14 16:58:00 GMT", posts[0].date_gmt assert_equal "Mon, 15 Jun 2009 01:58:00", posts[0].date assert_equal 1244998680, posts[0].unix_timestamp assert_equal "html", posts[0].format assert_equal ["quote", "test"], posts[0].tags assert_equal true, posts[0].bookmarklet assert_equal <ボールドです。
イタリックです。
取り消し線です。
ここからインデント
インデント開始
ああああ
インデント終了
ここまでインデント
EOF end def test_quote_create quotes = @site.find(:all, :type => Tumblr4r::POST_TYPE::QUOTE) post = @write_site.save(quotes[0]) assert_not_equal quotes[0].post_id, post.post_id assert_equal "http://#{WRITE_TEST_HOST}/post/#{post.post_id}", post.url assert_equal "http://#{WRITE_TEST_HOST}/post/#{post.post_id}/tumblelog-tumblr", post.url_with_slug assert_equal Tumblr4r::POST_TYPE::QUOTE, post.type assert_equal quotes[0].date_gmt, post.date_gmt assert_equal quotes[0].date, post.date # TODO # assert_equal 1245045480, post.unix_timestamp assert_equal quotes[0].format, post.format assert_equal quotes[0].tags, post.tags assert_equal false, post.bookmarklet assert_equal quotes[0].quote_text, post.quote_text assert_equal quotes[0].quote_source, post.quote_source end def test_regular_create regulars = @site.find(:all, :type => Tumblr4r::POST_TYPE::REGULAR) post = @write_site.save(regulars[0]) end def test_link_create links = @site.find(:all, :type => Tumblr4r::POST_TYPE::LINK) post = @write_site.save(links[0]) end def test_photo_create photos = @site.find(:all, :type => Tumblr4r::POST_TYPE::PHOTO) post = @write_site.save(photos[0]) end # def test_audio_create # audios = @site.find(:all, :type => Tumblr4r::POST_TYPE::AUDIO) # post = @write_site.save(audios[0]) # end def test_video_create videos = @site.find(:all, :type => Tumblr4r::POST_TYPE::VIDEO) post = @write_site.save(videos[0]) end end