Example #1
0
File: dbt.py Project: n37r06u3/Leaf
 def setUp(self):
     db.setup('localhost', 'test', 'test', 'leaf', pool_opt={'minconn': 3, 'maxconn': 10}, key='slave')
     db.execute('DROP TABLE IF EXISTS `users`', key='slave')
     res = db.execute("""CREATE TABLE `users` (
             `uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
             `name` varchar(20) NOT NULL,
             PRIMARY KEY (`uid`))""", key='slave')
     rows = []
     for _ in range(1, 10):
         rows.append('(%d , "name_%d")' % (_,  _))
     db.execute('INSERT INTO users VALUES ' + ', '.join(rows), key='slave')
Example #2
0
File: dbt.py Project: n37r06u3/Leaf
   def setUp(self):
       db.setup("localhost", "test", "test", "leaf", pool_opt={"minconn": 3, "maxconn": 10})
       db.execute("DROP TABLE IF EXISTS `users`")
       res = db.execute(
           """CREATE TABLE `users` (
 				`uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
 				`name` varchar(20) NOT NULL,
 				PRIMARY KEY (`uid`))"""
       )
       rows = []
       for _ in range(1, 100):
           rows.append('(%d , "name_%d")' % (_, _))
       db.execute("INSERT INTO users VALUES " + ", ".join(rows))
Example #3
0
from leaf import db

import log
from leaf.thing.job import JobThing
from leaf.thing.base import LeaderboardThing
from leaf.model import Job, Leaderboard
from datetime import datetime

import unittest


#log.setdebug(True)
db.setup('localhost', 'test', 'test', 'leaf', pool_opt={'minconn': 3, 'maxconn': 10})

class JobThingTest(unittest.TestCase):

    def setUp(self):
        db.execute("DELETE FROM cron WHERE name like 'job%'")
        db.execute('INSERT INTO cron VALUES (1, NULL, %s, %s, NULL, NULL)', ('job_name1', 'every 10'))
        db.execute('INSERT INTO cron VALUES (2, "job_id", %s, %s, NULL, NULL)', ('job_name2', 'every 10'))
        self.jobthing = JobThing()
        self.job = Job(3,  'job_3', 'job_name3', 'every 5')

    def tearDown(self):
        db.execute("DELETE FROM cron WHERE name like 'job%'")

    def test_find(self):
        job = self.jobthing.find('job_name1')
        self.assertEquals((job.name, job.event), ('job_name1', 'every 10'))

        # not exists
Example #4
0
from leaf import db

import log
from leaf.thing import thing_setup
from leaf.leaderboard import leaderboard


import unittest
import data

db.setup("localhost", "test", "test", "leaf", pool_opt={"minconn": 3, "maxconn": 10})
thing_setup()


class LeaderboardTest(unittest.TestCase):
    def setUp(self):
        data.up(lid=2)

    def tearDown(self):
        data.down(lid=2)

    def test_leaderboard(self):
        lb = leaderboard(2)
        self.assertTrue(lb)
        lb = leaderboard(name="unittest")
        self.assertTrue(lb)
        lb = leaderboard(name="not_found")
        self.assertFalse(lb)


if __name__ == "__main__":
Example #5
0
from leaf import db

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


def create_lb(lid=2, name='unittest'):
    r = db.query_one('SELECT lid from leaderboards WHERE lid=%s', (lid, ))
    if r:
        return False
    db.execute('INSERT INTO leaderboards VALUES(%s, %s, "base")', (
        lid,
        name,
    ))
    return True


def make_entries(lid=2, total=1000000):
    to = 0
    rows = []
    for uid in range(1, total + 1):
        data = r'{\"user\": \"user_%d\"}' % (uid)
        rows.append('(%d, %d, %d, "%s", "2014-08-17 12:49:01")' %
                    (uid, lid, (total - uid) / 3, data))
        if len(rows) == 1000: