Exemple #1
0
 def setUp(self):
     setattr(db, '__connections', {})
     db.setup('localhost',
              'test',
              'test',
              'test',
              pool_opt={
                  'minconn': 3,
                  'maxconn': 10
              },
              key='test')
     db.setup('localhost',
              'test',
              'test',
              'test',
              pool_opt={
                  'minconn': 3,
                  'maxconn': 10
              },
              key='test',
              slave=True)
     db.execute('DROP TABLE IF EXISTS `users`', key='test')
     res = db.execute("""CREATE TABLE `users` (
             `uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
             `name` varchar(20) NOT NULL,
             PRIMARY KEY (`uid`))""",
                      key='test')
     rows = []
     for _ in range(1, 10):
         rows.append('(%d , "name_%d")' % (_, _))
     db.execute('INSERT INTO users VALUES ' + ', '.join(rows), key='test')
Exemple #2
0
 def setUp(self):
     setattr(db, '__connections', {})
     db.setup('localhost', 'test', 'test', 'eden',
              pool_opt={'minconn': 3, 'maxconn': 10})
     self.task = Task(
         None, 'task_id', 'job_test', 'job.test', {'args': (), 'kw': {}}, 'every 5')
     Backend('task').delete_by_name('job_test')
     Backend('task').save(self.task)
Exemple #3
0
 def setUp(self):
     setattr(db, '__connections', {})
     db.setup('localhost', 'test', 'test', 'eden',
              pool_opt={'minconn': 3, 'maxconn': 10})
     self.user = User('username', 'email', 'real_name', 'password', 'active')
     db.execute('DELETE FROM users WHERE email=%s or email=%s',
                (self.user.email, 'email2'))
     Backend('user').save(self.user)
     self.uid = db.query_one('SELECT uid FROM users WHERE email=%s', (self.user.email,))[0]
Exemple #4
0
 def setUp(self):
     setattr(db, '__connections', {})
     db.setup('localhost', 'test', 'test', 'test', pool_opt={'minconn': 3, 'maxconn': 10}, key='test')
     db.setup('localhost', 'test', 'test', 'test', pool_opt={'minconn': 3, 'maxconn': 10}, key='test', slave=True)
     db.execute('DROP TABLE IF EXISTS `users`', key='test')
     res = db.execute("""CREATE TABLE `users` (
             `uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
             `name` varchar(20) NOT NULL,
             PRIMARY KEY (`uid`))""", key='test')
     rows = []
     for _ in range(1, 10):
         rows.append('(%d , "name_%d")' % (_,  _))
     db.execute('INSERT INTO users VALUES ' + ', '.join(rows), key='test')
Exemple #5
0
 def setUp(self):
     setattr(db, '__connections', {})
     db.setup('localhost',
              'test',
              'test',
              'eden',
              pool_opt={
                  'minconn': 3,
                  'maxconn': 10
              })
     self.task = Task(None, 'task_id', 'job_test', 'job.test', {
         'args': (),
         'kw': {}
     }, 'every 5')
     Backend('task').delete_by_name('job_test')
     Backend('task').save(self.task)
Exemple #6
0
 def setUp(self):
     setattr(db, '__connections', {})
     db.setup('localhost',
              'test',
              'test',
              'eden',
              pool_opt={
                  'minconn': 3,
                  'maxconn': 10
              })
     self.user = User('username', 'email', 'real_name', 'password',
                      'active')
     db.execute('DELETE FROM users WHERE email=%s or email=%s',
                (self.user.email, 'email2'))
     Backend('user').save(self.user)
     self.uid = db.query_one('SELECT uid FROM users WHERE email=%s',
                             (self.user.email, ))[0]
Exemple #7
0
 def test_dup_key(self):
     db.setup('localhost',
              'test',
              'test',
              'test',
              pool_opt={
                  'minconn': 3,
                  'maxconn': 10
              })
     f = lambda: db.setup('localhost',
                          'test',
                          'test',
                          'test',
                          pool_opt={
                              'minconn': 3,
                              'maxconn': 10
                          })
     self.assertRaises(db.DBError, f)
Exemple #8
0
    def test_invalid_key(self):
        f = lambda: db.setup('localhost',
                             'test',
                             'test',
                             'test',
                             pool_opt={
                                 'minconn': 3,
                                 'maxconn': 10
                             },
                             key='dd.xx')

        self.assertRaises(TypeError, f)
