dsander-reve 0.0.116

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/ChangeLog +155 -0
  2. data/LICENSE +22 -0
  3. data/Rakefile +79 -0
  4. data/init.rb +1 -0
  5. data/lib/reve/classes.rb +1341 -0
  6. data/lib/reve/exceptions.rb +353 -0
  7. data/lib/reve/extensions.rb +108 -0
  8. data/lib/reve.rb +1001 -0
  9. data/reve.rb +1 -0
  10. data/test/test_reve.rb +1191 -0
  11. data/test/xml/alliances.xml +171 -0
  12. data/test/xml/assets.xml +32 -0
  13. data/test/xml/badxml.xml +6 -0
  14. data/test/xml/certificate_tree.xml +231 -0
  15. data/test/xml/char_facwarstats.xml +18 -0
  16. data/test/xml/char_medals.xml +12 -0
  17. data/test/xml/character_sheet.xml +288 -0
  18. data/test/xml/characterid.xml +11 -0
  19. data/test/xml/charactername.xml +11 -0
  20. data/test/xml/characters.xml +13 -0
  21. data/test/xml/conqurable_stations.xml +12 -0
  22. data/test/xml/corp_facwarstats.xml +17 -0
  23. data/test/xml/corp_medals.xml +23 -0
  24. data/test/xml/corp_member_medals.xml +20 -0
  25. data/test/xml/corp_membersecurity.xml +49 -0
  26. data/test/xml/corporate_assets_list.xml +16 -0
  27. data/test/xml/corporate_market_orders.xml +10 -0
  28. data/test/xml/corporate_wallet_balance.xml +16 -0
  29. data/test/xml/corporate_wallet_journal.xml +11 -0
  30. data/test/xml/corporate_wallet_transactions.xml +10 -0
  31. data/test/xml/corporation_sheet.xml +52 -0
  32. data/test/xml/errors/error_100.xml +5 -0
  33. data/test/xml/errors/error_101.xml +5 -0
  34. data/test/xml/errors/error_102.xml +5 -0
  35. data/test/xml/errors/error_103.xml +5 -0
  36. data/test/xml/errors/error_104.xml +5 -0
  37. data/test/xml/errors/error_105.xml +5 -0
  38. data/test/xml/errors/error_106.xml +5 -0
  39. data/test/xml/errors/error_107.xml +5 -0
  40. data/test/xml/errors/error_108.xml +5 -0
  41. data/test/xml/errors/error_109.xml +5 -0
  42. data/test/xml/errors/error_110.xml +5 -0
  43. data/test/xml/errors/error_111.xml +5 -0
  44. data/test/xml/errors/error_112.xml +5 -0
  45. data/test/xml/errors/error_113.xml +5 -0
  46. data/test/xml/errors/error_114.xml +5 -0
  47. data/test/xml/errors/error_115.xml +5 -0
  48. data/test/xml/errors/error_116.xml +5 -0
  49. data/test/xml/errors/error_117.xml +5 -0
  50. data/test/xml/errors/error_118.xml +5 -0
  51. data/test/xml/errors/error_119.xml +5 -0
  52. data/test/xml/errors/error_120.xml +5 -0
  53. data/test/xml/errors/error_121.xml +5 -0
  54. data/test/xml/errors/error_122.xml +5 -0
  55. data/test/xml/errors/error_123.xml +5 -0
  56. data/test/xml/errors/error_124.xml +5 -0
  57. data/test/xml/errors/error_125.xml +5 -0
  58. data/test/xml/errors/error_200.xml +5 -0
  59. data/test/xml/errors/error_201.xml +5 -0
  60. data/test/xml/errors/error_202.xml +5 -0
  61. data/test/xml/errors/error_203.xml +5 -0
  62. data/test/xml/errors/error_204.xml +5 -0
  63. data/test/xml/errors/error_205.xml +5 -0
  64. data/test/xml/errors/error_206.xml +5 -0
  65. data/test/xml/errors/error_207.xml +5 -0
  66. data/test/xml/errors/error_208.xml +5 -0
  67. data/test/xml/errors/error_209.xml +5 -0
  68. data/test/xml/errors/error_210.xml +5 -0
  69. data/test/xml/errors/error_211.xml +5 -0
  70. data/test/xml/errors/error_212.xml +5 -0
  71. data/test/xml/errors/error_213.xml +5 -0
  72. data/test/xml/errors/error_214.xml +5 -0
  73. data/test/xml/errors/error_500.xml +5 -0
  74. data/test/xml/errors/error_501.xml +5 -0
  75. data/test/xml/errors/error_502.xml +5 -0
  76. data/test/xml/errors/error_503.xml +5 -0
  77. data/test/xml/errors/error_504.xml +5 -0
  78. data/test/xml/errors/error_505.xml +5 -0
  79. data/test/xml/errors/error_506.xml +5 -0
  80. data/test/xml/errors/error_507.xml +5 -0
  81. data/test/xml/errors/error_508.xml +5 -0
  82. data/test/xml/errors/error_509.xml +5 -0
  83. data/test/xml/errors/error_510.xml +5 -0
  84. data/test/xml/errors/error_511.xml +5 -0
  85. data/test/xml/errors/error_512.xml +5 -0
  86. data/test/xml/errors/error_513.xml +5 -0
  87. data/test/xml/errors/error_514.xml +5 -0
  88. data/test/xml/errors/error_515.xml +5 -0
  89. data/test/xml/errors/error_516.xml +5 -0
  90. data/test/xml/errors/error_517.xml +5 -0
  91. data/test/xml/errors/error_518.xml +5 -0
  92. data/test/xml/errors/error_519.xml +5 -0
  93. data/test/xml/errors/error_520.xml +5 -0
  94. data/test/xml/errors/error_521.xml +5 -0
  95. data/test/xml/errors/error_522.xml +5 -0
  96. data/test/xml/errors/error_523.xml +5 -0
  97. data/test/xml/errors/error_524.xml +5 -0
  98. data/test/xml/errors/error_525.xml +5 -0
  99. data/test/xml/errors/error_900.xml +5 -0
  100. data/test/xml/errors/error_901.xml +5 -0
  101. data/test/xml/errors/error_902.xml +5 -0
  102. data/test/xml/errors/error_903.xml +5 -0
  103. data/test/xml/errors/error_999.xml +5 -0
  104. data/test/xml/errors.xml +70 -0
  105. data/test/xml/eve_facwarstats.xml +35 -0
  106. data/test/xml/eve_facwartopstats.xml +178 -0
  107. data/test/xml/industryjobs.xml +11 -0
  108. data/test/xml/kills.xml +569 -0
  109. data/test/xml/map_facwarsystems.xml +13 -0
  110. data/test/xml/mapjumps.xml +15 -0
  111. data/test/xml/mapkills.xml +16 -0
  112. data/test/xml/market_transactions.xml +79 -0
  113. data/test/xml/marketorders.xml +43 -0
  114. data/test/xml/member_tracking.xml +22 -0
  115. data/test/xml/nonmember_corpsheet.xml +30 -0
  116. data/test/xml/reftypes.xml +14 -0
  117. data/test/xml/server_status.xml +9 -0
  118. data/test/xml/skill_in_training-amarr-titan.xml +15 -0
  119. data/test/xml/skill_in_training-none.xml +7 -0
  120. data/test/xml/skill_queue.xml +18 -0
  121. data/test/xml/skilltree.xml +41 -0
  122. data/test/xml/sovereignty.xml +29 -0
  123. data/test/xml/starbase_fuel.xml +23 -0
  124. data/test/xml/starbases.xml +12 -0
  125. data/test/xml/wallet_balance.xml +17 -0
  126. data/test/xml/wallet_journal.xml +48 -0
  127. data/tester.rb +17 -0
  128. metadata +187 -0
