# Path: bibserver/dao.py
# def make_id(data):
# def init_db():
# def get_conn():
#     def __init__(self, **kwargs):
#     def id(self):
#     def version(self):
#     def save(self):
#     def delete(self):
#     def get(cls, id_):
#     def get_mapping(cls):
#     def get_facets_from_mapping(cls,mapping=False,prefix=''):
#     def upsert(cls, data, state=None):
#     def bulk_upsert(cls, dataset, state=None):
#     def delete_by_query(cls, query):
#     def query(cls, q='', terms=None, facet_fields=None, flt=False, default_operator='AND', **kwargs):
#     def raw_query(self, query_string):
#     def about(cls, id_):
#     def records(self):
#     def get_by_owner_coll(cls,owner,coll):
#     def delete(self):
#     def __len__(self):
#     def set_password(self, password):
#     def check_password(self, password):
#     def is_super(self):
#     def collections(self):
#     def notes(self):
#     def delete(self):
# class InvalidDAOIDException(Exception):
# class DomainObject(UserDict.IterableUserDict):
# class Record(DomainObject):
# class Note(DomainObject):
# class Collection(DomainObject):
# class Account(DomainObject, UserMixin):


from base import fixtures, Fixtures, TESTDB
from bibserver import ingest, dao
from bibserver.config import config
import bibserver.dao as dao
import nose.tools
import os, json, subprocess

class TestIngest:
    @classmethod
    def setup_class(cls):
        Fixtures.create_account()
        config['download_cache_directory'] = 'test/data/downloads'
        # initialise the plugins
        ingest.init()
        assert 'bibtex' in ingest.PLUGINS

    @classmethod
    def teardown_class(cls):
        conn, db = dao.get_conn()
        conn.delete_index(TESTDB)
        for x in os.listdir('test/data/downloads'):
            os.unlink(os.path.join('test/data/downloads', x))
        os.rmdir('test/data/downloads')

    @nose.tools.raises(ingest.IngestTicketInvalidInit)
    def test_params(self):
        t = ingest.IngestTicket(owner='tester')

    @nose.tools.raises(ingest.IngestTicketInvalidOwnerException)
    def test_owner_none(self):
        t = ingest.IngestTicket(owner=None, 
                                    collection='test', format='json', source_url='')

    def test_owner_valid_01(self):

# Path: bibserver/dao.py
# def make_id(data):
# def init_db():
# def get_conn():
#     def __init__(self, **kwargs):
#     def id(self):
#     def version(self):
#     def save(self):
#     def delete(self):
#     def get(cls, id_):
#     def get_mapping(cls):
#     def get_facets_from_mapping(cls,mapping=False,prefix=''):
#     def upsert(cls, data, state=None):
#     def bulk_upsert(cls, dataset, state=None):
#     def delete_by_query(cls, query):
#     def query(cls, q='', terms=None, facet_fields=None, flt=False, default_operator='AND', **kwargs):
#     def raw_query(self, query_string):
#     def about(cls, id_):
#     def records(self):
#     def get_by_owner_coll(cls,owner,coll):
#     def delete(self):
#     def __len__(self):
#     def set_password(self, password):
#     def check_password(self, password):
#     def is_super(self):
#     def collections(self):
#     def notes(self):
#     def delete(self):
# class InvalidDAOIDException(Exception):
# class DomainObject(UserDict.IterableUserDict):
# class Record(DomainObject):
# class Note(DomainObject):
# class Collection(DomainObject):
# class Account(DomainObject, UserMixin):


# Path: test/test_ingest.py
from base import fixtures, Fixtures, TESTDB
from bibserver import ingest, dao
from bibserver.config import config
import bibserver.dao as dao
import nose.tools
import os, json, subprocess


class TestIngest:
    @classmethod
    def setup_class(cls):
        Fixtures.create_account()
        config['download_cache_directory'] = 'test/data/downloads'
        # initialise the plugins
        ingest.init()
        assert 'bibtex' in ingest.PLUGINS

    @classmethod
    def teardown_class(cls):
        conn, db = dao.get_conn()
        conn.delete_index(TESTDB)
        for x in os.listdir('test/data/downloads'):
            os.unlink(os.path.join('test/data/downloads', x))
        os.rmdir('test/data/downloads')

    @nose.tools.raises(ingest.IngestTicketInvalidInit)
    def test_params(self):
        t = ingest.IngestTicket(owner='tester')

    @nose.tools.raises(ingest.IngestTicketInvalidOwnerException)
    def test_owner_none(self):
        t = ingest.IngestTicket(owner=None, 
                                    collection='test', format='json', source_url='')

    def test_owner_valid_01(self):

        unknown_owner = dao.Account.get('moocow')