Exemple #9
0
    def test_database(self):
        db.setup('localhost', 'test', 'test', 'test', pool_opt={'minconn': 3, 'maxconn': 10})
        self.assertEqual(db.database(), db.database('default.slave'))
        conns = getattr(db, '__connections', [])
        self.assertEqual(len(conns['default.slave']), 1)

        db.setup('localhost', 'test', 'test', 'test', pool_opt={'minconn': 3, 'maxconn': 10}, slave=True)
        self.assertNotEqual(db.database(), db.database('default.slave'))
        conns = getattr(db, '__connections', [])
        self.assertEqual(len(conns['default.slave']), 1)

        db.setup('localhost', 'test', 'test', 'test', pool_opt={'minconn': 3, 'maxconn': 10}, slave=True)
        conns = getattr(db, '__connections', [])
        self.assertEqual(len(conns['default.slave']), 2)
Exemple #10
0
    def test_database(self):
        db.setup('localhost',
                 'test',
                 'test',
                 'test',
                 pool_opt={
                     'minconn': 3,
                     'maxconn': 10
                 })
        self.assertEqual(db.database(), db.database('default.slave'))
        conns = getattr(db, '__connections', [])
        self.assertEqual(len(conns['default.slave']), 1)

        db.setup('localhost',
                 'test',
                 'test',
                 'test',
                 pool_opt={
                     'minconn': 3,
                     'maxconn': 10
                 },
                 slave=True)
        self.assertNotEqual(db.database(), db.database('default.slave'))
        conns = getattr(db, '__connections', [])
        self.assertEqual(len(conns['default.slave']), 1)

        db.setup('localhost',
                 'test',
                 'test',
                 'test',
                 pool_opt={
                     'minconn': 3,
                     'maxconn': 10
                 },
                 slave=True)
        conns = getattr(db, '__connections', [])
        self.assertEqual(len(conns['default.slave']), 2)
Exemple #11
0
import logging
from eden.server import EdenWebServer
import os.path

from eden import db

db.setup('localhost',
         'test',
         'test',
         'eden',
         pool_opt={
             'minconn': 3,
             'maxconn': 10
         })


def run(host='localhost', port=80, use_gevent=False, debug=False):
    setdebug(debug)
    EdenWebServer(host=host,
                  port=port,
                  use_gevent=use_gevent,
                  mako_cache_dir=os.path.join(
                      os.path.dirname(os.path.dirname(__file__)), 'cache'),
                  debug=debug).serve_forever()


def setdebug(debug=False):

    level = logging.DEBUG if debug else logging.INFO
    logging.basicConfig(level=level,
                        format='%(asctime)s %(levelname)-8s %(message)s',
Exemple #12
0
 def get_date(url, session='xxx'):
     date = None
     try:
         r = urllib2.urlopen(url)
         date = r.info().dict['date']
     except:
         LOGGER.info('open failed')
     LOGGER.info('session: %s, date:%s,', session, date)
  
 def setdebug(debug=False):
     level = logging.DEBUG if debug else logging.INFO
     logging.basicConfig(level=level,
                             format='%(asctime)s %(levelname)-8s %(message)s',
                             datefmt='%Y-%m-%d %H:%M:%S', filemode='a+')
 setdebug(False)
 db.setup('localhost', 'test', 'test', 'eden',
     pool_opt={'minconn': 3, 'maxconn': 10})
  
 app = App()
 app.add_task('task.test', get_date)
 scheduler = Scheduler(app, 20, 20, 100)
  
 db.execute('delete from cron')
 for i in range(100):
     if i % 2 == 0:
         print i
         action = 'task.not_found'
     else:
         action = 'task.test'
     scheduler.add_task('name_%d' %(i), 'every 2', action, datetime.now(), 'http://www.google.com', session=i)
 scheduler.run()
Exemple #13
0
    def test_invalid_key(self):
        f = lambda: db.setup('localhost', 'test', 'test', 'test', pool_opt={'minconn': 3, 'maxconn': 10}, key='dd.xx')

        self.assertRaises(TypeError, f)
Exemple #14
0
 def test_dup_key(self):
     db.setup('localhost', 'test', 'test', 'test', pool_opt={'minconn': 3, 'maxconn': 10})
     f = lambda: db.setup('localhost', 'test', 'test', 'test', pool_opt={'minconn': 3, 'maxconn': 10})
     self.assertRaises(db.DBError, f)