Class TestReve
In: test/test_reve.rb
Parent: Test::Unit::TestCase

Methods

get_api   kills_cleanly   setup   teardown   test_all_raise_errors   test_alliances_clean   test_amarr_titan_skill_in_training_clean   test_assets_clean   test_assignment   test_bad_xml   test_character_sheet_clean   test_characters_clean   test_charid_default_works_when_characterid_is_nil   test_check_exception_with_bad_xml_document   test_conqurable_stations_clean   test_convert_characterids_to_names   test_convert_characternames_to_ids   test_corporate_assets_list_clean   test_corporate_factional_war_stats_clean   test_corporate_industry_jobs_clean   test_corporate_kills_clean   test_corporate_market_orders_clean   test_corporate_wallet_balance_clean   test_corporate_wallet_journal_clean   test_corporate_wallet_transactions   test_corporation_sheet_clean   test_errors_api_call   test_faction_war_stats_clean   test_faction_war_system_stats_alias_clean   test_faction_war_system_stats_clean   test_faction_war_top_stats_clean   test_for_bad_uri_passed_to_method   test_format_url_request_nil_value   test_format_url_request_one_arg   test_format_url_request_two_args   test_get_xml_from_filesystem   test_get_xml_from_filesystem_missing_file   test_get_xml_from_web   test_get_xml_from_web_missing_file   test_kills_clean   test_makes_a_complex_hash   test_makes_a_simple_hash   test_makes_right_api_1_param   test_makes_right_api_2_param   test_makes_right_api_3_param   test_makes_right_api_empty   test_map_jumps_clean   test_map_kills_clean   test_market_orders_clean   test_member_corporation_sheet_clean   test_member_tracking_clean   test_no_skill_in_training_clean   test_no_skill_in_training_clean_from_svn   test_nonmember_corporation_sheet_clean   test_personal_factional_war_stats_clean   test_personal_industry_jobs_clean   test_reftypes_clean   test_saving_xml_when_404   test_saving_xml_when_save_path_is_nil   test_saving_xml_with_bad_short_tag   test_saving_xml_works   test_skill_tree_clean   test_sovereignty_clean   test_starbase_fuel_clean   test_starbases_clean   test_to_time_method   test_wallet_balance_clean   test_wallet_journal_clean   test_wallet_transactions_clean  

Public Instance methods

[Source]

    # File test/test_reve.rb, line 10
10:   def setup
11:     @api = get_api
12:     assert_nil @api.last_hash
13:     FileUtils.mkdir(SAVE_PATH) rescue nil
14:   end

[Source]

    # File test/test_reve.rb, line 15
15:   def teardown
16:     FileUtils.rm_rf(SAVE_PATH)
17:   end

Laziness pays off I hope

[Source]

     # File test/test_reve.rb, line 924
924:   def test_all_raise_errors
925:     Dir.glob(File.join(XML_BASE,'errors','*.xml')).each do |file|
926:       # Using begin/rescue/assert here because assert_raise doesn't work with.
927:       # the exception superclass.
928:       begin
929:         @api.send(:check_exception,(File.open(file).read))
930:       rescue Exception => e
931:         assert e.kind_of?(Reve::Exceptions::ReveError)
932:       end
933:     end
934:   end

[Source]

     # File test/test_reve.rb, line 512
512:   def test_alliances_clean
513:     Reve::API.alliances_url = XML_BASE + 'alliances.xml'
514:     alliances = nil
515:     assert_nothing_raised do
516:       alliances = @api.alliances
517:     end
518:     assert_not_nil @api.last_hash
519:     assert_kind_of Time, @api.cached_until
520:     assert_equal 3, alliances.size
521:     corpsize = 0
522:     alliances.each do |alliance|
523:       assert_instance_of Reve::Classes::Alliance, alliance
524:       assert_not_equal 0, alliance.member_corporations
525:       assert_not_nil alliance.name
526:       assert_not_nil alliance.id
527:       assert_not_nil alliance.short_name
528:       assert_not_nil alliance.member_count
529:       assert_not_nil alliance.executor_corp_id
530:       corpsize += alliance.member_corporations.size
531:     end
532:     assert_equal 150, corpsize
533:   end

[Source]

     # File test/test_reve.rb, line 864
864:   def test_amarr_titan_skill_in_training_clean
865:     Reve::API.training_skill_url = XML_BASE + 'skill_in_training-amarr-titan.xml'
866:     skill = nil
867:     assert_nothing_raised do
868:       skill = @api.skill_in_training(:characerid => 1)
869:     end
870:     assert_not_nil @api.last_hash
871:     assert_kind_of Time, @api.cached_until
872:     assert skill.skill_in_training
873:     assert_not_nil skill.start_time
874:     assert_not_nil skill.type_id
875:     assert_not_nil skill.end_time
876:     assert_not_nil skill.to_level
877:     assert_not_nil skill.start_sp
878:     assert_not_nil skill.end_sp
879:   end

[Source]

     # File test/test_reve.rb, line 421
421:   def test_assets_clean
422:     Reve::API.personal_assets_url = XML_BASE + 'assets.xml'
423:     assets = nil
424:     assert_nothing_raised do
425:       assets = @api.personal_assets_list
426:     end
427:     assert_equal 18, assets.size # 18 single and 1 container
428:     contained_assets = assets.inject([]) { |ass,container| ass << container.assets }.flatten
429:     assert_equal(1, contained_assets.size) # We have a container it happens to have 1 asset in it
430:     contained_assets.each do |asset|
431:       assert_instance_of(Reve::Classes::Asset, asset)
432:       assert_not_nil(asset.item_id)
433:       assert_not_nil(asset.type_id)
434:       assert_not_nil(asset.quantity)
435:       assert_not_nil(asset.flag)
436:       assert_not_nil(asset.singleton)
437:     end
438:     assets.each do |asset|
439:       assert_instance_of(Reve::Classes::AssetContainer, asset)
440:       assert_not_nil(asset.item_id)
441:       assert_not_nil(asset.location_id)
442:       assert_not_nil(asset.type_id)
443:       assert_not_nil(asset.quantity)
444:       assert_not_nil(asset.flag)
445:       assert_not_nil(asset.singleton)
446:     end
447:   end

Can we reassign a URL?

[Source]

     # File test/test_reve.rb, line 917
917:   def test_assignment
918:     assert_nothing_raised do
919:       Reve::API.character_sheet_url = "hello"
920:     end
921:   end

[Source]

    # File test/test_reve.rb, line 69
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

[Source]

     # File test/test_reve.rb, line 881
881:   def test_character_sheet_clean
882:     Reve::API.character_sheet_url = XML_BASE + 'character_sheet.xml'
883:     sheet = nil
884:     assert_nothing_raised do
885:       sheet = @api.character_sheet(:characterid => 1)
886:     end
887:     assert_not_nil @api.last_hash
888:     assert_kind_of Time, @api.cached_until
889:     
890:     assert_not_nil sheet.name
891:     assert_not_nil sheet.race
892:     assert_not_nil sheet.bloodline
893:     assert_not_nil sheet.gender
894:     assert_not_nil sheet.id
895:     assert_not_nil sheet.corporation_name
896:     assert_not_nil sheet.corporation_id
897:     assert_not_nil sheet.balance
898: 
899:     assert_not_nil sheet.intelligence
900:     assert_not_nil sheet.memory
901:     assert_not_nil sheet.charisma
902:     assert_not_nil sheet.perception
903:     assert_not_nil sheet.willpower
904: 
905:     assert_equal 2, sheet.enhancers.size
906:     sheet.enhancers.each do |enhancer|
907:       assert_kind_of Reve::Classes::AttributeEnhancer, enhancer
908:     end
909:     assert_equal 24500, sheet.skills.inject(0) { |sum,s| sum += s.skillpoints }
910: 
911:     sheet.skills.each do |skill|
912:       assert_kind_of Reve::Classes::Skill, skill
913:     end
914:   end

[Source]

     # File test/test_reve.rb, line 459
459:   def test_characters_clean
460:     Reve::API.characters_url = XML_BASE + 'characters.xml'
461:     chars = nil
462:     assert_nothing_raised do
463:       chars = @api.characters
464:     end
465:     assert_not_nil @api.last_hash
466:     assert_kind_of Time, @api.cached_until
467:     assert_equal 1, chars.size
468:     chars.each do |char|
469:       assert_not_nil(char.name)
470:       assert_not_nil(char.id)
471:       assert_not_nil(char.corporation_name)
472:       assert_not_nil(char.corporation_id)
473:       assert_instance_of Reve::Classes::Character, char
474:     end
475:   end

[Source]

    # File test/test_reve.rb, line 55
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

[Source]

     # File test/test_reve.rb, line 117
117:   def test_check_exception_with_bad_xml_document
118:     assert_raise ArgumentError do
119:       @api.send(:check_exception,nil)
120:     end
121:   end

[Source]

     # File test/test_reve.rb, line 178
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.type_name
194:       assert_not_nil station.corporation_id
195:       assert_not_nil station.corporation_name
196:     end
197:   end

[Source]

     # File test/test_reve.rb, line 199
199:   def test_convert_characterids_to_names
200:     ids = [ 797400947,892008733 ] # CCP Garthagk, Raquel Smith
201:     names = []
202:     assert_nothing_raised do
203:       names = @api.character_name :url => XML_BASE + 'charactername.xml', :ids => ids
204:     end
205:     assert_equal 2, names.size
206:     names.each do |name|
207:       assert_not_nil(name.name)
208:       assert_not_nil(name.id)
209:     end
210:     actual_names = names.collect { |n| n.name }
211:     assert actual_names.include?('CCP Garthagk')
212:     assert actual_names.include?('Raquel Smith')
213:   end

[Source]

     # File test/test_reve.rb, line 215
215:   def test_convert_characternames_to_ids
216:     names = [ 'CCP Garthagk', 'Raquel Smith' ] # 797400947,892008733
217:     ids = []
218:     assert_nothing_raised do
219:       ids = @api.character_id :url => XML_BASE + 'characterid.xml', :names => names
220:     end
221:     assert_equal 2, ids.size
222:     ids.each do |id|
223:       assert_not_nil(id.id)
224:       assert_not_nil(id.name)
225:     end
226:     actual_ids = ids.collect { |n| n.id }
227:     assert actual_ids.include?(797400947)
228:     assert actual_ids.include?(892008733)
229:   end

[Source]

     # File test/test_reve.rb, line 662
662:   def test_corporate_assets_list_clean
663:     assets = nil
664:     assert_nothing_raised do
665:       assets = @api.corporate_assets_list :url => File.join(XML_BASE,'corporate_assets_list.xml')
666:     end
667:     assert_equal 2, assets.size
668:     assert assets.all? { |a| a.kind_of?(Reve::Classes::AssetContainer) }
669:   end

[Source]

     # File test/test_reve.rb, line 364
364:   def test_corporate_factional_war_stats_clean
365:     Reve::API.corporate_faction_war_stats_url = XML_BASE + 'corp_facwarstats.xml'
366:     stats = nil
367:     assert_nothing_raised do
368:       stats = @api.corporate_faction_war_stats
369:     end
370:     assert_instance_of Reve::Classes::CorporateFactionWarParticpant, stats
371:     assert_equal(500001, stats.faction_id)  
372:     assert_equal("Caldari State", stats.faction_name)
373:     assert_equal("2008-06-10 22:10:00".to_time, stats.enlisted_at)
374:     assert_equal(4, stats.pilots)
375:     assert_equal(3, stats.kills_yesterday)
376:     assert_equal(4, stats.kills_last_week)
377:     assert_equal(5, stats.kills_total)
378:     assert_equal(124, stats.victory_points_yesterday)
379:     assert_equal(906, stats.victory_points_last_week)
380:     assert_equal(2690, stats.victory_points_total)
381:   end

[Source]

     # File test/test_reve.rb, line 253
253:   def test_corporate_industry_jobs_clean
254:     Reve::API.corporate_industry_jobs_url = XML_BASE + 'industryjobs.xml'
255:     jobs = nil
256:     assert_nothing_raised do
257:       jobs = @api.corporate_industry_jobs
258:     end
259:     assert_equal 2, jobs.size
260:     # All things got assigned something.
261:     jobs.each do |job|
262:       [ :id, :assembly_line_id, :container_id, :installed_item_id, :installed_item_location_id,
263:         :installed_item_quantity, :installed_item_productivity_level, :installed_item_material_level,
264:         :installed_item_licensed_production_runs_remaining, :output_location_id, :installer_id, :runs,
265:         :licensed_production_runs, :installed_system_id, :container_location_id, :material_multiplier,
266:         :char_material_multiplier, :time_multiplier, :char_time_multiplier, :installed_item_type_id,
267:         :output_type_id, :container_type_id, :installed_item_copy, :completed, :completed_successfully, 
268:         :installed_item_flag, :output_flag, :activity_id, :completed_status, :installed_at, 
269:         :begin_production_at, :end_production_at, :pause_production_time ].each do |att|
270:           assert_not_nil job.send(att)
271:       end
272:     end
273:   end

[Source]

     # File test/test_reve.rb, line 455
455:   def test_corporate_kills_clean
456:     kills_cleanly(:corporate_kills,File.join(XML_BASE,'kills.xml'))
457:   end

[Source]

     # File test/test_reve.rb, line 591
591:   def test_corporate_market_orders_clean
592:     orders = nil
593:     assert_nothing_raised do
594:       orders = @api.corporate_market_orders :url => File.join(XML_BASE,'corporate_market_orders.xml')  
595:     end
596:     assert_not_nil @api.last_hash
597:     assert_kind_of Time, @api.cached_until
598:     assert_equal 1, orders.size    
599:     buys = sells = 0
600:     orders.each do |order|
601:       [ :id, :character_id, :station_id, :volume_entered, :volume_remaining, :minimum_volume,
602:       :order_state, :type_id, :range, :account_key, :duration, :escrow, :price, :bid ].each do |attr|
603:         assert_not_nil(order.send(attr))
604:       end
605:       assert_kind_of Time, order.created_at
606:       assert [TrueClass, FalseClass].include?(order.bid.class)
607:       buys  += 1 if ! order.bid
608:       sells += 1 if   order.bid        
609:     end
610:     assert_equal 1, buys
611:     assert_equal 0, sells    
612:   end

[Source]

     # File test/test_reve.rb, line 631
631:   def test_corporate_wallet_balance_clean
632:     balance = nil
633:     assert_nothing_raised do
634:       balance = @api.corporate_wallet_balance :url => File.join(XML_BASE, 'corporate_wallet_balance.xml')
635:     end
636:     assert balance.all? { |b| b.kind_of?(Reve::Classes::WalletBalance) }
637:     balance.each do |bal|
638:       assert_not_nil(bal.account_id)
639:       assert_not_nil(bal.account_key)
640:       assert_not_nil(bal.balance)
641:     end
642:     assert_equal 18004409.84, balance.select { |b| b.account_key == '1000' }.first.balance
643:     balance.select { |b| b.account_key != '1000' }.each do |non_tested_account|
644:       assert_equal 0.00, non_tested_account.balance
645:     end
646:   end

[Source]

     # File test/test_reve.rb, line 648
648:   def test_corporate_wallet_journal_clean
649:     journal = nil
650:     assert_nothing_raised do
651:       journal = @api.corporate_wallet_journal :url => File.join(XML_BASE,'corporate_wallet_journal.xml')
652:     end
653:     assert_equal 2, journal.size
654:     assert journal.all? { |j| j.kind_of?(Reve::Classes::WalletJournal) }    
655:     journal.each do |j|
656:       [ :date, :ref_id, :reftype_id, :owner_name1, :owner_name2, :arg_name1, :amount, :balance, :reason ].each do |attr|
657:         assert_not_nil(j.send(attr))
658:       end
659:     end
660:   end

[Source]

     # File test/test_reve.rb, line 614
