File: online_test.rb

package info (click to toggle)
libwww-delicious-ruby 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 320 kB
  • ctags: 366
  • sloc: ruby: 2,178; xml: 106; makefile: 2
file content (147 lines) | stat: -rw-r--r-- 3,518 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# 
# = WWW::Delicious
#
# Ruby client for del.icio.us API.
# 
#
# Category::    WWW
# Package::     WWW::Delicious
# Author::      Simone Carletti <weppos@weppos.net>
# License::     MIT License
#
#--
# SVN: $Id$
#++


require 'test_helper'


RUN_ONLINE_TESTS = ($0 == __FILE__) unless defined?(RUN_ONLINE_TESTS)

puts "Online test #{__FILE__} skipped.\n" +
     "Use `ONLINE=1` to run online tests.\n" unless RUN_ONLINE_TESTS


class OnlineTest < Test::Unit::TestCase
  
  def setup
    init_account
  end
  
  
  def test_update
    response = @delicious.update
    assert_instance_of(Time, response)
  end
  
  
  def test_bundles_all
    response = @delicious.bundles_all
    assert_kind_of(Array, response)

    response.each do |bundle|
      assert_instance_of(WWW::Delicious::Bundle, bundle)
      assert_instance_of(Array, bundle.tags)
      assert_not_nil(bundle.name)
    end
  end
  
  def test_bundles_set
    bundle = WWW::Delicious::Bundle.new(:name => 'test_bundle', :tags => %w(ruby python).sort)
    assert_nothing_raised() { @delicious.bundles_set(bundle) }
  end
  
  def test_bundles_delete
    bundle = WWW::Delicious::Bundle.new(:name => 'test_bundle')
    assert_nothing_raised() { @delicious.bundles_delete(bundle) }
  end
  
  
  def test_tags_get
    response = @delicious.tags_get
    assert_kind_of(Array, response)

    response.each do |tag|
      assert_instance_of(WWW::Delicious::Tag, tag)
      assert_not_nil(tag.name)
      assert_not_nil(tag.count)
    end
  end
  
  def test_tags_rename
    ftag = WWW::Delicious::Tag.new(:name => 'old_tag')
    otag = WWW::Delicious::Tag.new(:name => 'new_tag')
    assert_nothing_raised() { @delicious.tags_rename(ftag, otag) }
  end
  
  
  def test_post_add
    # TODO
  end
  
  def test_post_all
    response = @delicious.posts_get
    assert_kind_of(Array, response)

    response.each do |post|
      assert_kind_of(WWW::Delicious::Post, post)
    end
  end
  
  def test_post_dates
    response = @delicious.posts_dates
    assert_kind_of(Hash, response)

    response.each do |item, value|
      assert_match(/[\d]{4}-[\d]{2}-[\d]{2}/, item)
      assert_match(/[\d]+/, value.to_s)
    end
  end
  
  def test_post_delete
    # TODO
  end
  
  def test_posts_get
    response = @delicious.posts_get
    assert_kind_of(Array, response)

    response.each do |post|
      assert_kind_of(WWW::Delicious::Post, post)
    end
  end
  
  def test_posts_recent
    response = @delicious.posts_recent
    assert_kind_of(Array, response)

    response.each do |post|
      assert_kind_of(WWW::Delicious::Post, post)
    end
  end
  
  
  protected
  
    def init_account(options = {}, &block)
      @delicious_username ||= ENV['DELICIOUS_USERNAME'] || self.class.prompt('Delicious Username') { |value| abort('Value cannot be blank') if value.blank?; value }
      @delicious_password ||= ENV['DELICIOUS_PASSWORD'] || self.class.prompt('Delicious Password') { |value| abort('Value cannot be blank') if value.blank?; value }
      @delicious = WWW::Delicious.new(@delicious_username, @delicious_password, options, &block)
    end
    
    # Convenient method for collecting user input
    def self.prompt(text, options = {}, &block)
      default = options[:default] || ''
      value   = nil
      while value.blank?
        print "#{text} [#{default}]: "
        value = STDIN.gets.chomp!
        value = default if value.blank?
        value = yield value if block_given?
        value
      end
      value
    end

end if RUN_ONLINE_TESTS