app_store 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,180 @@
1
+ require "test_helper"
2
+
3
+ class ApplicationTest < Test::Unit::TestCase
4
+
5
+ context "test custom initializer with an emulated plist as a hash" do
6
+ setup do
7
+ AppStore::Application.send(:public, *AppStore::Application.protected_instance_methods)
8
+ @plist = {
9
+ 'type' => 'software',
10
+ 'store-offers' => {
11
+ 'STDQ' => {
12
+ 'price' => 42,
13
+ 'size' => 101010
14
+ }
15
+ },
16
+ 'artwork-urls' => [
17
+ { "box-height" => 57,
18
+ "url" => "http://a1.phobos.apple.com/us/r1000/058/Purple/c6/e0/62/mzl.eillqyke.png",
19
+ "box-width" => 57,
20
+ "needs-shine" => false },
21
+
22
+ { "box-height" => 460,
23
+ "url" => "http://a1.phobos.apple.com/us/r1000/009/Purple/d7/72/58/mzl.yridpiqv.480x480-75.jpg",
24
+ "box-width" => 320 },
25
+
26
+ { "default" => {
27
+ "box-height" => 57,
28
+ "url" => "http://a1.phobos.apple.com/us/r1000/058/Purple/c6/e0/62/mzl.eillqyke.png",
29
+ "box-width" => 57,
30
+ "needs-shine" => false
31
+ },
32
+ "image-type" => "software-icon",
33
+ "url" => "" },
34
+
35
+ { "thumbnail" => {
36
+ "box-height" => 99,
37
+ "url" => "http://a1.phobos.apple.com/us/r1000/037/Purple/df/fa/6a/mzl.mlprrfol.148x99-75.jpg",
38
+ "box-width" => 148,
39
+ "needs-shine" => false
40
+ },
41
+ "default" => {
42
+ "box-height" => 460,
43
+ "url" => "http://a1.phobos.apple.com/us/r1000/037/Purple/df/fa/6a/mzl.mlprrfol.480x480-75.jpg",
44
+ "box-width" => 320
45
+ },
46
+ "image-type" => "screenshot",
47
+ "url" => "" },
48
+ { "thumbnail" => {
49
+ "box-height" => 99,
50
+ "url" => "http://a1.phobos.apple.com/us/r1000/058/Purple/d5/d4/6a/mzl.zmpdhenu.148x99-75.jpg",
51
+ "box-width" => 148,
52
+ "needs-shine" => false
53
+ },
54
+ "default" => {
55
+ "box-height" => 460,
56
+ "url" => "http://a1.phobos.apple.com/us/r1000/058/Purple/d5/d4/6a/mzl.zmpdhenu.480x480-75.jpg",
57
+ "box-width" => 320
58
+ },
59
+ "image-type" => "screenshot",
60
+ "url" => "" },
61
+ { "thumbnail" => {
62
+ "box-height" => 99,
63
+ "url" => "http://a1.phobos.apple.com/us/r1000/029/Purple/d3/9c/76/mzl.xgeoazvu.148x99-75.jpg",
64
+ "box-width" => 148,
65
+ "needs-shine" => false
66
+ },
67
+ "default" => {
68
+ "box-height" => 460,
69
+ "url" => "http://a1.phobos.apple.com/us/r1000/029/Purple/d3/9c/76/mzl.xgeoazvu.480x480-75.jpg",
70
+ "box-width" => 320
71
+ },
72
+ "image-type" => "screenshot",
73
+ "url" => "" },
74
+ { "thumbnail" => {
75
+ "box-height" => 99,
76
+ "url" => "http://a1.phobos.apple.com/us/r1000/038/Purple/df/24/ec/mzl.ktobakku.148x99-75.jpg",
77
+ "box-width" => 148,
78
+ "needs-shine" => false
79
+ },
80
+ "default" => {
81
+ "box-height" => 480,
82
+ "url" => "http://a1.phobos.apple.com/us/r1000/038/Purple/df/24/ec/mzl.ktobakku.480x480-75.jpg",
83
+ "box-width" => 320
84
+ },
85
+ "image-type" => "screenshot",
86
+ "url" => "" }
87
+ ],
88
+ 'company' => {
89
+ 'url' => 'http://www.google.com',
90
+ 'title' => 'Google'
91
+ }
92
+ }
93
+ @app = AppStore::Application.new(:plist => @plist)
94
+ end
95
+
96
+ should "set price correctly on initialization from plist" do
97
+ assert_equal 42, @app.price
98
+ end
99
+
100
+ should "set size correctly on initialization from plist" do
101
+ assert_equal 101010, @app.size
102
+ end
103
+
104
+ should "set company correctly on initialization from plist" do
105
+ assert_equal 'http://www.google.com', @app.company.url
106
+ assert_equal 'Google', @app.company.title
107
+ end
108
+
109
+ should "have 5 artworks" do
110
+ assert_equal 5, @app.artworks.count
111
+ end
112
+
113
+ should "have a software icon" do
114
+ assert_not_nil @app.icon
115
+ assert_kind_of AppStore::Image, @app.icon
116
+ end
117
+
118
+ should "have 4 screenshots" do
119
+ assert_equal 4, @app.screenshots.count
120
+ end
121
+ end
122
+
123
+ context "fake calls to real AppStore using FakeMechanize for offline tests" do
124
+ setup do
125
+ @http_agent = FakeMechanize::Agent.new do |mock|
126
+ # Search for term "remote"
127
+ mock.get :uri => AppStore::Caller::SearchURL,
128
+ :parameters => {:media => 'software', :term => 'remote'},
129
+ :body => File.open("test/raw_answers/search_remote.txt").read
130
+
131
+ [284417350, 289616509, 316771002, 300719251].each do |app_id|
132
+ # Load all applications
133
+ mock.get :uri => AppStore::Caller::ApplicationURL,
134
+ :parameters => {:id => app_id},
135
+ :body => File.open("test/raw_answers/application_#{app_id}.txt").read
136
+
137
+ # Add an error catch for all non existing applications
138
+ mock.error :uri => AppStore::Caller::ApplicationURL,
139
+ :params_not_equal => {:id => app_id},
140
+ :body => File.open("test/raw_answers/application_not_found.txt").read
141
+
142
+ end
143
+ end
144
+
145
+ # Place the fake agent in the caller
146
+ AppStore::Caller.instance_variable_set "@agent", @http_agent
147
+ end
148
+
149
+ teardown do
150
+ # Remove fake agent
151
+ AppStore::Caller.instance_variable_set "@agent", nil
152
+ end
153
+
154
+ context "search for 'remote'" do
155
+ setup do
156
+ @list = AppStore::Application.search('remote')
157
+ end
158
+
159
+ should "call search url with search term in the http query" do
160
+ assert @http_agent.was_get?(AppStore::Caller::SearchURL,
161
+ :parameters => {:media => 'software', :term => 'remote'})
162
+ end
163
+
164
+ should "find 4 applications" do
165
+ assert_equal 4, @list.length
166
+ end
167
+
168
+ end
169
+
170
+ context "load application 316771002" do
171
+ setup do
172
+ @app = AppStore::Application.find_by_id(316771002)
173
+ end
174
+
175
+ should "should have 4 artworks" do
176
+ assert_equal 4, @app.artworks.count
177
+ end
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,66 @@
1
+ require "test_helper"
2
+
3
+ class ArtworkTest < Test::Unit::TestCase
4
+
5
+ context "test custom initializer with an emulated plist as a hash" do
6
+ setup do
7
+ @icon_plist = {
8
+ "default" => {
9
+ "box-height" => 57,
10
+ "url" => "http://a1.phobos.apple.com/us/r1000/058/Purple/c6/e0/62/mzl.eillqyke.png",
11
+ "box-width" => 57,
12
+ "needs-shine" => false
13
+ },
14
+ "image-type" => "software-icon",
15
+ "url" => ""
16
+ }
17
+
18
+ @screenshot_plist = {
19
+ "thumbnail" => {
20
+ "box-height" => 99,
21
+ "url" => "http://a1.phobos.apple.com/us/r1000/038/Purple/df/24/ec/mzl.ktobakku.148x99-75.jpg",
22
+ "box-width" => 148,
23
+ "needs-shine" => false
24
+ },
25
+ "default" => {
26
+ "box-height" => 480,
27
+ "url" => "http://a1.phobos.apple.com/us/r1000/038/Purple/df/24/ec/mzl.ktobakku.480x480-75.jpg",
28
+ "box-width" => 320
29
+ },
30
+ "image-type" => "screenshot",
31
+ "url" => ""
32
+ }
33
+
34
+ @icon = AppStore::Artwork.new(:plist => @icon_plist)
35
+ @screenshot = AppStore::Artwork.new(:plist => @screenshot_plist)
36
+ end
37
+
38
+ should "return true for is_icon? if it is an icon" do
39
+ assert @icon.is_icon?
40
+ end
41
+
42
+ should "return false for is_icon? if it is a screenshot (not an icon)" do
43
+ assert_equal false, @screenshot.is_icon?
44
+ end
45
+
46
+ should "set image-type through plist mapping" do
47
+ assert_equal @icon_plist['image-type'], @icon.image_type
48
+ assert_equal @screenshot_plist['image-type'], @screenshot.image_type
49
+ end
50
+
51
+ should "set default image for icon" do
52
+ assert_not_nil @icon.default
53
+ assert_kind_of AppStore::Image, @icon.default
54
+ end
55
+
56
+ should "set default image for screenshot" do
57
+ assert_not_nil @screenshot.default
58
+ assert_kind_of AppStore::Image, @screenshot.default
59
+ end
60
+
61
+ should "set thumbnail for screenshot" do
62
+ assert_not_nil @screenshot.default
63
+ assert_kind_of AppStore::Image, @screenshot.default
64
+ end
65
+ end
66
+ end
data/test/base_test.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "test_helper"
2
+
3
+ class BaseTest < Test::Unit::TestCase
4
+ should "store raw data from plist at initialization" do
5
+ base = AppStore::Dummy.new :plist => "plist instance"
6
+ assert_equal "plist instance", base.raw
7
+ end
8
+
9
+ should "call custom_init_from_plist with plist given at initialization if custom_init_from_plist is defined" do
10
+ # Define a custom_init_from_plist function which do something testable
11
+ class AppStore::Dummy
12
+ attr_reader :plist_stored_via_custom
13
+
14
+ def custom_init_from_plist(plist)
15
+ @plist_stored_via_custom = plist
16
+ end
17
+ end
18
+
19
+ dummy = AppStore::Dummy.new :plist => "plist object"
20
+
21
+ assert_equal "plist object", dummy.plist_stored_via_custom
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,15 @@
1
+ require "test_helper"
2
+
3
+ class CallerTest < Test::Unit::TestCase
4
+ def setup
5
+ AppStore::Caller.send(:public, *AppStore::Caller.protected_instance_methods)
6
+ end
7
+
8
+ should "returns a mechanize agent on call to agent" do
9
+ assert_kind_of WWW::Mechanize, AppStore::Caller.agent
10
+ end
11
+
12
+ should "set mechanize user agent to iTunes-iPhone/3.0 (2)" do
13
+ assert_equal 'iTunes-iPhone/3.0 (2)', AppStore::Caller.agent.user_agent
14
+ end
15
+ end
@@ -0,0 +1,60 @@
1
+ require "test_helper"
2
+
3
+ class ImageTest < Test::Unit::TestCase
4
+
5
+ context "test custom initializer with an emulated plist as a hash" do
6
+ setup do
7
+ @icon_plist = {
8
+ "box-height" => 57,
9
+ "url" => "http://a1.phobos.apple.com/us/r1000/058/Purple/c6/e0/62/mzl.eillqyke.png",
10
+ "box-width" => 57,
11
+ "needs-shine" => false
12
+ }
13
+
14
+ @default_screenshot_plist = {
15
+ "box-height" => 480,
16
+ "url" => "http://a1.phobos.apple.com/us/r1000/038/Purple/df/24/ec/mzl.ktobakku.480x480-75.jpg",
17
+ "box-width" => 320
18
+ }
19
+
20
+ @thumbnail_screenshot_plist = {
21
+ "box-height" => 99,
22
+ "url" => "http://a1.phobos.apple.com/us/r1000/038/Purple/df/24/ec/mzl.ktobakku.148x99-75.jpg",
23
+ "box-width" => 148,
24
+ "needs-shine" => false
25
+ }
26
+
27
+ @icon = AppStore::Image.new(:plist => @icon_plist)
28
+ @default_screenshot = AppStore::Image.new(:plist => @default_screenshot_plist)
29
+ @thumbnail_screenshot = AppStore::Image.new(:plist => @thumbnail_screenshot_plist)
30
+ end
31
+
32
+ should "have a box-height property correctly set through plist mapping" do
33
+ assert_equal @icon_plist['box-height'], @icon.height
34
+ assert_equal @default_screenshot_plist['box-height'], @default_screenshot.height
35
+ assert_equal @thumbnail_screenshot_plist['box-height'], @thumbnail_screenshot.height
36
+ end
37
+
38
+ should "have a box-width property correctly set through plist mapping" do
39
+ assert_equal @icon_plist['box-width'], @icon.width
40
+ assert_equal @default_screenshot_plist['box-width'], @default_screenshot.width
41
+ assert_equal @thumbnail_screenshot_plist['box-width'], @thumbnail_screenshot.width
42
+ end
43
+
44
+ should "have an url property correctly set through plist mapping" do
45
+ assert_equal @icon_plist['url'], @icon.url
46
+ assert_equal @default_screenshot_plist['url'], @default_screenshot.url
47
+ assert_equal @thumbnail_screenshot_plist['url'], @thumbnail_screenshot.url
48
+ end
49
+
50
+ should "have an optional needs-shine property" do
51
+ assert_equal @icon_plist['needs-shine'], @icon.needs_shine
52
+ assert_equal @thumbnail_screenshot_plist['needs-shine'], @thumbnail_screenshot.needs_shine
53
+ end
54
+
55
+ should "not fail if needs-shine was not provided" do
56
+ assert_nil @default_screenshot.needs_shine
57
+ end
58
+
59
+ end
60
+ end