614:   def test_corporate_wallet_transactions
615:     trans = nil
616:     assert_nothing_raised do
617:       trans = @api.corporate_wallet_transactions :url => File.join(XML_BASE,'corporate_wallet_transactions.xml')
618:     end
619:     assert_equal 1, trans.size
620:     assert trans.all? { |tran| tran.kind_of?(Reve::Classes::CorporateWalletTransaction) }
621:     trans.each do |tran|
622:       [ :created_at, :id, :quantity, :type_name, :type_id, :price, 
623:         :client_id, :client_name, :character_id, :station_id, :station_name, :type,
624:         :transaction_for ].each do |attr|
625:       assert_not_nil(tran.send(attr))
626:     end
627:     assert_instance_of(Time, tran.created_at)
628:     end
629:   end

[Source]

     # File test/test_reve.rb, line 136
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

[Source]

     # File test/test_reve.rb, line 123
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

[Source]

     # File test/test_reve.rb, line 307
307:   def test_faction_war_stats_clean
308:     Reve::API.general_faction_war_stats_url = XML_BASE + 'eve_facwarstats.xml'
309:     stats = nil
310:     assert_nothing_raised do
311:       stats = @api.faction_war_stats
312:     end
313:     assert_instance_of(Reve::Classes::EveFactionWarStat, stats)
314:     assert_equal(1707, stats.kills_yesterday)
315:     assert_equal(9737, stats.kills_last_week)
316:     assert_equal(27866, stats.kills_total)
317:     assert_equal(215674, stats.victory_points_yesterday)
318:     assert_equal(1738351, stats.victory_points_last_week)
319:     assert_equal(5613787, stats.victory_points_total)
320:     
321:     assert stats.faction_wars.all? { |w| w.kind_of?(Reve::Classes::FactionWar) }
322:     assert stats.faction_participants.all? { |w| w.kind_of?(Reve::Classes::FactionwideFactionWarParticpant) }
323:     assert_equal(8, stats.faction_wars.size)
324:     assert_equal(4, stats.faction_participants.size)
325:     stats.faction_wars.each do |war|
326:       assert_not_nil(war.faction_id)
327:       assert_not_nil(war.faction_name)
328:       assert_not_nil(war.against_id)
329:       assert_not_nil(war.against_name)
330:     end
331:     stats.faction_participants.each do |participant|
332:       assert_not_nil(participant.faction_id)
333:       assert_not_nil(participant.faction_name)
334:       assert_not_nil(participant.systems_controlled)
335:       assert_not_nil(participant.kills_yesterday)
336:       assert_not_nil(participant.kills_last_week)
337:       assert_not_nil(participant.kills_total)
338:       assert_not_nil(participant.victory_points_yesterday)
339:       assert_not_nil(participant.victory_points_last_week)
340:       assert_not_nil(participant.victory_points_total)
341:     end
342:     assert_not_nil(@api.cached_until)
343:   end

[Source]

     # File test/test_reve.rb, line 298
298:   def test_faction_war_system_stats_alias_clean
299:     Reve::API.faction_war_occupancy_url = XML_BASE + 'map_facwarsystems.xml'
300:     stats = nil
301:     assert_nothing_raised do
302:       stats = @api.faction_war_occupancy
303:     end
304:     test_faction_war_system_stats_clean(true,stats)
305:   end

[Source]

     # File test/test_reve.rb, line 275
275:   def test_faction_war_system_stats_clean(skip_preamble = false,stats = nil)
276:     Reve::API.faction_war_occupancy_url = XML_BASE + 'map_facwarsystems.xml'
277:     unless skip_preamble # not best practice but will get the job done!
278:       stats = nil
279:       assert_nothing_raised do
280:         stats = @api.faction_war_system_stats
281:       end
282:     end
283:     assert stats.all? { |s| s.kind_of?(Reve::Classes::FactionWarSystemStatus) }
284:     assert_equal(4, stats.size)
285:     stats.each do |sys|
286:       # can't assert_not_nil faction_id or faction_name since they may be nil
287:       assert_not_nil(sys.system_id)
288:       assert_not_nil(sys.system_name)
289:       assert_not_nil(sys.contested)
290:     end
291:     assert_equal(1, stats.select { |s| s.faction_id == 500001 }.size)
292:     assert_equal(1, stats.select { |s| s.faction_id == 500002 }.size)
293:     assert_equal(1, stats.select { |s| ! s.contested }.size)
294:     assert_equal(2, stats.select { |s| s.faction_id.nil? }.size)
295:     assert_equal(3, stats.select { |s| s.contested }.size)
296:   end

[Source]

     # File test/test_reve.rb, line 383
383:   def test_faction_war_top_stats_clean
384:     Reve::API.top_faction_war_stats_url = XML_BASE + 'eve_facwartopstats.xml'
385:     stats = nil
386:     assert_nothing_raised do
387:       stats = @api.faction_war_top_stats
388:     end
389:     assert_kind_of(Reve::Classes::FactionWarTopStats, stats)
390:     [ :characters, :corporations, :factions ].each do |kind|
391:       [ :yesterday_kills, :last_week_kills, :total_kills ].each do |attr|
392:         assert_kind_of(Hash, stats.send(kind))
393:         assert_kind_of(Array, stats.send(kind)[attr])
394:         assert ! stats.send(kind)[attr].empty?
395:         [ :name, :id, :kills ].each do |c_attr|
396:           assert stats.send(kind)[attr].all? { |e| ! e.nil? }
397:         end
398:       end
399:       [ :last_week_victory_points, :yesterday_victory_points, :total_victory_points ].each do |attr|
400:         assert_kind_of(Hash, stats.send(kind))
401:         assert_kind_of(Array, stats.send(kind)[attr])
402:         assert ! stats.send(kind)[attr].empty?
403:         [ :name, :id, :victory_points ].each do |c_attr|
404:           assert stats.send(kind)[attr].all? { |e| ! e.nil? }
405:         end
406:       end
407:     end
408:     assert_equal(5, stats.characters[:yesterday_kills].size)
409:     assert_equal(6, stats.characters[:last_week_kills].size)
410:     assert_equal(7, stats.characters[:total_kills].size)
411:     [ :yesterday_kills, :yesterday_victory_points, :last_week_kills,
412:       :last_week_victory_points, :total_kills, :total_victory_points ].each do |attr|
413:         assert_equal(10,stats.corporations[attr].size)
414:     end
415:     [ :yesterday_kills, :yesterday_victory_points, :last_week_kills,
416:       :last_week_victory_points, :total_kills, :total_victory_points ].each do |attr|
417:         assert_equal(4,stats.factions[attr].size)
418:     end
419:   end

File.split exists and File is not a String or URI class as permitted in Reve::API#get_xml. This means as a parameter it will pass through Reve::API#compute_hash method and get to Reve::API#get_xml

[Source]

     # File test/test_reve.rb, line 111
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

[Source]

     # File test/test_reve.rb, line 972
972:   def test_format_url_request_nil_value
973:     req = @api.send(:format_url_request, { :a => "Hello", :world => nil })
974:     assert_equal "?a=Hello", req  
975:   end

[Source]

     # File test/test_reve.rb, line 962
962:   def test_format_url_request_one_arg
963:     req = @api.send(:format_url_request, { :a => "Hello" })
964:     assert_equal "?a=Hello", req
965:   end

[Source]

     # File test/test_reve.rb, line 967
967:   def test_format_url_request_two_args
968:     req = @api.send(:format_url_request, { :a => "Hello", :world => "b" })
969:     assert_equal "?a=Hello&world=b", req
970:   end

[Source]

     # File test/test_reve.rb, line 936
936:   def test_get_xml_from_filesystem
937:     xmldoc = @api.send(:get_xml, File.join(XML_BASE, 'skill_in_training-none.xml'), {} )
938:     assert_equal File.open(File.join(XML_BASE, 'skill_in_training-none.xml')).read, xmldoc
939:   end

[Source]

     # File test/test_reve.rb, line 946
946:   def test_get_xml_from_filesystem_missing_file
947:     assert_raise Errno::ENOENT do
948:       xmldoc = @api.send(:get_xml, File.join(XML_BASE,rand.to_s), {} )
949:     end    
950:   end

[Source]

     # File test/test_reve.rb, line 941
941:   def test_get_xml_from_web
942:     xmldoc = @api.send(:get_xml, 'http://svn.crudvision.com/reve/trunk/test/xml/skill_in_training-none.xml', {} )
943:     assert_equal File.open(File.join(XML_BASE, 'skill_in_training-none.xml')).read, xmldoc
944:   end

if this starts to fail make sure the 404 ErrorDocument includes ‘404 Not Found‘

[Source]

     # File test/test_reve.rb, line 953
953:   def test_get_xml_from_web_missing_file
954:     begin
955:       xmldoc = @api.send(:get_xml, 'http://svn.crudvision.com/reve/trunk/test/' + rand.to_s, {} )
956:     rescue Exception => e
957:       assert e.kind_of?(Reve::Exceptions::ReveNetworkStatusException)
958:       assert e.message.include?('404 Not Found')
959:     end    
960:   end

no need to test corporate cos they‘re the same. TODO: Test with nested losses

[Source]

     # File test/test_reve.rb, line 451
451:   def test_kills_clean
452:     kills_cleanly(:personal_kills,File.join(XML_BASE,'kills.xml'))
453:   end

[Source]

    # File test/test_reve.rb, line 60
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

[Source]

    # File test/test_reve.rb, line 48
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

[Source]

    # File test/test_reve.rb, line 26
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

[Source]

    # File test/test_reve.rb, line 33
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

[Source]

    # File test/test_reve.rb, line 40
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

[Source]

    # File test/test_reve.rb, line 19
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

[Source]

     # File test/test_reve.rb, line 671
671:   def test_map_jumps_clean
672:     Reve::API.map_jumps_url = XML_BASE + 'mapjumps.xml'
673:     mapjumps = nil
674:     assert_nothing_raised do
675:       mapjumps = @api.map_jumps
676:     end
677:     assert_not_nil @api.last_hash
678:     assert_kind_of Time, @api.cached_until
679:     assert_equal 5, mapjumps.size
680:     mapjumps.each do |jump|
681:       assert_not_nil jump.system_id
682:       assert_not_nil jump.jumps
683:     end
684:   end

[Source]

     # File test/test_reve.rb, line 686
686:   def test_map_kills_clean
687:     Reve::API.map_kills_url = XML_BASE + 'mapkills.xml'
688:     mapkills = nil
689:     assert_nothing_raised do
690:       mapkills = @api.map_kills
691:     end
692:     assert_not_nil @api.last_hash
693:     assert_kind_of Time, @api.cached_until
694:     assert_equal 4, mapkills.size
695:     mapkills.each do |kill|
696:       assert_not_nil kill.system_id
697:       assert_not_nil kill.faction_kills
698:       assert_not_nil kill.ship_kills
699:       assert_not_nil kill.pod_kills
700:     end
701:   end

[Source]

     # File test/test_reve.rb, line 567
567:   def test_market_orders_clean
568:     Reve::API.personal_market_orders_url = XML_BASE + 'marketorders.xml'
569:     orders = nil
570:     assert_nothing_raised do
571:       orders = @api.personal_market_orders
572:     end
573:     assert_not_nil @api.last_hash
574:     assert_kind_of Time, @api.cached_until
575:     assert_equal 11, orders.size    
576:     buys = sells = 0
577:     orders.each do |order|
578:       [ :id, :character_id, :station_id, :volume_entered, :volume_remaining, :minimum_volume,
579:       :order_state, :type_id, :range, :account_key, :duration, :escrow, :price, :bid ].each do |attr|
580:         assert_not_nil(order.send(attr))
581:       end
582:       assert_kind_of Time, order.created_at
583:       assert [TrueClass, FalseClass].include?(order.bid.class)
584:       buys  += 1 if ! order.bid
585:       sells += 1 if   order.bid        
586:     end
587:     assert_equal 4, buys
588:     assert_equal 7, sells
589:   end

[Source]

     # File test/test_reve.rb, line 818
818:   def test_member_corporation_sheet_clean
819:     Reve::API.corporation_sheet_url = XML_BASE + 'corporation_sheet.xml'
820:     sheet = nil
821:     assert_nothing_raised do
822:       sheet = @api.corporation_sheet
823:     end
824:     assert_not_nil @api.last_hash
825:     assert_kind_of Time, @api.cached_until
826:     assert_equal 7, sheet.divisions.size
827:     assert_equal 7, sheet.wallet_divisions.size
828:   end

[Source]

     # File test/test_reve.rb, line 791
791:   def test_member_tracking_clean
792:     Reve::API.member_tracking_url = XML_BASE + 'member_tracking.xml'
793:     members = nil
794:     assert_nothing_raised do
795:       members = @api.member_tracking(:characterid => 1)
796:     end
797:     assert_not_nil @api.last_hash
798:     assert_kind_of Time, @api.cached_until
799:     assert_equal 2, members.size
800:     members.each do |member|
801:       assert_not_nil member.character_id
802:       assert_not_nil member.character_name
803:       assert_not_nil member.start_time
804:       assert_not_nil member.base_id
805:       assert_not_nil member.base
806:       assert_not_nil member.title
807:       assert_not_nil member.logon_time
808:       assert_not_nil member.logoff_time
809:       assert_not_nil member.location_id
810:       assert_not_nil member.location
811:       assert_not_nil member.ship_type_id
812:       assert_not_nil member.ship_type
813:       assert_not_nil member.roles
814:       assert_not_nil member.grantable_roles
815:     end
816:   end

[Source]

     # File test/test_reve.rb, line 842
842:   def test_no_skill_in_training_clean
843: #    Reve::API.training_skill_url = XML_BASE + 'skill_in_training-none.xml'
844:     skill = nil
845:     assert_nothing_raised do
846:       skill = @api.skill_in_training(:characterid => 1, :url => XML_BASE + 'skill_in_training-none.xml')
847:     end
848:     assert_not_nil @api.last_hash
849:     assert_kind_of Time, @api.cached_until
850:     assert_equal false, skill.skill_in_training
851:   end

Tests Reve::API#get_xml‘s segment that fetches from http

[Source]

     # File test/test_reve.rb, line 854
854:   def test_no_skill_in_training_clean_from_svn
855:     skill = nil
856:     assert_nothing_raised do
857:       skill = @api.skill_in_training(:characterid => 123, :url => URI.parse('http://svn.crudvision.com/reve/trunk/test/xml/skill_in_training-none.xml'))
858:     end
859:     assert_not_nil @api.last_hash
860:     assert_kind_of Time, @api.cached_until
861:     assert_equal false, skill.skill_in_training
862:   end

[Source]

     # File test/test_reve.rb, line 830
830:   def test_nonmember_corporation_sheet_clean
831:     Reve::API.corporation_sheet_url = XML_BASE + 'nonmember_corpsheet.xml'
832:     sheet = nil
833:     assert_nothing_raised do
834:       sheet = @api.corporation_sheet :corporationid => 134300597
835:     end
836:     assert_not_nil @api.last_hash
837:     assert_kind_of Time, @api.cached_until
838:     assert_equal 0, sheet.divisions.size
839:     assert_equal 0, sheet.wallet_divisions.size
840:   end

[Source]

     # File test/test_reve.rb, line 344
344:   def test_personal_factional_war_stats_clean
345:     Reve::API.personal_faction_war_stats_url = XML_BASE + 'char_facwarstats.xml'
346:     stats = nil
347:     assert_nothing_raised do
348:       stats = @api.personal_faction_war_stats
349:     end
350:     assert_instance_of Reve::Classes::PersonalFactionWarParticpant, stats
351:     assert_equal(500001, stats.faction_id)  
352:     assert_equal("Caldari State", stats.faction_name)
353:     assert_equal("2008-06-13 20:38:00".to_time, stats.enlisted_at)
354:     assert_equal(1, stats.current_rank)
355:     assert_equal(2, stats.highest_rank)
356:     assert_equal(3, stats.kills_yesterday)
357:     assert_equal(4, stats.kills_last_week)
358:     assert_equal(5, stats.kills_total)
359:     assert_equal(124, stats.victory_points_yesterday)
360:     assert_equal(124, stats.victory_points_last_week)
361:     assert_equal(506, stats.victory_points_total)
362:   end

[Source]

     # File test/test_reve.rb, line 231
231:   def test_personal_industry_jobs_clean
232:     Reve::API.personal_industry_jobs_url = XML_BASE + 'industryjobs.xml'
233:     jobs = nil
234:     assert_nothing_raised do
235:       jobs = @api.personal_industry_jobs
236:     end
237:     assert_equal 2, jobs.size
238:     # All things got assigned something.
239:     jobs.each do |job|
240:       [ :id, :assembly_line_id, :container_id, :installed_item_id, :installed_item_location_id,
241:         :installed_item_quantity, :installed_item_productivity_level, :installed_item_material_level,
242:         :installed_item_licensed_production_runs_remaining, :output_location_id, :installer_id, :runs,
243:         :licensed_production_runs, :installed_system_id, :container_location_id, :material_multiplier,
244:         :char_material_multiplier, :time_multiplier, :char_time_multiplier, :installed_item_type_id,
245:         :output_type_id, :container_type_id, :installed_item_copy, :completed, :completed_successfully, 
246:         :installed_item_flag, :output_flag, :activity_id, :completed_status, :installed_at, 
247:         :begin_production_at, :end_production_at, :pause_production_time ].each do |att|
248:           assert_not_nil job.send(att)
249:       end
250:     end
251:   end

[Source]

     # File test/test_reve.rb, line 552
552:   def test_reftypes_clean
553:     Reve::API.reftypes_url = XML_BASE + 'reftypes.xml'
554:     reftypes = nil
555:     assert_nothing_raised do
556:       reftypes = @api.ref_types
557:     end
558:     assert_not_nil @api.last_hash
559:     assert_kind_of Time, @api.cached_until
560:     assert_equal 6, reftypes.size
561:     reftypes.each do |reftype|
562:       assert_not_nil reftype.id
563:       assert_not_nil reftype.name
564:     end
565:   end

[Source]

     # File test/test_reve.rb, line 98
 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

[Source]

    # File test/test_reve.rb, line 84
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

We want to see <url /> in the saved XML because that‘s what came from the source

[Source]

    # File test/test_reve.rb, line 91
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

[Source]

    # File test/test_reve.rb, line 75
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

[Source]

     # File test/test_reve.rb, line 703
703:   def test_skill_tree_clean
704:     Reve::API.skill_tree_url = XML_BASE + 'skilltree.xml'
705:     skilltrees = nil
706:     assert_nothing_raised do
707:       skilltrees = @api.skill_tree
708:     end
709:     assert_not_nil @api.last_hash
710:     assert_kind_of Time, @api.cached_until
711:     assert_equal 2, skilltrees.size
712:     skilltrees.each do |skill|
713:       assert_not_nil skill.type_id
714:       assert_not_nil skill.name
715:       assert_not_nil skill.rank
716:       assert_not_nil skill.description
717:       skill.bonuses.each do |bonus|
718:         assert_kind_of Reve::Classes::SkillBonus, bonus
719:       end
720:       skill.attribs.each do |attrib|
721:         assert_kind_of Reve::Classes::RequiredAttribute, attrib
722:       end
723:       skill.required_skills.each do |req|
724:         assert_kind_of Reve::Classes::SkillRequirement, req
725:       end
726:     end
727:   end

[Source]

     # File test/test_reve.rb, line 535
535:   def test_sovereignty_clean
536:     Reve::API.sovereignty_url = XML_BASE + 'sovereignty.xml'
537:     sovereignties = nil
538:     assert_nothing_raised do
539:       sovereignties = @api.sovereignty
540:     end
541:     assert_not_nil @api.last_hash
542:     assert_kind_of Time, @api.cached_until
543:     assert_equal 7, sovereignties.size
544:     sovereignties.each do |sovereignty|
545:       assert_instance_of Reve::Classes::Sovereignty, sovereignty
546:       assert_not_nil sovereignty.system_id
547:       assert_not_nil sovereignty.constellation_sovereignty
548:       assert_not_nil sovereignty.system_name
549:     end
550:   end

[Source]

     # File test/test_reve.rb, line 496
496:   def test_starbase_fuel_clean
497:     Reve::API.starbasedetail_url = XML_BASE + 'starbase_fuel.xml'
498:     fuels = nil
499:     assert_nothing_raised do
500:       fuels = @api.starbase_fuel(:starbaseid => 1,:characterid => 2)
501:     end
502:     assert_not_nil @api.last_hash
503:     assert_kind_of Time, @api.cached_until
504:     assert_equal 14, fuels.size
505:     fuels.each do |fuel|
506:       assert_equal 1, fuel.starbase_id
507:       assert_not_nil fuel.type_id
508:       assert_not_nil fuel.quantity
509:     end
510:   end

[Source]

     # File test/test_reve.rb, line 477
477:   def test_starbases_clean
478:     Reve::API.starbases_url = XML_BASE + 'starbases.xml'
479:     bases = nil
480:     assert_nothing_raised do
481:       bases = @api.starbases(:characterid => 1)
482:     end
483:     assert_not_nil @api.last_hash
484:     assert_kind_of Time, @api.cached_until
485:     assert_equal 4, bases.size
486:     bases.each do |starbase|
487:       assert_instance_of Reve::Classes::Starbase, starbase
488:       assert_not_nil starbase.type_id
489:       assert_not_nil starbase.type_name
490:       assert_not_nil starbase.id
491:       assert_not_nil starbase.system_id
492:       assert_not_nil starbase.system_name
493:     end
494:   end

make sure we can make a Time object

[Source]

     # File test/test_reve.rb, line 978
