blythedunham-base4r 0.2.0.6 → 0.2.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,93 @@
1
+ # Base4R is a ruby interface to Google Base
2
+ # Copyright 2007 Dan Dukeson
3
+
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License along
15
+ # with this program; if not, write to the Free Software Foundation, Inc.,
16
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
+
18
+ #
19
+ # tests for BaseClient
20
+ #
21
+
22
+ require 'test/unit'
23
+ require 'base_client'
24
+ require 'net/http'
25
+ require 'test/test_config'
26
+
27
+ module Base4R
28
+
29
+ class BaseClientTest < Test::Unit::TestCase #:nodoc:
30
+
31
+ def setup
32
+
33
+ @username = TEST_CONFIG[:username]
34
+ @password = TEST_CONFIG[:password]
35
+ @api_key = TEST_CONFIG[:api_key]
36
+
37
+ @base_client = Base4R::BaseClient.new(@username, @password, @api_key, false)
38
+
39
+ @item = UniversalItem.new('TEST123',
40
+ 'base4r test author',
41
+ 'base4r@example.com',
42
+ 'This description describes a new item',
43
+ 'http://example.com/items/dir/34545.html',
44
+ 'Title of a new item',
45
+ '0114 1111111',
46
+ 'products',
47
+ 'GB',
48
+ 'EN')
49
+
50
+ end
51
+
52
+ def teardown
53
+ end
54
+
55
+ def test_feed_path
56
+
57
+ assert_equal '/base/feeds/items/', @base_client.feed_path
58
+ another_client = BaseClient.new(@username, @password, @api_key)
59
+ assert_equal '/base/feeds/snippets/', another_client.feed_path
60
+ end
61
+
62
+ def test_update_item
63
+
64
+ base_id = @base_client.create_item(@item)
65
+ assert base_id.kind_of?(String)
66
+ @item.add_label('updated_label')
67
+ assert @base_client.update_item(@item)
68
+ end
69
+
70
+ def test_post_simple_item
71
+
72
+ base_id = @base_client.create_item(@item)
73
+ assert base_id.kind_of?(String)
74
+ end
75
+
76
+ def test_delete_item
77
+
78
+ assert @base_client.create_item(@item)
79
+ assert @base_client.delete_item(@item)
80
+ end
81
+
82
+ # sanity test to assert the network is up
83
+ def test_getter
84
+
85
+ resp = Net::HTTP.get_response('www.google.com', '/base/feeds/itemtypes/en_GB/jobs')
86
+ assert resp.kind_of?(Net::HTTPOK)
87
+ end
88
+
89
+
90
+ end
91
+
92
+ end
93
+
@@ -0,0 +1,60 @@
1
+ # Base4R is a ruby interface to Google Base
2
+ # Copyright 2007 Dan Dukeson
3
+
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License along
15
+ # with this program; if not, write to the Free Software Foundation, Inc.,
16
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
+
18
+ #
19
+ # tests for ClientLogin
20
+ #
21
+
22
+ require 'test/unit'
23
+ require 'client_login'
24
+ require 'test/test_config'
25
+
26
+ module Base4R
27
+
28
+ class ClientTest < Test::Unit::TestCase #:nodoc:
29
+
30
+ def setup
31
+
32
+ @username = TEST_CONFIG[:username]
33
+ @password = TEST_CONFIG[:password]
34
+ @login = ClientLogin.new
35
+ end
36
+
37
+ def test_login_correct
38
+
39
+ resp = @login.authenticate(@username, @password)
40
+ assert resp
41
+ end
42
+
43
+ def test_login_incorrect
44
+
45
+ resp = @login.authenticate(@username, @password+'wrongpassword');
46
+ assert resp.instance_of?(Net::HTTPForbidden)
47
+ flunk
48
+
49
+ rescue
50
+ assert true
51
+ end
52
+
53
+ def test_captcha_exception
54
+ e = CaptchaRequiredException.new('test@example.com')
55
+ assert_equal 'test@example.com', e.email
56
+ end
57
+
58
+ end
59
+
60
+ end
data/test/item_test.rb ADDED
@@ -0,0 +1,51 @@
1
+ #
2
+ # tests for Item and children
3
+ #
4
+
5
+ require 'test/unit'
6
+ require 'item'
7
+
8
+ module Base4R
9
+
10
+ class ItemTest < Test::Unit::TestCase #:nodoc:
11
+
12
+ def setup
13
+
14
+ @item = UniversalItem.new('ABC123',
15
+ 'Dan',
16
+ 'dan@example.com',
17
+ 'A wonderful item with many featureful benefits',
18
+ 'http://example.com/greatstuff/item/goo',
19
+ 'Beneficial Product',
20
+ '0114 1234567',
21
+ 'generic item',
22
+ 'GB',
23
+ 'EN')
24
+
25
+ @expiration_time = Time.now+7*60*60*24
26
+
27
+ @item.application = 'base4r'
28
+ @item.expiration_date = @expiration_time
29
+ @item.add_image_link('http://example.com/images/big1.png')
30
+ @item.add_image_link('http://example.com/images/big2.png')
31
+ @item.add_label('big')
32
+ @item.add_label('clever')
33
+ @item.add_label('funny')
34
+
35
+ end
36
+
37
+
38
+ def test_attributes_present
39
+ assert_equal 14, @item.attributes.size
40
+ end
41
+
42
+ def test_xml
43
+
44
+ expected_xml = "<?xml version='1.0'?><entry xmlns:g='http://base.google.com/ns/1.0' xmlns='http://www.w3.org/2005/Atom'><author><name>Dan</name><email>dan@example.com</email></author><category term='googlebase.item' scheme='http://www.google.com/type'/><title>Beneficial Product</title><link href='http://example.com/greatstuff/item/goo' rel='alternate' type='text/html'/><content>A wonderful item with many featureful benefits</content><g:contact_phone type='text'>0114 1234567</g:contact_phone><g:item_language type='text'>EN</g:item_language><g:item_type type='text'>generic item</g:item_type><g:target_country type='text'>GB</g:target_country><g:id type='text'>ABC123</g:id><g:application type='text'>base4r</g:application><g:expiration_date type='dateTime'>#{@expiration_time}</g:expiration_date><g:image_link>http://example.com/images/big1.png</g:image_link><g:image_link>http://example.com/images/big2.png</g:image_link><g:label type='text'>big</g:label><g:label type='text'>clever</g:label><g:label type='text'>funny</g:label></entry>"
45
+ actual_xml = ""
46
+ @item.to_xml.write(actual_xml)
47
+ self.assert_equal expected_xml, actual_xml
48
+
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blythedunham-base4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.6
4
+ version: 0.2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Dukeson, Blythe Dunham
@@ -21,8 +21,20 @@ extensions: []
21
21
 
22
22
  extra_rdoc_files: []
23
23
 
24
- files: []
25
-
24
+ files:
25
+ - lib/attribute.rb
26
+ - lib/base4r.rb
27
+ - lib/base_client.rb
28
+ - lib/client_login.rb
29
+ - lib/item.rb
30
+ - lib/http_logger.rb
31
+ - test/attribute_test.rb
32
+ - test/client_login_test.rb
33
+ - test/item_test.rb
34
+ - test/base_client_test.rb
35
+ - cert/cacert.pem
36
+ - LICENSE
37
+ - README
26
38
  has_rdoc: false
27
39
  homepage: http://github.com/blythedunham/base4r
28
40
  post_install_message: