# Path: web/tasks.py
# MAX_LOCK_AGE = 10 * 60
# def ensure_dir(path):
# def progress(fname, downloaded, size):
# def sync_dbs():
# def lock_watch():
# def download_dbs():
# def cached_db(state):
# def scan_database_dir(state):
# def relations():
# def schema(relation_name):
# def query(statement):
# def execute(cols=None, where=None, limit=100, offset=0, order_by=[]):
# def ticks():


import os
import shutil
import tempfile
import splicer_discodb
from unittest import TestCase
from discodb import DiscoDB
from nose.tools import *
from web import tasks
  def tearDown(self):
    shutil.rmtree(self.tmp_dir)
    os.environ['DATA_DB_PATH'] = self._old_db_path

  def create_db(self, name, data):
    db_path = os.path.join(os.environ['DATA_DB_PATH'], name + '.db')
    data = DiscoDB(data)
    data.dump(open(db_path, 'w'))
    return db_path
  
  def create_db2(self, name, fields, data):
    db_path = os.path.join(os.environ['DATA_DB_PATH'], name + '.db')
    schema = dict(
      name=name,
      fields=fields
    )

    db = splicer_discodb.create(db_path, schema, data)
    db.dump(open(db_path, 'w'))

  def test_scan_database_dir(self):
    state = dict(
      dbs={},
    )

    db_path = self.create_db(
      'test',
      [("A", "1"), ("A", "2"), ("B","1")]
    )


# Path: web/tasks.py
# MAX_LOCK_AGE = 10 * 60
# def ensure_dir(path):
# def progress(fname, downloaded, size):
# def sync_dbs():
# def lock_watch():
# def download_dbs():
# def cached_db(state):
# def scan_database_dir(state):
# def relations():
# def schema(relation_name):
# def query(statement):
# def execute(cols=None, where=None, limit=100, offset=0, order_by=[]):
# def ticks():


# Path: web/tests/test_tasks.py
import os
import shutil
import tempfile
import splicer_discodb
from unittest import TestCase
from discodb import DiscoDB
from nose.tools import *
from web import tasks

  def tearDown(self):
    shutil.rmtree(self.tmp_dir)
    os.environ['DATA_DB_PATH'] = self._old_db_path

  def create_db(self, name, data):
    db_path = os.path.join(os.environ['DATA_DB_PATH'], name + '.db')
    data = DiscoDB(data)
    data.dump(open(db_path, 'w'))
    return db_path
  
  def create_db2(self, name, fields, data):
    db_path = os.path.join(os.environ['DATA_DB_PATH'], name + '.db')
    schema = dict(
      name=name,
      fields=fields
    )

    db = splicer_discodb.create(db_path, schema, data)
    db.dump(open(db_path, 'w'))

  def test_scan_database_dir(self):
    state = dict(
      dbs={},
    )

    db_path = self.create_db(
      'test',
      [("A", "1"), ("A", "2"), ("B","1")]
    )


    state = tasks.scan_database_dir(state)