978:   def test_to_time_method
979:     str = "2008-01-23 10:32:20"
980:     real = Time.utc(2008,01,23,10,32,20)
981:     time = nil
982:     assert_nothing_raised do
983:       time  = str.to_time
984:     end
985:     assert_kind_of Time,time
986:     assert_equal real,time
987:   end

[Source]

     # File test/test_reve.rb, line 729
729:   def test_wallet_balance_clean
730:     Reve::API.personal_wallet_balance_url = XML_BASE + 'wallet_balance.xml'
731:     balance = nil
732:     assert_nothing_raised do
733:       balance = @api.personal_wallet_balance(:characterid => 1)
734:     end
735:     assert_not_nil @api.last_hash
736:     assert_kind_of Time, @api.cached_until
737:     assert_equal 7, balance.size
738:     balance.each do |bal|
739:       assert_not_nil bal.account_id
740:       assert_not_nil bal.account_key
741:       assert_not_nil bal.balance
742:     end
743:   end

[Source]

     # File test/test_reve.rb, line 769
769:   def test_wallet_journal_clean
770:     Reve::API.personal_wallet_journal_url = XML_BASE + 'wallet_journal.xml'
771:     journal = nil
772:     assert_nothing_raised do
773:       journal = @api.personal_wallet_journal(:characterid => 1)
774:     end
775:     assert_not_nil @api.last_hash
776:     assert_kind_of Time, @api.cached_until
777:     assert_equal 8, journal.size
778:     journal.each do |j|
779:       assert_not_nil j.date
780:       assert_not_nil j.ref_id
781:       assert_not_nil j.reftype_id
782:       assert_not_nil j.owner_name1
783:       assert_not_nil j.owner_name2
784:       assert_not_nil j.arg_name1
785:       assert_not_nil j.amount
786:       assert_not_nil j.balance
787:       assert_not_nil j.reason
788:     end
789:   end

[Source]

     # File test/test_reve.rb, line 745
745:   def test_wallet_transactions_clean
746:     Reve::API.personal_wallet_trans_url = XML_BASE + 'market_transactions.xml'
747:     trans = nil
748:     assert_nothing_raised do
749:       trans = @api.personal_wallet_transactions(:characterid => 1)
750:     end
751:     assert_not_nil @api.last_hash
752:     assert_kind_of Time, @api.cached_until
753:     assert_instance_of Reve::Classes::PersonalWalletTransaction, trans.first
754:     assert_equal 9, trans.size
755:     trans.each do |t|
756:       assert_not_nil t.created_at
757:       assert_not_nil t.id
758:       assert_not_nil t.quantity
759:       assert_not_nil t.type_name
760:       assert_not_nil t.type_id
761:       assert_not_nil t.price
762:       assert_not_nil t.client_name
763:       assert_not_nil t.station_id
764:       assert_not_nil t.station_name
765:       assert_not_nil t.type
766:     end
767:   end

Protected Instance methods

[Source]

     # File test/test_reve.rb, line 990
990:   def get_api(userid = nil, apikey = nil, charid = nil)
991:     api = Reve::API.new(userid, apikey, charid)
992:     api.save_path = nil
993:     api
994:   end

no need to test corporate cos they‘re the same. TODO: Test with nested losses

[Source]

      # File test/test_reve.rb, line 998
 998:   def kills_cleanly(meth = :personal_kills,url = File.join(XML_BASE,'kills.xml'))
 999:     kills = nil
1000:     assert_nothing_raised do
1001:       kills = @api.send(meth,{:url =>url})
1002:     end
1003:     assert_equal 10, kills.size
1004:     assert_equal 10, kills.collect { |k| k.victim.name }.nitems # i should have 10 good victim names to match with 10 kills
1005:     
1006:     # Process the Kills here to get the number of "Contained Losses" - KillLoss that are contained within another
1007:     # KillLoss (like a Giant Secure Container); there should only be one contained loss and should be 
1008:     # 64 losses (including the contained_losses)
1009:     losses = kills.collect { |k| k.losses }.flatten
1010:     assert_equal 64, losses.size
1011:     contained_losses = losses.collect { |loss| loss.contained_losses  }.flatten
1012:     assert_equal 1, contained_losses.size
1013: 
1014:     attacker_names = kills.collect { |k| k.attackers.collect { |a| a.name } }.flatten
1015:     assert_equal 25, attacker_names.size # total of 25 attackers (24 players + 1 NPC)
1016:     assert_equal 1, attacker_names.grep(nil).size # npc exists once
1017:     assert_equal 24, attacker_names.nitems # 24 player attackers
1018:     
1019:     kills.each do |kill|
1020:       assert_kind_of Integer, kill.id
1021:       assert_kind_of Integer, kill.system_id
1022:       assert_kind_of Time, kill.created_at
1023:       assert_nil kill.moon_id # the ones in the kills.xml are all nil
1024:       kill.losses.each do |loss|
1025:         assert_not_nil(loss.type_id)
1026:         assert_not_nil(loss.flag)
1027:         assert_not_nil(loss.quantity_dropped)
1028:         assert_not_nil(loss.quantity_destroyed)
1029:         loss.contained_losses.each do |closs|
1030:           assert_not_nil(closs.type_id)
1031:           assert_not_nil(closs.flag)
1032:           assert_not_nil(closs.quantity_dropped)
1033:           assert_not_nil(closs.quantity_destroyed)
1034:         end
1035:       end
1036:     end
1037:   end

[Validate]