def main(): # Setup the command line arguments. optp = OptionParser() # Output verbosity options. optp.add_option('-q', '--quiet', help='set logging to ERROR', action='store_const', dest='loglevel', const=logging.ERROR, default=logging.INFO) optp.add_option('-d', '--debug', help='set logging to DEBUG', action='store_const', dest='loglevel', const=logging.DEBUG, default=logging.INFO) optp.add_option('-v', '--verbose', help='set logging to COMM', action='store_const', dest='loglevel', const=5, default=logging.INFO) # JID and password options. optp.add_option("-c", "--config", dest="config", help="Configuration file to use") opts, args = optp.parse_args() # Load config if opts.config == 'env': # Parse the environment for config config = dict([(k[8:].lower(), v) for k, v in os.environ.items() if 'DROPBOT_' in k]) # Split out array type configs for key in ['rooms', 'admins', 'kill_corps', 'market_systems']: if key in config: config[key] = [x.strip() for x in config[key].split(',')] elif opts.config.lower().startswith('http'): try: config = requests.get(opts.config).json() except: print "Unable to download configuration from %s" % opts.config return 1 else: cfg = os.path.expanduser(os.path.expandvars(opts.config)) if not os.path.exists(cfg): print "Configuration file %s does not exist" % cfg return 1 with open(os.path.expanduser(cfg), 'r') as f: config = load(f) # Setup logging. logging.basicConfig(level=opts.loglevel, format='%(levelname)-8s %(message)s') xmpp = DropBot(**config) # Connect to the XMPP server and start processing XMPP stanzas. if xmpp.connect(): xmpp.process(block=True) print("Done") else: print("Unable to connect.")
class DropBotTestCase(TestCase): def setUp(self): self.bot = DropBot('*****@*****.**', 'testpassword') def test_simple_bot(self): self.assertIsNotNone(self.bot) def test_system_picker(self): self.assertEquals(self.bot._system_picker('Jita'), 30000142) self.assertEquals(self.bot._system_picker('Jit'), 30000142) self.assertIs(type(self.bot._system_picker('J')), str) self.assertEqual( self.bot._system_picker('J'), 'More than 10 systems match J, please provide a more complete name' ) self.assertEqual(self.bot._system_picker('GE-'), 'Did you mean: GE-94X, GE-8JV?') self.assertEqual(self.bot._system_picker('asdasd'), 'No systems found matching asdasd') def test_get_evecentral_price(self): self.assertIs(self.bot._get_evecentral_price(1, 1), None) self.assertIs(type(self.bot._get_evecentral_price(22430, 30000142)), tuple)
def setUp(self): self.bot = DropBot('*****@*****.**', 'testpassword')
class DropBotTestCase(TestCase): def setUp(self): self.bot = DropBot('*****@*****.**', 'testpassword') def call_command(self, command, args=[]): """Fakes a call to a bot command""" msg = {'type': 'groupchat'} return self.bot.call_command(command, args, msg) def test_simple_bot(self): self.assertIsNotNone(self.bot) def test_system_picker(self): self.assertEquals(self.bot._system_picker('Jita'), 30000142) self.assertEquals(self.bot._system_picker('Jit'), 30000142) self.assertIs(type(self.bot._system_picker('J')), str) self.assertEqual(self.bot._system_picker('J'), 'More than 10 systems match J, please provide a more complete name') self.assertEqual(self.bot._system_picker('GE-'), 'Did you mean: GE-94X, GE-8JV?') self.assertEqual(self.bot._system_picker('asdasd'), 'No systems found matching asdasd') @unittest.skipIf(os.environ.get('NO_NETWORK', '0') == '1', 'No networking, skipping test') def test_get_evecentral_price(self): self.assertIs(self.bot._get_evecentral_price(1,1), None) self.assertIs(type(self.bot._get_evecentral_price(22430, 30000142)), tuple) def test_cmd_help(self): res = self.call_command('help') self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) @unittest.skipIf(os.environ.get('NO_NETWORK', '0') == '1', 'No networking, skipping test') def test_cmd_bestprice(self): res = self.call_command('bestprice', ['rifter']) self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) @unittest.skipIf(os.environ.get('NO_NETWORK', '0') == '1', 'No networking, skipping test') def test_cmd_price(self): res = self.call_command('price', args=['jita', 'rifter']) self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) @unittest.skipIf(os.environ.get('NO_NETWORK', '0') == '1', 'No networking, skipping test') def test_cmd_jita(self): res = self.call_command('jita', ['rifter']) self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) @unittest.skipIf(os.environ.get('NO_NETWORK', '0') == '1', 'No networking, skipping test') def test_cmd_amarr(self): res = self.call_command('amarr', ['rifter']) self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) @unittest.skipIf(os.environ.get('NO_NETWORK', '0') == '1', 'No networking, skipping test') def test_cmd_rens(self): res = self.call_command('rens', ['rifter']) self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) @unittest.skipIf(os.environ.get('NO_NETWORK', '0') == '1', 'No networking, skipping test') def test_cmd_dodixie(self): res = self.call_command('dodixie', ['rifter']) self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) @unittest.skipIf(os.environ.get('NO_NETWORK', '0') == '1', 'No networking, skipping test') def test_cmd_uh(self): res = self.call_command('uh', ['rifter']) self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) @unittest.skipIf(os.environ.get('NO_NETWORK', '0') == '1', 'No networking, skipping test') def test_cmd_hek(self): res = self.call_command('hek', ['rifter']) self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) def test_cmd_r(self): pass def test_cmd_redditimg(self): pass @unittest.skipIf(os.environ.get('NO_NETWORK', '0') == '1', 'No networking, skipping test') def test_cmd_kos(self): res = self.call_command('kos', ['Palkark']) self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) def test_cmd_range(self): res = self.call_command('range', ['U-HVIX']) self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) def test_cmd_route(self): res = self.call_command('route', ['Jita', 'Amarr']) self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) def test_cmd_addjb(self): res = self.call_command('addjb', ['Jita', 'Amarr']) self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) self.assertEqual(res[0], 'Done') def test_cmd_listjbs(self): res = self.call_command('listjbs') self.assertIsInstance(res, tuple) self.assertIsNone(res[0], None) self.call_command('addjb', ['Jita', 'Amarr']) res = self.call_command('listjbs') self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) def test_cmd_mapstats(self): res = self.call_command('mapstats') self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) def test_cmd_hit(self): pass def test_cmd_jump(self): pass @unittest.skipIf(os.environ.get('NO_NETWORK', '0') == '1', 'No networking, skipping test') def test_cmd_id(self): pass @unittest.skipIf(os.environ.get('NO_NETWORK', '0') == '1', 'No networking, skipping test') def test_cmd_kill(self): pass def test_cmd_mute(self): self.assertEqual(self.bot.kills_muted, False) res = self.call_command('mute') self.assertIsInstance(res, tuple) self.assertIsInstance(res[0], basestring) self.assertEqual(res[0], 'Killmails muted, posting will resume automatically in 30 minutes') self.assertEqual(self.bot.kills_muted, True) @unittest.skipIf(os.environ.get('NO_NETWORK', '0') == '1', 'No networking, skipping test') def test_cmd_nearestoffice(self): pass def test_cmd_rageping(self): pass def test_jackdaw(self): """ The items in the Carnyx release can be found. """ self.assertEqual(self.bot._item_picker("Jackdaw"), (u'34828', u'Jackdaw')) def test_carnyx_plex(self): self.assertEqual(self.bot._item_picker("plex"), (u"29668", "30 Day Pilot's License Extension (PLEX)"))