data/test/test_reve.rb ADDED
@@ -0,0 +1,1191 @@
1
+ require 'test/unit'
2
+ require '../lib/reve'
3
+ require 'fileutils' # for saving downloaded XML
4
+
5
+ XML_BASE = File.join(File.dirname(__FILE__),'xml/')
6
+ SAVE_PATH = File.join(File.dirname(__FILE__),'downloads')
7
+
8
+ class TestReve < Test::Unit::TestCase
9
+
10
+ def setup
11
+ @api = get_api
12
+ assert_nil @api.last_hash
13
+ FileUtils.mkdir(SAVE_PATH) rescue nil
14
+ end
15
+ def teardown
16
+ FileUtils.rm_rf(SAVE_PATH)
17
+ end
18
+
19
+ def test_makes_right_api_empty
20
+ api = get_api
21
+ assert_instance_of Reve::API, api
22
+ assert_equal "", api.userid
23
+ assert_equal "", api.key
24
+ assert_equal "", api.charid
25
+ end
26
+ def test_makes_right_api_1_param
27
+ api = get_api(12345)
28
+ assert_instance_of Reve::API, api
29
+ assert_equal "12345", api.userid
30
+ assert_equal "", api.key
31
+ assert_equal "", api.charid
32
+ end
33
+ def test_makes_right_api_2_param
34
+ api = get_api(12345,54321)
35
+ assert_instance_of Reve::API, api
36
+ assert_equal "12345", api.userid
37
+ assert_equal "54321", api.key
38
+ assert_equal "", api.charid
39
+ end
40
+ def test_makes_right_api_3_param
41
+ api = get_api(12345,54321,'abcde')
42
+ assert_instance_of Reve::API, api
43
+ assert_equal "12345", api.userid
44
+ assert_equal "54321", api.key
45
+ assert_equal "abcde", api.charid
46
+ end
47
+
48
+ def test_makes_a_simple_hash
49
+ Reve::API.alliances_url = XML_BASE + 'alliances.xml'
50
+ h = @api.alliances :just_hash => true
51
+ assert_instance_of String, h
52
+ assert_equal "xml/alliances.xml", h
53
+ end
54
+
55
+ def test_charid_default_works_when_characterid_is_nil
56
+ # this line of code is wrong on so many levels.
57
+ assert_equal("CharID", Reve::API.new('uid','key','CharID').send(:postfields,{})['characterid'])
58
+ end
59
+
60
+ def test_makes_a_complex_hash
61
+ Reve::API.corporate_wallet_trans_url = XML_BASE + 'market_transactions.xml'
62
+ @api.userid = 999
63
+ @api.key = 'aaa'
64
+ h = @api.corporate_wallet_transactions :accountkey => '1001', :characterid => 123, :beforerefid => 456, :just_hash => true
65
+ assert_instance_of String, h
66
+ assert_equal 'xml/market_transactions.xml:accountkey:1001:apikey:aaa:beforerefid:456:characterid:123:userid:999',h
67
+ end
68
+
69
+ def test_bad_xml
70
+ Reve::API.training_skill_url = XML_BASE + 'badxml.xml'
71
+ skill = @api.skill_in_training
72
+ assert_not_nil @api.last_hash
73
+ end
74
+
75
+ def test_saving_xml_works
76
+ @api.save_path = SAVE_PATH
77
+ alliances = @api.alliances :url => File.join(XML_BASE,'alliances.xml')
78
+ assert File.exists?(File.join(SAVE_PATH,'alliances',@api.cached_until.to_i.to_s + '.xml'))
79
+ assert_equal(
80
+ File.open(File.join(XML_BASE,'alliances.xml')).read,
81
+ File.open(File.join(SAVE_PATH,'alliances',@api.cached_until.to_i.to_s + '.xml')).read)
82
+ end
83
+
84
+ def test_saving_xml_when_save_path_is_nil
85
+ assert_nil @api.save_path
86
+ alliances = @api.alliances :url => File.join(XML_BASE,'alliances.xml')
87
+ assert ! File.exists?(File.join(SAVE_PATH,'alliances',@api.cached_until.to_i.to_s + '.xml'))
88
+ end
89
+
90
+ # We want to see <url /> in the saved XML because that's what came from the source
91
+ def test_saving_xml_with_bad_short_tag
92
+ @api.save_path = SAVE_PATH
93
+ @corpsheet = @api.corporation_sheet :url => File.join(XML_BASE,'corporation_sheet.xml')
94
+ assert_equal "", @corpsheet.url
95
+ assert File.open(File.join(SAVE_PATH,'corporation_sheet',@api.cached_until.to_i.to_s + '.xml')).read.include?("<url />")
96
+ end
97
+
98
+ def test_saving_xml_when_404
99
+ @api.save_path = SAVE_PATH
100
+ alliances = nil
101
+ assert_raise Errno::ENOENT do
102
+ alliances = @api.alliances :url => File.join(XML_BASE,rand.to_s)
103
+ end
104
+ assert_nil @api.cached_until
105
+ assert_equal 0, Dir.glob(File.join(SAVE_PATH,'alliances','*.xml')).size # no XML saved
106
+ end
107
+
108
+ # File.split exists and File is not a String or URI class as permitted in Reve::API#get_xml.
109
+ # This means as a parameter it will pass through Reve::API#compute_hash method and
110
+ # get to Reve::API#get_xml
111
+ def test_for_bad_uri_passed_to_method
112
+ assert_raise Reve::Exceptions::ReveNetworkStatusException do
113
+ @api.character_sheet :url => File
114
+ end
115
+ end
116
+
117
+ def test_check_exception_with_bad_xml_document
118
+ assert_raise ArgumentError do
119
+ @api.send(:check_exception,nil)
120
+ end
121
+ end
122
+
123
+ def test_errors_api_call
124
+ errors = nil
125
+ assert_nothing_raised do
126
+ errors = @api.errors :url => File.join(XML_BASE,'errors.xml')
127
+ end
128
+ assert errors.all? { |e| e.kind_of?(Reve::Classes::APIError) }
129
+ assert_equal 61, errors.size # 61 errors in total
130
+ errors.each do |error|
131
+ assert_not_nil(error.code)
132
+ assert_not_nil(error.text)
133
+ end
134
+ end
135
+
136
+ def test_corporation_sheet_clean
137
+ Reve::API.corporation_sheet_url = XML_BASE + 'corporation_sheet.xml'
138
+ corporation = nil
139
+ assert_nothing_raised do
140
+ corporation = @api.corporation_sheet :characterid => 123
141
+ end
142
+ assert_not_nil @api.last_hash
143
+ assert_kind_of Time, @api.cached_until
144
+ assert_equal 150212025, corporation.id
145
+ assert_equal "Banana Republic", corporation.name
146
+ assert_equal "BR", corporation.ticker
147
+ assert_equal(150208955, corporation.ceo_id)
148
+ assert_equal("Mark Roled", corporation.ceo_name)
149
+ assert_equal(60003469, corporation.station_id)
150
+ assert_equal("Jita IV - Caldari Business Tribunal Information Center", corporation.station_name)
151
+ assert_equal "Garth's testing corp of awesome sauce, win sauce as it were. In this corp...<br><br>IT HAPPENS ALL OVER", corporation.description
152
+ assert_equal("", corporation.url)
153
+ assert_equal(150430947, corporation.alliance_id)
154
+ assert_equal("The Dead Rabbits", corporation.alliance_name)
155
+ assert_equal 93.7, corporation.tax_rate
156
+ assert_equal(3, corporation.member_count)
157
+ assert_equal(6300, corporation.member_limit)
158
+ assert_equal(1, corporation.shares)
159
+ assert_equal "DIVISION", corporation.divisions.select { |d| d.key == 1003 }.first.description
160
+ corporation.divisions.each do |d|
161
+ assert_not_nil(d.key)
162
+ assert_not_nil(d.description)
163
+ end
164
+ assert_equal "Master Wallet", corporation.wallet_divisions.select { |d| d.key == 1000 }.first.description
165
+ corporation.wallet_divisions.each do |wd|
166
+ assert_not_nil(wd.key)
167
+ assert_not_nil(wd.description)
168
+ end
169
+ assert_equal 0, corporation.logo.graphic_id
170
+ assert_equal 681, corporation.logo.color_1
171
+ assert_equal 676, corporation.logo.color_2
172
+ assert_equal 448, corporation.logo.shape_1
173
+ assert_equal 418, corporation.logo.shape_3
174
+ assert_equal 0, corporation.logo.color_3
175
+ assert_equal 0, corporation.logo.shape_2
176
+ end
177
+
178
+ def test_conqurable_stations_clean
179
+ Reve::API.conqurable_outposts_url = XML_BASE + 'conqurable_stations.xml'
180
+ stations = nil
181
+ assert_nothing_raised do
182
+ stations = @api.conqurable_stations
183
+ end
184
+
185
+ assert_equal 3, stations.size
186
+ assert_not_nil @api.last_hash
187
+ assert_kind_of Time, @api.cached_until
188
+
189
+ stations.each do |station|
190
+ assert_not_nil station.id
191
+ assert_not_nil station.name
192
+ assert_not_nil station.type_id
193
+ assert_not_nil station.system_id
194
+ assert_not_nil station.corporation_id
195
+ assert_not_nil station.corporation_name
196
+ assert_not_nil station.system_id
197
+ end
198
+ end
199
+
200
+ def test_convert_characterids_to_names
201
+ ids = [ 797400947,892008733 ] # CCP Garthagk, Raquel Smith
202
+ names = []
203
+ assert_nothing_raised do
204
+ names = @api.character_name :url => XML_BASE + 'charactername.xml', :ids => ids
205
+ end
206
+ assert_equal 2, names.size
207
+ names.each do |name|
208
+ assert_not_nil(name.name)
209
+ assert_not_nil(name.id)
210
+ end
211
+ actual_names = names.collect { |n| n.name }
212
+ assert actual_names.include?('CCP Garthagk')
213
+ assert actual_names.include?('Raquel Smith')
214
+ end
215
+
216
+ def test_convert_characternames_to_ids
217
+ names = [ 'CCP Garthagk', 'Raquel Smith' ] # 797400947,892008733
218
+ ids = []
219
+ assert_nothing_raised do
220
+ ids = @api.names_to_ids :url => XML_BASE + 'characterid.xml', :names => names
221
+ end
222
+ assert_equal 2, ids.size
223
+ ids.each do |id|
224
+ assert_not_nil(id.id)
225
+ assert_not_nil(id.name)
226
+ end
227
+ actual_ids = ids.collect { |n| n.id }
228
+ assert actual_ids.include?(797400947)
229
+ assert actual_ids.include?(892008733)
230
+ end
231
+
232
+ def test_personal_industry_jobs_clean
233
+ Reve::API.personal_industry_jobs_url = XML_BASE + 'industryjobs.xml'
234
+ jobs = nil
235
+ assert_nothing_raised do
236
+ jobs = @api.personal_industry_jobs
237
+ end
238
+ assert_equal 2, jobs.size
239
+ # All things got assigned something.
240
+ jobs.each do |job|
241
+ [ :id, :assembly_line_id, :container_id, :installed_item_id, :installed_item_location_id,
242
+ :installed_item_quantity, :installed_item_productivity_level, :installed_item_material_level,
243
+ :installed_item_licensed_production_runs_remaining, :output_location_id, :installer_id, :runs,
244
+ :licensed_production_runs, :installed_system_id, :container_location_id, :material_multiplier,
245
+ :char_material_multiplier, :time_multiplier, :char_time_multiplier, :installed_item_type_id,
246
+ :output_type_id, :container_type_id, :installed_item_copy, :completed, :completed_successfully,
247
+ :installed_item_flag, :output_flag, :activity_id, :completed_status, :installed_at,
248
+ :begin_production_at, :end_production_at, :pause_production_time ].each do |att|
249
+ assert_not_nil job.send(att)
250
+ end
251
+ end
252
+ end
253
+
254
+ def test_corporate_industry_jobs_clean
255
+ Reve::API.corporate_industry_jobs_url = XML_BASE + 'industryjobs.xml'
256
+ jobs = nil
257
+ assert_nothing_raised do
258
+ jobs = @api.corporate_industry_jobs
259
+ end
260
+ assert_equal 2, jobs.size
261
+ # All things got assigned something.
262
+ jobs.each do |job|
263
+ [ :id, :assembly_line_id, :container_id, :installed_item_id, :installed_item_location_id,
264
+ :installed_item_quantity, :installed_item_productivity_level, :installed_item_material_level,
265
+ :installed_item_licensed_production_runs_remaining, :output_location_id, :installer_id, :runs,
266
+ :licensed_production_runs, :installed_system_id, :container_location_id, :material_multiplier,
267
+ :char_material_multiplier, :time_multiplier, :char_time_multiplier, :installed_item_type_id,
268
+ :output_type_id, :container_type_id, :installed_item_copy, :completed, :completed_successfully,
269
+ :installed_item_flag, :output_flag, :activity_id, :completed_status, :installed_at,
270
+ :begin_production_at, :end_production_at, :pause_production_time ].each do |att|
271
+ assert_not_nil job.send(att)
272
+ end
273
+ end
274
+ end
275
+
276
+ def test_faction_war_system_stats_clean(skip_preamble = false,stats = nil)
277
+ Reve::API.faction_war_occupancy_url = XML_BASE + 'map_facwarsystems.xml'
278
+ unless skip_preamble # not best practice but will get the job done!
279
+ stats = nil
280
+ assert_nothing_raised do
281
+ stats = @api.faction_war_system_stats
282
+ end
283
+ end
284
+ assert stats.all? { |s| s.kind_of?(Reve::Classes::FactionWarSystemStatus) }
285
+ assert_equal(4, stats.size)
286
+ stats.each do |sys|
287
+ # can't assert_not_nil faction_id or faction_name since they may be nil
288
+ assert_not_nil(sys.system_id)
289
+ assert_not_nil(sys.system_name)
290
+ assert_not_nil(sys.contested)
291
+ end
292
+ assert_equal(1, stats.select { |s| s.faction_id == 500001 }.size)
293
+ assert_equal(1, stats.select { |s| s.faction_id == 500002 }.size)
294
+ assert_equal(1, stats.select { |s| ! s.contested }.size)
295
+ assert_equal(2, stats.select { |s| s.faction_id.nil? }.size)
296
+ assert_equal(3, stats.select { |s| s.contested }.size)
297
+ end
298
+
299
+ def test_faction_war_system_stats_alias_clean
300
+ Reve::API.faction_war_occupancy_url = XML_BASE + 'map_facwarsystems.xml'
301
+ stats = nil
302
+ assert_nothing_raised do
303
+ stats = @api.faction_war_occupancy
304
+ end
305
+ test_faction_war_system_stats_clean(true,stats)
306
+ end
307
+
308
+ def test_faction_war_stats_clean
309
+ Reve::API.general_faction_war_stats_url = XML_BASE + 'eve_facwarstats.xml'
310
+ stats = nil
311
+ assert_nothing_raised do
312
+ stats = @api.faction_war_stats
313
+ end
314
+ assert_instance_of(Reve::Classes::EveFactionWarStat, stats)
315
+ assert_equal(1707, stats.kills_yesterday)
316
+ assert_equal(9737, stats.kills_last_week)
317
+ assert_equal(27866, stats.kills_total)
318
+ assert_equal(215674, stats.victory_points_yesterday)
319
+ assert_equal(1738351, stats.victory_points_last_week)
320
+ assert_equal(5613787, stats.victory_points_total)
321
+
322
+ assert stats.faction_wars.all? { |w| w.kind_of?(Reve::Classes::FactionWar) }
323
+ assert stats.faction_participants.all? { |w| w.kind_of?(Reve::Classes::FactionwideFactionWarParticpant) }
324
+ assert_equal(8, stats.faction_wars.size)
325
+ assert_equal(4, stats.faction_participants.size)
326
+ stats.faction_wars.each do |war|
327
+ assert_not_nil(war.faction_id)
328
+ assert_not_nil(war.faction_name)
329
+ assert_not_nil(war.against_id)
330
+ assert_not_nil(war.against_name)
331
+ end
332
+ stats.faction_participants.each do |participant|
333
+ assert_not_nil(participant.faction_id)
334
+ assert_not_nil(participant.faction_name)
335
+ assert_not_nil(participant.systems_controlled)
336
+ assert_not_nil(participant.kills_yesterday)
337
+ assert_not_nil(participant.kills_last_week)
338
+ assert_not_nil(participant.kills_total)
339
+ assert_not_nil(participant.victory_points_yesterday)
340
+ assert_not_nil(participant.victory_points_last_week)
341
+ assert_not_nil(participant.victory_points_total)
342
+ end
343
+ assert_not_nil(@api.cached_until)
344
+ end
345
+ def test_personal_factional_war_stats_clean
346
+ Reve::API.personal_faction_war_stats_url = XML_BASE + 'char_facwarstats.xml'
347
+ stats = nil
348
+ assert_nothing_raised do
349
+ stats = @api.personal_faction_war_stats
350
+ end
351
+ assert_instance_of Reve::Classes::PersonalFactionWarParticpant, stats
352
+ assert_equal(500001, stats.faction_id)
353
+ assert_equal("Caldari State", stats.faction_name)
354
+ assert_equal("2008-06-13 20:38:00".to_time, stats.enlisted_at)
355
+ assert_equal(1, stats.current_rank)
356
+ assert_equal(2, stats.highest_rank)
357
+ assert_equal(3, stats.kills_yesterday)
358
+ assert_equal(4, stats.kills_last_week)
359
+ assert_equal(5, stats.kills_total)
360
+ assert_equal(124, stats.victory_points_yesterday)
361
+ assert_equal(124, stats.victory_points_last_week)
362
+ assert_equal(506, stats.victory_points_total)
363
+ end
364
+
365
+ def test_corporate_factional_war_stats_clean
366
+ Reve::API.corporate_faction_war_stats_url = XML_BASE + 'corp_facwarstats.xml'
367
+ stats = nil
368
+ assert_nothing_raised do
369
+ stats = @api.corporate_faction_war_stats
370
+ end
371
+ assert_instance_of Reve::Classes::CorporateFactionWarParticpant, stats
372
+ assert_equal(500001, stats.faction_id)
373
+ assert_equal("Caldari State", stats.faction_name)
374
+ assert_equal("2008-06-10 22:10:00".to_time, stats.enlisted_at)
375
+ assert_equal(4, stats.pilots)
376
+ assert_equal(3, stats.kills_yesterday)
377
+ assert_equal(4, stats.kills_last_week)
378
+ assert_equal(5, stats.kills_total)
379
+ assert_equal(124, stats.victory_points_yesterday)
380
+ assert_equal(906, stats.victory_points_last_week)
381
+ assert_equal(2690, stats.victory_points_total)
382
+ end
383
+
384
+ def test_faction_war_top_stats_clean
385
+ Reve::API.top_faction_war_stats_url = XML_BASE + 'eve_facwartopstats.xml'
386
+ stats = nil
387
+ assert_nothing_raised do
388
+ stats = @api.faction_war_top_stats
389
+ end
390
+ assert_kind_of(Reve::Classes::FactionWarTopStats, stats)
391
+ [ :characters, :corporations, :factions ].each do |kind|
392
+ [ :yesterday_kills, :last_week_kills, :total_kills ].each do |attr|
393
+ assert_kind_of(Hash, stats.send(kind))
394
+ assert_kind_of(Array, stats.send(kind)[attr])
395
+ assert ! stats.send(kind)[attr].empty?
396
+ [ :name, :id, :kills ].each do |c_attr|
397
+ assert stats.send(kind)[attr].all? { |e| ! e.nil? }
398
+ end
399
+ end
400
+ [ :last_week_victory_points, :yesterday_victory_points, :total_victory_points ].each do |attr|
401
+ assert_kind_of(Hash, stats.send(kind))
402
+ assert_kind_of(Array, stats.send(kind)[attr])
403
+ assert ! stats.send(kind)[attr].empty?
404
+ [ :name, :id, :victory_points ].each do |c_attr|
405
+ assert stats.send(kind)[attr].all? { |e| ! e.nil? }
406
+ end
407
+ end
408
+ end
409
+ assert_equal(5, stats.characters[:yesterday_kills].size)
410
+ assert_equal(6, stats.characters[:last_week_kills].size)
411
+ assert_equal(7, stats.characters[:total_kills].size)
412
+ [ :yesterday_kills, :yesterday_victory_points, :last_week_kills,
413
+ :last_week_victory_points, :total_kills, :total_victory_points ].each do |attr|
414
+ assert_equal(10,stats.corporations[attr].size)
415
+ end
416
+ [ :yesterday_kills, :yesterday_victory_points, :last_week_kills,
417
+ :last_week_victory_points, :total_kills, :total_victory_points ].each do |attr|
418
+ assert_equal(4,stats.factions[attr].size)
419
+ end
420
+ end
421
+
422
+ def test_assets_clean
423
+ Reve::API.personal_assets_url = XML_BASE + 'assets.xml'
424
+ assets = nil
425
+ assert_nothing_raised do
426
+ assets = @api.personal_assets_list
427
+ end
428
+ assert_equal 18, assets.size # 18 single and 1 container
429
+ contained_assets = assets.inject([]) { |ass,container| ass << container.assets }.flatten
430
+ assert_equal(1, contained_assets.size) # We have a container it happens to have 1 asset in it
431
+ contained_assets.each do |asset|
432
+ assert_instance_of(Reve::Classes::Asset, asset)
433
+ assert_not_nil(asset.item_id)
434
+ assert_not_nil(asset.type_id)
435
+ assert_not_nil(asset.quantity)
436
+ assert_not_nil(asset.flag)
437
+ assert_not_nil(asset.singleton)
438
+ end
439
+ assets.each do |asset|
440
+ assert_instance_of(Reve::Classes::AssetContainer, asset)
441
+ assert_not_nil(asset.item_id)
442
+ assert_not_nil(asset.location_id)
443
+ assert_not_nil(asset.type_id)
444
+ assert_not_nil(asset.quantity)
445
+ assert_not_nil(asset.flag)
446
+ assert_not_nil(asset.singleton)
447
+ end
448
+ end
449
+
450
+ # no need to test corporate cos they're the same.
451
+ # TODO: Test with nested losses
452
+ def test_kills_clean
453
+ kills_cleanly(:personal_kills,File.join(XML_BASE,'kills.xml'))
454
+ end
455
+
456
+ def test_corporate_kills_clean
457
+ kills_cleanly(:corporate_kills,File.join(XML_BASE,'kills.xml'))
458
+ end
459
+
460
+ def test_characters_clean
461
+ Reve::API.characters_url = XML_BASE + 'characters.xml'
462
+ chars = nil
463
+ assert_nothing_raised do
464
+ chars = @api.characters
465
+ end
466
+ assert_not_nil @api.last_hash
467
+ assert_kind_of Time, @api.cached_until
468
+ assert_equal 1, chars.size
469
+ chars.each do |char|
470
+ assert_not_nil(char.name)
471
+ assert_not_nil(char.id)
472
+ assert_not_nil(char.corporation_name)
473
+ assert_not_nil(char.corporation_id)
474
+ assert_instance_of Reve::Classes::Character, char
475
+ end
476
+ end
477
+
478
+ def test_starbases_clean
479
+ Reve::API.starbases_url = XML_BASE + 'starbases.xml'
480
+ bases = nil
481
+ assert_nothing_raised do
482
+ bases = @api.starbases(:characterid => 1)
483
+ end
484
+ assert_not_nil @api.last_hash
485
+ assert_kind_of Time, @api.cached_until
486
+ assert_equal 4, bases.size
487
+ bases.each do |starbase|
488
+ assert_instance_of Reve::Classes::Starbase, starbase
489
+ assert_not_nil starbase.type_id
490
+ assert_not_nil starbase.type_name
491
+ assert_not_nil starbase.id
492
+ assert_not_nil starbase.system_id
493
+ assert_not_nil starbase.system_name
494
+ end
495
+ end
496
+
497
+ def test_starbase_fuel_clean
498
+ Reve::API.starbasedetail_url = XML_BASE + 'starbase_fuel.xml'
499
+ fuels = nil
500
+ assert_nothing_raised do
501
+ fuels = @api.starbase_fuel(:starbaseid => 1,:characterid => 2)
502
+ end
503
+ assert_not_nil @api.last_hash
504
+ assert_kind_of Time, @api.cached_until
505
+ assert_equal 14, fuels.size
506
+ fuels.each do |fuel|
507
+ assert_equal 1, fuel.starbase_id
508
+ assert_not_nil fuel.type_id
509
+ assert_not_nil fuel.quantity
510
+ end
511
+ end
512
+
513
+ def test_alliances_clean
514
+ Reve::API.alliances_url = XML_BASE + 'alliances.xml'
515
+ alliances = nil
516
+ assert_nothing_raised do
517
+ alliances = @api.alliances
518
+ end
519
+ assert_not_nil @api.last_hash
520
+ assert_kind_of Time, @api.cached_until
521
+ assert_equal 3, alliances.size
522
+ corpsize = 0
523
+ alliances.each do |alliance|
524
+ assert_instance_of Reve::Classes::Alliance, alliance
525
+ assert_not_equal 0, alliance.member_corporations
526
+ assert_not_nil alliance.name
527
+ assert_not_nil alliance.id
528
+ assert_not_nil alliance.short_name
529
+ assert_not_nil alliance.member_count
530
+ assert_not_nil alliance.executor_corp_id
531
+ corpsize += alliance.member_corporations.size
532
+ end
533
+ assert_equal 150, corpsize
534
+ end
535
+
536
+ def test_sovereignty_clean
537
+ Reve::API.sovereignty_url = XML_BASE + 'sovereignty.xml'
538
+ sovereignties = nil
539
+ assert_nothing_raised do
540
+ sovereignties = @api.sovereignty
541
+ end
542
+ assert_not_nil @api.last_hash
543
+ assert_kind_of Time, @api.cached_until
544
+ assert_equal 7, sovereignties.size
545
+ sovereignties.each do |sovereignty|
546
+ assert_instance_of Reve::Classes::Sovereignty, sovereignty
547
+ assert_not_nil sovereignty.system_id
548
+ assert_not_nil sovereignty.constellation_sovereignty
549
+ assert_not_nil sovereignty.system_name
550
+ end
551
+ end
552
+
553
+ def test_reftypes_clean
554
+ Reve::API.reftypes_url = XML_BASE + 'reftypes.xml'
555
+ reftypes = nil
556
+ assert_nothing_raised do
557
+ reftypes = @api.ref_types
558
+ end
559
+ assert_not_nil @api.last_hash
560
+ assert_kind_of Time, @api.cached_until
561
+ assert_equal 6, reftypes.size
562
+ reftypes.each do |reftype|
563
+ assert_not_nil reftype.id
564
+ assert_not_nil reftype.name
565
+ end
566
+ end
567
+
568
+ def test_market_orders_clean
569
+ Reve::API.personal_market_orders_url = XML_BASE + 'marketorders.xml'
570
+ orders = nil
571
+ assert_nothing_raised do
572
+ orders = @api.personal_market_orders
573
+ end
574
+ assert_not_nil @api.last_hash
575
+ assert_kind_of Time, @api.cached_until
576
+ assert_equal 11, orders.size
577
+ buys = sells = 0
578
+ orders.each do |order|
579
+ [ :id, :character_id, :station_id, :volume_entered, :volume_remaining, :minimum_volume,
580
+ :order_state, :type_id, :range, :account_key, :duration, :escrow, :price, :bid ].each do |attr|
581
+ assert_not_nil(order.send(attr))
582
+ end
583
+ assert_kind_of Time, order.created_at
584
+ assert [TrueClass, FalseClass].include?(order.bid.class)
585
+ buys += 1 if ! order.bid
586
+ sells += 1 if order.bid
587
+ assert_not_equal(0, order.character_id)
588
+ end
589
+ assert_equal 4, buys
590
+ assert_equal 7, sells
591
+ end
592
+
593
+ def test_corporate_market_orders_clean
594
+ orders = nil
595
+ assert_nothing_raised do
596
+ orders = @api.corporate_market_orders :url => File.join(XML_BASE,'corporate_market_orders.xml')
597
+ end
598
+ assert_not_nil @api.last_hash
599
+ assert_kind_of Time, @api.cached_until
600
+ assert_equal 1, orders.size
601
+ buys = sells = 0
602
+ orders.each do |order|
603
+ [ :id, :character_id, :station_id, :volume_entered, :volume_remaining, :minimum_volume,
604
+ :order_state, :type_id, :range, :account_key, :duration, :escrow, :price, :bid ].each do |attr|
605
+ assert_not_nil(order.send(attr))
606
+ end
607
+ assert_kind_of Time, order.created_at
608
+ assert [TrueClass, FalseClass].include?(order.bid.class)
609
+ buys += 1 if ! order.bid
610
+ sells += 1 if order.bid
611
+ end
612
+ assert_equal 1, buys
613
+ assert_equal 0, sells
614
+ end
615
+
616
+ def test_corporate_wallet_transactions
617
+ trans = nil
618
+ assert_nothing_raised do
619
+ trans = @api.corporate_wallet_transactions :url => File.join(XML_BASE,'corporate_wallet_transactions.xml')
620
+ end
621
+ assert_equal 1, trans.size
622
+ assert trans.all? { |tran| tran.kind_of?(Reve::Classes::CorporateWalletTransaction) }
623
+ trans.each do |tran|
624
+ [ :created_at, :id, :quantity, :type_name, :type_id, :price,
625
+ :client_id, :client_name, :character_id, :station_id, :station_name, :type,
626
+ :transaction_for ].each do |attr|
627
+ assert_not_nil(tran.send(attr))
628
+ end
629
+ assert_instance_of(Time, tran.created_at)
630
+ end
631
+ end
632
+
633
+ def test_corporate_wallet_balance_clean
634
+ balance = nil
635
+ assert_nothing_raised do
636
+ balance = @api.corporate_wallet_balance :url => File.join(XML_BASE, 'corporate_wallet_balance.xml')
637
+ end
638
+ assert balance.all? { |b| b.kind_of?(Reve::Classes::WalletBalance) }
639
+ balance.each do |bal|
640
+ assert_not_nil(bal.account_id)
641
+ assert_not_nil(bal.account_key)
642
+ assert_not_nil(bal.balance)
643
+ end
644
+ assert_equal 18004409.84, balance.select { |b| b.account_key == '1000' }.first.balance
645
+ balance.select { |b| b.account_key != '1000' }.each do |non_tested_account|
646
+ assert_equal 0.00, non_tested_account.balance
647
+ end
648
+ end
649
+
650
+ def test_corporate_wallet_journal_clean
651
+ journal = nil
652
+ assert_nothing_raised do
653
+ journal = @api.corporate_wallet_journal :url => File.join(XML_BASE,'corporate_wallet_journal.xml')
654
+ end
655
+ assert_equal 2, journal.size
656
+ assert journal.all? { |j| j.kind_of?(Reve::Classes::WalletJournal) }
657
+ journal.each do |j|
658
+ [ :date, :ref_id, :reftype_id, :owner_name1, :owner_name2, :arg_name1, :amount, :balance, :reason ].each do |attr|
659
+ assert_not_nil(j.send(attr))
660
+ end
661
+ end
662
+ end
663
+
664
+ def test_corporate_assets_list_clean
665
+ assets = nil
666
+ assert_nothing_raised do
667
+ assets = @api.corporate_assets_list :url => File.join(XML_BASE,'corporate_assets_list.xml')
668
+ end
669
+ assert_equal 2, assets.size
670
+ assert assets.all? { |a| a.kind_of?(Reve::Classes::AssetContainer) }
671
+ end
672
+
673
+ def test_map_jumps_clean
674
+ Reve::API.map_jumps_url = XML_BASE + 'mapjumps.xml'
675
+ mapjumps = nil
676
+ assert_nothing_raised do
677
+ mapjumps = @api.map_jumps
678
+ end
679
+ assert_not_nil @api.last_hash
680
+ assert_kind_of Time, @api.cached_until
681
+ assert_equal 5, mapjumps.size
682
+ mapjumps.each do |jump|
683
+ assert_not_nil jump.system_id
684
+ assert_not_nil jump.jumps
685
+ end
686
+ end
687
+
688
+ def test_map_kills_clean
689
+ Reve::API.map_kills_url = XML_BASE + 'mapkills.xml'
690
+ mapkills = nil
691
+ assert_nothing_raised do
692
+ mapkills = @api.map_kills
693
+ end
694
+ assert_not_nil @api.last_hash
695
+ assert_kind_of Time, @api.cached_until
696
+ assert_equal 4, mapkills.size
697
+ mapkills.each do |kill|
698
+ assert_not_nil kill.system_id
699
+ assert_not_nil kill.faction_kills
700
+ assert_not_nil kill.ship_kills
701
+ assert_not_nil kill.pod_kills
702
+ end
703
+ end
704
+
705
+ def test_skill_tree_clean
706
+ Reve::API.skill_tree_url = XML_BASE + 'skilltree.xml'
707
+ skilltrees = nil
708
+ assert_nothing_raised do
709
+ skilltrees = @api.skill_tree
710
+ end
711
+ assert_not_nil @api.last_hash
712
+ assert_kind_of Time, @api.cached_until
713
+ assert_equal 2, skilltrees.size
714
+ skilltrees.each do |skill|
715
+ assert_not_nil skill.type_id
716
+ assert_not_nil skill.name
717
+ assert_not_nil skill.rank
718
+ assert_not_nil skill.description
719
+ skill.bonuses.each do |bonus|
720
+ assert_kind_of Reve::Classes::SkillBonus, bonus
721
+ end
722
+ skill.attribs.each do |attrib|
723
+ assert_kind_of Reve::Classes::RequiredAttribute, attrib
724
+ end
725
+ skill.required_skills.each do |req|
726
+ assert_kind_of Reve::Classes::SkillRequirement, req
727
+ end
728
+ end
729
+ end
730
+
731
+ def test_wallet_balance_clean
732
+ Reve::API.personal_wallet_balance_url = XML_BASE + 'wallet_balance.xml'
733
+ balance = nil
734
+ assert_nothing_raised do
735
+ balance = @api.personal_wallet_balance(:characterid => 1)
736
+ end
737
+ assert_not_nil @api.last_hash
738
+ assert_kind_of Time, @api.cached_until
739
+ assert_equal 7, balance.size
740
+ balance.each do |bal|
741
+ assert_not_nil bal.account_id
742
+ assert_not_nil bal.account_key
743
+ assert_not_nil bal.balance
744
+ end
745
+ end
746
+
747
+ def test_wallet_transactions_clean
748
+ Reve::API.personal_wallet_trans_url = XML_BASE + 'market_transactions.xml'
749
+ trans = nil
750
+ assert_nothing_raised do
751
+ trans = @api.personal_wallet_transactions(:characterid => 1)
752
+ end
753
+ assert_not_nil @api.last_hash
754
+ assert_kind_of Time, @api.cached_until
755
+ assert_instance_of Reve::Classes::PersonalWalletTransaction, trans.first
756
+ assert_equal 9, trans.size
757
+ trans.each do |t|
758
+ assert_not_nil t.created_at
759
+ assert_not_nil t.id
760
+ assert_not_nil t.quantity
761
+ assert_not_nil t.type_name
762
+ assert_not_nil t.type_id
763
+ assert_not_nil t.price
764
+ assert_not_nil t.client_name
765
+ assert_not_nil t.station_id
766
+ assert_not_nil t.station_name
767
+ assert_not_nil t.type
768
+ end
769
+ end
770
+
771
+ def test_wallet_journal_clean
772
+ Reve::API.personal_wallet_journal_url = XML_BASE + 'wallet_journal.xml'
773
+ journal = nil
774
+ assert_nothing_raised do
775
+ journal = @api.personal_wallet_journal(:characterid => 1)
776
+ end
777
+ assert_not_nil @api.last_hash
778
+ assert_kind_of Time, @api.cached_until
779
+ assert_equal 8, journal.size
780
+ journal.each do |j|
781
+ assert_not_nil j.date
782
+ assert_not_nil j.ref_id
783
+ assert_not_nil j.reftype_id
784
+ assert_not_nil j.owner_name1
785
+ assert_not_nil j.owner_name2
786
+ assert_not_nil j.arg_name1
787
+ assert_not_nil j.amount
788
+ assert_not_nil j.balance
789
+ assert_not_nil j.reason
790
+ end
791
+ end
792
+
793
+ def test_member_tracking_clean
794
+ Reve::API.member_tracking_url = XML_BASE + 'member_tracking.xml'
795
+ members = nil
796
+ assert_nothing_raised do
797
+ members = @api.member_tracking(:characterid => 1)
798
+ end
799
+ assert_not_nil @api.last_hash
800
+ assert_kind_of Time, @api.cached_until
801
+ assert_equal 2, members.size
802
+ members.each do |member|
803
+ assert_not_nil member.character_id
804
+ assert_not_nil member.character_name
805
+ assert_not_nil member.start_time
806
+ assert_not_nil member.base_id
807
+ assert_not_nil member.base
808
+ assert_not_nil member.title
809
+ assert_not_nil member.logon_time
810
+ assert_not_nil member.logoff_time
811
+ assert_not_nil member.location_id
812
+ assert_not_nil member.location
813
+ assert_not_nil member.ship_type_id
814
+ assert_not_nil member.ship_type
815
+ assert_not_nil member.roles
816
+ assert_not_nil member.grantable_roles
817
+ end
818
+ end
819
+
820
+ def test_member_corporation_sheet_clean
821
+ Reve::API.corporation_sheet_url = XML_BASE + 'corporation_sheet.xml'
822
+ sheet = nil
823
+ assert_nothing_raised do
824
+ sheet = @api.corporation_sheet
825
+ end
826
+ assert_not_nil @api.last_hash
827
+ assert_kind_of Time, @api.cached_until
828
+ assert_equal 7, sheet.divisions.size
829
+ assert_equal 7, sheet.wallet_divisions.size
830
+ end
831
+
832
+ def test_nonmember_corporation_sheet_clean
833
+ Reve::API.corporation_sheet_url = XML_BASE + 'nonmember_corpsheet.xml'
834
+ sheet = nil
835
+ assert_nothing_raised do
836
+ sheet = @api.corporation_sheet :corporationid => 134300597
837
+ end
838
+ assert_not_nil @api.last_hash
839
+ assert_kind_of Time, @api.cached_until
840
+ assert_equal 0, sheet.divisions.size
841
+ assert_equal 0, sheet.wallet_divisions.size
842
+ end
843
+
844
+ def test_no_skill_in_training_clean
845
+ # Reve::API.training_skill_url = XML_BASE + 'skill_in_training-none.xml'
846
+ skill = nil
847
+ assert_nothing_raised do
848
+ skill = @api.skill_in_training(:characterid => 1, :url => XML_BASE + 'skill_in_training-none.xml')
849
+ end
850
+ assert_not_nil @api.last_hash
851
+ assert_kind_of Time, @api.cached_until
852
+ assert_equal false, skill.skill_in_training
853
+ end
854
+
855
+ =begin
856
+ # Tests Reve::API#get_xml's segment that fetches from http
857
+ def test_no_skill_in_training_clean_from_svn
858
+ skill = nil
859
+ assert_nothing_raised do
860
+ skill = @api.skill_in_training(:characterid => 123, :url => URI.parse('http://svn.crudvision.com/reve/trunk/test/xml/skill_in_training-none.xml'))
861
+ end
862
+ assert_not_nil @api.last_hash
863
+ assert_kind_of Time, @api.cached_until
864
+ assert_equal false, skill.skill_in_training
865
+ end
866
+ =end
867
+
868
+ def test_amarr_titan_skill_in_training_clean
869
+ Reve::API.training_skill_url = XML_BASE + 'skill_in_training-amarr-titan.xml'
870
+ skill = nil
871
+ assert_nothing_raised do
872
+ skill = @api.skill_in_training(:characerid => 1)
873
+ end
874
+ assert_not_nil @api.last_hash
875
+ assert_kind_of Time, @api.cached_until
876
+ assert skill.skill_in_training
877
+ assert_not_nil skill.start_time
878
+ assert_not_nil skill.type_id
879
+ assert_not_nil skill.end_time
880
+ assert_not_nil skill.to_level
881
+ assert_not_nil skill.start_sp
882
+ assert_not_nil skill.end_sp
883
+ end
884
+
885
+ def test_skill_queue_clean
886
+ Reve::API.skill_queue_url = XML_BASE + 'skill_queue.xml'
887
+ queue = nil
888
+ assert_nothing_raised do
889
+ queue = @api.skill_queue(:characerid => 1)
890
+ end
891
+ assert_kind_of(Reve::Classes::QueuedSkill, queue.first)
892
+ assert_not_nil queue.first.queue_position
893
+ assert_not_nil queue.first.start_time
894
+ assert_not_nil queue.first.type_id
895
+ assert_not_nil queue.first.end_time
896
+ assert_not_nil queue.first.to_level
897
+ assert_not_nil queue.first.start_sp
898
+ assert_not_nil queue.first.end_sp
899
+ assert_equal 9, queue.length
900
+ end
901
+
902
+ def test_corporate_medals
903
+ Reve::API.corporate_medals_url = XML_BASE + 'corp_medals.xml'
904
+ medals = nil
905
+ assert_nothing_raised do
906
+ medals = @api.corporate_medals
907
+ end
908
+ assert_equal(12, medals.size)
909
+ medals.each do |medal|
910
+ assert_kind_of(Reve::Classes::CorporateMedal, medal)
911
+ assert_kind_of(Numeric, medal.id)
912
+ assert_kind_of(NilClass, medal.issued_at) # Doesn't exist for this class, look at created_at
913
+ assert_kind_of(Time, medal.created_at)
914
+ assert_kind_of(String, medal.description)
915
+ assert_kind_of(Numeric, medal.creator_id)
916
+ assert_kind_of(String, medal.title)
917
+ end
918
+ end
919
+
920
+ def test_corporate_member_medals
921
+ Reve::API.corp_member_medals_url = XML_BASE + 'corp_member_medals.xml'
922
+ medals = nil
923
+ assert_nothing_raised do
924
+ medals = @api.corporate_member_medals
925
+ end
926
+ assert_equal(9, medals.size)
927
+ medals.each do |medal|
928
+ assert_kind_of(Reve::Classes::CorporateMemberMedal, medal)
929
+ assert_kind_of(Numeric, medal.id)
930
+ assert_kind_of(Time, medal.issued_at)
931
+ assert_kind_of(Numeric, medal.character_id)
932
+ assert_kind_of(String, medal.reason)
933
+ assert_kind_of(Numeric, medal.issuer_id)
934
+ assert_kind_of(String, medal.status)
935
+ assert medal.is_public?
936
+ assert ! medal.is_private?
937
+ end
938
+ end
939
+
940
+ def test_server_status
941
+ Reve::API.server_status_url = XML_BASE + 'server_status.xml'
942
+ status = nil
943
+ assert_nothing_raised do
944
+ status = @api.server_status
945
+ end
946
+ assert_kind_of(Reve::Classes::ServerStatus, status)
947
+ assert_equal(34444, status.players)
948
+ assert status.open?
949
+ assert status.open
950
+ end
951
+
952
+ def test_character_medals
953
+ Reve::API.character_medals_url = XML_BASE + 'char_medals.xml'
954
+ obj = nil
955
+ assert_nothing_raised do
956
+ obj = @api.character_medals
957
+ end
958
+ assert_kind_of(Reve::Classes::CharacterMedals, obj)
959
+ assert_equal(1, obj.current_corporation.size)
960
+ assert obj.other_corporation.empty?
961
+ obj.current_corporation.each do |medal|
962
+ assert_kind_of(Reve::Classes::CharacterMedal, medal)
963
+ assert_kind_of(Numeric, medal.id)
964
+ assert_kind_of(Time, medal.issued_at)
965
+ assert_kind_of(String, medal.reason)
966
+ assert_kind_of(Numeric, medal.issuer_id)
967
+ assert_kind_of(String, medal.status)
968
+ assert medal.is_public?
969
+ assert ! medal.is_private?
970
+ end
971
+
972
+ end
973
+
974
+ def test_certificate_sheet
975
+ Reve::API.certificate_tree_url = XML_BASE + 'certificate_tree.xml'
976
+ tree = nil
977
+ assert_nothing_raised do
978
+ tree = @api.certificate_tree
979
+ end
980
+ # going to hell
981
+ assert_kind_of(Reve::Classes::CertificateTree, tree)
982
+ assert_equal(1, tree.categories.size)
983
+ assert tree.categories.all? { |cat| cat.kind_of?(Reve::Classes::CertificateCategory) }
984
+ assert tree.categories.all? { |cat| cat.id.kind_of?(Numeric) && cat.name.kind_of?(String) }
985
+ assert_equal(6, tree.categories.first.classes.size) # just 1 category
986
+ assert tree.categories.first.classes.all? { |klass| klass.kind_of?(Reve::Classes::CertificateClass) }
987
+ assert tree.categories.first.classes.all? { |klass| klass.id.kind_of?(Numeric) && klass.name.kind_of?(String) }
988
+ assert tree.categories.first.classes.collect { |klass| klass.certificates }.flatten.all? { |cert| cert.id.kind_of?(Numeric) && cert.grade.kind_of?(Numeric) && cert.corporation_id.kind_of?(Numeric) && cert.description.kind_of?(String) }
989
+ assert_equal(20, tree.categories.first.classes.collect { |klass| klass.certificates }.flatten.size)
990
+ assert_equal(54, tree.categories.first.classes.collect { |klass| klass.certificates }.flatten.collect { |cert| cert.required_skills }.flatten.size)
991
+ assert tree.categories.first.classes.collect { |klass| klass.certificates }.flatten.collect { |cert| cert.required_skills }.flatten.all? { |req| req.id.kind_of?(Numeric) && req.level.kind_of?(Numeric) }
992
+ assert_equal(29, tree.categories.first.classes.collect { |klass| klass.certificates }.flatten.collect { |cert| cert.required_certificates }.flatten.size)
993
+ assert tree.categories.first.classes.collect { |klass| klass.certificates }.flatten.collect { |cert| cert.required_certificates }.flatten.all? { |req| req.id.kind_of?(Numeric) && req.grade.kind_of?(Numeric) }
994
+ end
995
+
996
+ def test_character_sheet_clean
997
+ Reve::API.character_sheet_url = XML_BASE + 'character_sheet.xml'
998
+ sheet = nil
999
+ assert_nothing_raised do
1000
+ sheet = @api.character_sheet(:characterid => 1)
1001
+ end
1002
+ assert_not_nil @api.last_hash
1003
+ assert_kind_of Time, @api.cached_until
1004
+
1005
+ assert_not_nil sheet.name
1006
+ assert_not_nil sheet.race
1007
+ assert_not_nil sheet.bloodline
1008
+ assert_not_nil sheet.gender
1009
+ assert_not_nil sheet.id
1010
+ assert_not_nil sheet.corporation_name
1011
+ assert_not_nil sheet.corporation_id
1012
+ assert_not_nil sheet.balance
1013
+
1014
+ assert_not_nil sheet.intelligence
1015
+ assert_not_nil sheet.memory
1016
+ assert_not_nil sheet.charisma
1017
+ assert_not_nil sheet.perception
1018
+ assert_not_nil sheet.willpower
1019
+
1020
+ assert_equal 5, sheet.enhancers.size, "Implant size mismatch"
1021
+ sheet.enhancers.each do |enhancer|
1022
+ assert_kind_of Reve::Classes::AttributeEnhancer, enhancer
1023
+ end
1024
+ assert_equal 44842126, sheet.skills.inject(0) { |sum,s| sum += s.skillpoints }, "Skillpoint total mismatch"
1025
+
1026
+ sheet.skills.each do |skill|
1027
+ assert_kind_of Reve::Classes::Skill, skill
1028
+ end
1029
+ assert_equal(57, sheet.certificate_ids.size,"Certificate ID size mismatch")
1030
+ assert sheet.certificate_ids.all? { |cid| cid.kind_of?(Fixnum) }
1031
+
1032
+ # role aliases
1033
+ assert ! sheet.corporate_roles_at_hq.empty?
1034
+ assert ! sheet.corporate_roles.empty?
1035
+ assert ! sheet.corporate_roles_at_base.empty?
1036
+ assert ! sheet.corporate_roles_at_other.empty?
1037
+ # role proper methods
1038
+ assert ! sheet.corporationRolesAtHQ.empty?
1039
+ assert ! sheet.corporationRoles.empty?
1040
+ assert ! sheet.corporationRolesAtBase.empty?
1041
+ assert ! sheet.corporationRolesAtOther.empty?
1042
+
1043
+ [ :corporate_roles_at_hq, :corporate_roles, :corporate_roles_at_base, :corporate_roles_at_other ].each do |role_kind|
1044
+ r_ary = sheet.send(role_kind)
1045
+ assert r_ary.all? { |r| r.kind_of?(Reve::Classes::CorporateRole) }
1046
+ assert r_ary.all? { |r| r.name.kind_of?(String) }
1047
+ assert r_ary.all? { |r| r.id.kind_of?(Numeric) }
1048
+ end
1049
+
1050
+ assert ! sheet.corporate_titles.empty?
1051
+ assert sheet.corporate_titles.all? { |t| t.kind_of?(Reve::Classes::CorporateTitle) }
1052
+ assert sheet.corporate_titles.all? { |t| t.name.kind_of?(String) }
1053
+ assert sheet.corporate_titles.all? { |t| t.id.kind_of?(Numeric) }
1054
+
1055
+
1056
+
1057
+ end
1058
+
1059
+ # Can we reassign a URL?
1060
+ def test_assignment
1061
+ assert_nothing_raised do
1062
+ Reve::API.character_sheet_url = "hello"
1063
+ end
1064
+ end
1065
+
1066
+ # Laziness pays off I hope
1067
+ def test_all_raise_errors
1068
+ Dir.glob(File.join(XML_BASE,'errors','*.xml')).each do |file|
1069
+ # Using begin/rescue/assert here because assert_raise doesn't work with.
1070
+ # the exception superclass.
1071
+ begin
1072
+ @api.send(:check_exception,(File.open(file).read))
1073
+ rescue Exception => e
1074
+ assert e.kind_of?(Reve::Exceptions::ReveError)
1075
+ end
1076
+ end
1077
+ end
1078
+
1079
+ def test_get_xml_from_filesystem
1080
+ xmldoc = @api.send(:get_xml, File.join(XML_BASE, 'skill_in_training-none.xml'), {} )
1081
+ assert_equal File.open(File.join(XML_BASE, 'skill_in_training-none.xml')).read, xmldoc
1082
+ end
1083
+
1084
+ =begin
1085
+ def test_get_xml_from_web
1086
+ xmldoc = @api.send(:get_xml, 'http://svn.crudvision.com/reve/trunk/test/xml/skill_in_training-none.xml', {} )
1087
+ assert_equal File.open(File.join(XML_BASE, 'skill_in_training-none.xml')).read, xmldoc
1088
+ end
1089
+ =end
1090
+
1091
+ def test_get_xml_from_filesystem_missing_file
1092
+ assert_raise Errno::ENOENT do
1093
+ xmldoc = @api.send(:get_xml, File.join(XML_BASE,rand.to_s), {} )
1094
+ end
1095
+ end
1096
+ =begin
1097
+ # if this starts to fail make sure the 404 ErrorDocument includes '404 Not Found'
1098
+ def test_get_xml_from_web_missing_file
1099
+ begin
1100
+ xmldoc = @api.send(:get_xml, 'http://svn.crudvision.com/reve/trunk/test/' + rand.to_s, {} )
1101
+ rescue Exception => e
1102
+ assert e.kind_of?(Reve::Exceptions::ReveNetworkStatusException)
1103
+ assert e.message.include?('404 Not Found')
1104
+ end
1105
+ end
1106
+ =end
1107
+
1108
+ def test_format_url_request_one_arg
1109
+ req = @api.send(:format_url_request, { :a => "Hello" })
1110
+ assert_equal "?a=Hello", req
1111
+ end
1112
+
1113
+ def test_format_url_request_two_args
1114
+ req = @api.send(:format_url_request, { :a => "Hello", :world => "b" })
1115
+ assert_equal "?a=Hello&world=b", req
1116
+ end
1117
+
1118
+ def test_format_url_request_nil_value
1119
+ req = @api.send(:format_url_request, { :a => "Hello", :world => nil })
1120
+ assert_equal "?a=Hello", req
1121
+ end
1122
+
1123
+ # make sure we can make a Time object
1124
+ def test_to_time_method
1125
+ str = "2008-01-23 10:32:20"
1126
+ real = Time.utc(2008,01,23,10,32,20)
1127
+ time = nil
1128
+ assert_nothing_raised do
1129
+ time = str.to_time
1130
+ end
1131
+ assert_kind_of Time,time
1132
+ assert_equal real,time
1133
+ end
1134
+
1135
+ protected
1136
+ def get_api(userid = nil, apikey = nil, charid = nil)
1137
+ api = Reve::API.new(userid, apikey, charid)
1138
+ api.save_path = nil
1139
+ api
1140
+ end
1141
+
1142
+ # no need to test corporate cos they're the same.
1143
+ # TODO: Test with nested losses
1144
+ def kills_cleanly(meth = :personal_kills,url = File.join(XML_BASE,'kills.xml'))
1145
+ kills = nil
1146
+ assert_nothing_raised do
1147
+ kills = @api.send(meth,{:url =>url})
1148
+ end
1149
+ assert_equal 25, kills.size
1150
+ assert_equal 25, kills.collect { |k| k.victim.name }.nitems # i should have 10 good victim names to match with 10 kills
1151
+
1152
+ # Process the Kills here to get the number of "Contained Losses" - KillLoss that are contained within another
1153
+ # KillLoss (like a Giant Secure Container); there should only be one contained loss and should be
1154
+ # 64 losses (including the contained_losses)
1155
+ losses = kills.collect { |k| k.losses }.flatten
1156
+ assert_equal 292, losses.size
1157
+ contained_losses = losses.collect { |loss| loss.contained_losses }.flatten
1158
+ assert_equal 0, contained_losses.size
1159
+
1160
+ attacker_names = kills.collect { |k| k.attackers.collect { |a| a.name } }.flatten
1161
+ assert_equal 98, attacker_names.size # total of 25 attackers (24 players + 1 NPC)
1162
+ assert_equal 2, attacker_names.grep(nil).size # npc exists once
1163
+ assert_equal 96, attacker_names.nitems # 24 player attackers
1164
+
1165
+ assert_kind_of Integer, kills.first.victim.faction_id
1166
+ assert_kind_of String, kills.first.victim.faction_name
1167
+
1168
+ assert_kind_of String, kills.first.attackers.first.faction_name
1169
+
1170
+ kills.each do |kill|
1171
+ assert_kind_of Integer, kill.id
1172
+ assert_kind_of Integer, kill.system_id
1173
+
1174
+ assert_kind_of Time, kill.created_at
1175
+ assert_nil kill.moon_id # the ones in the kills.xml are all nil
1176
+ kill.losses.each do |loss|
1177
+ assert_not_nil(loss.type_id)
1178
+ assert_not_nil(loss.flag)
1179
+ assert_not_nil(loss.quantity_dropped)
1180
+ assert_not_nil(loss.quantity_destroyed)
1181
+ loss.contained_losses.each do |closs|
1182
+ assert_not_nil(closs.type_id)
1183
+ assert_not_nil(closs.flag)
1184
+ assert_not_nil(closs.quantity_dropped)
1185
+ assert_not_nil(closs.quantity_destroyed)
1186
+ end
1187
+ end
1188
+ end
1189
+ end
1190
+
1191
+ end