# Path: lighty/db/backend.py
# class Datastore(object):
# class DatastoreManager(object):
#     def __init__(self, name, db_name, **kwargs):
#     def get(self, model, kwargs):
#     def put(self, model, item):
#     def delete(self, model, **kwargs):
#     def get_datastore_operation(operation, operand=None):
#     def process_operand(operand):
#     def build_query(query):
#     def query(self, query, fields=None):
#     def count(self, query):
#     def slice(self, query, limit=1, offset=0):
#     def __init__(self, default_name='default'):
#     def connect(self, name, **kwargs):
#     def get(self, name=None):
#     def default(self):
#     def swap(self, first_name, second_name=None):
# 
# Path: lighty/db/fields.py
# def add_validator(validator, options):
#     def __init__(self, verbose_name=None, primary_key=False, db_index=False,
#                        unique=False, blank=False, null=False, choices=None,
#                        default=None, editable=True, validators=(),
#                        help_text="", db_column=None, db_tablespace=False):
#     def configure(self, model_name, field_name):
#     def get_value_for_datastore(self, model):
#     def make_value_from_datastore(self, value):
#     def __str__(self, model=None):
#     def configure(self, model_name, field_name):
#     def __get__(self, instance, owner):
#     def __set__(self, instance, value):
#     def __init__(self, **options):
#     def __set__(self, instance, value):
#     def __init__(self, **options):
#     def __init__(self, **options):
#     def __set__(self, instance, value):
#     def __init__(self, max_digits=None, decimal_places=None, **options):
#     def __set__(self, instance, value):
#     def __init__(self, **options):
#     def __set__(self, instance, value):
#     def __init__(self, max_length=None, **options):
#     def __init__(self, max_length=75, **options):
#     def __init__(self, verify_exists=True, max_length=200, **options):
#     def __init__(self, **options):
#     def __init__(self, max_length=50, **options):
#     def __init__(self, auto_now=False, auto_now_add=False, **options):
#     def get_value_for_datastore(self, model):
#     def make_value_from_datastore(self, value):
#     def get_value_for_datastore(self, model):
#     def make_value_from_datastore(self, value):
#     def get_value_for_datastore(self, model):
#     def __init__(self, model, **kwargs):
#     def get_value_for_datastore(self, model):
#     def make_value_from_datastore(self, value):
# class Field(BaseField):
# class FieldDescriptor(Field):
# class IntegerField(FieldDescriptor, NumericField):
# class PositiveIntegerField(IntegerField):
# class AutoField(IntegerField):
# class FloatField(FieldDescriptor, NumericField):
# class DecimalField(Field, NumericField):
# class BooleanField(FieldDescriptor):
# class NullBooleanField(BooleanField):
# class CharField(Field, SequenceField):
# class EmailField(CharField):
# class URLField(CharField):
# class IPAddressField(Field):
# class SlugField(CharField):
# class DateField(Field, NumericField):
# class DateTimeField(DateField, NumericField):
# class TimeField(DateField, NumericField):
# class TextField(Field, SequenceField):
# class ForeignKey(Field):
# 
# Path: lighty/db/models.py
# def get_attr_source(name, cls):
#     def __new__(cls, name, bases, attrs):
#     def __init__(self, is_new=True, **kwds):
#     def datastore(cls):
#     def is_saved(self):
#     def key(self):
#     def put(self):
#     def delete(self):
#     def entity_name(cls):
#     def get(cls, _key=None, **keys):
#     def all(cls):
#     def fields(cls):
#     def validators(cls):
# class ModelBase(type):
# class Model(with_metaclass(ModelBase)):


import unittest
from lighty.db import backend, fields, models
    class TestClass(models.Model):
        _datastore_name = 'test1'
        name = fields.CharField()

    def testBackendSwap(self):
        '''Test database swapping
        '''

        class TestClass(models.Model):
            _datastore_name = 'test2'
            name = fields.CharField()

        # Create and check objects
        DatastoreTestCase.TestClass(name='first').save()
        TestClass(name='second').save()
        first = DatastoreTestCase.TestClass.get(name='first')
        assert first, 'Error putting object into database: %s' % first
        second = TestClass.get(name='second')
        assert second, 'Error putting object into database: %s' % second
        # Swap databases and check again
        backend.manager.swap('test1', 'test2')
        first = DatastoreTestCase.TestClass.get(name='first')
        assert not first, 'Error swapping datastores: %s' % first
        second = TestClass.get(name='second')
        assert not second, 'Error swapping datastores: %s' % second
        first = DatastoreTestCase.TestClass.get(name='second')
        assert first, 'Error swapping datastores: %s' % first
        second = TestClass.get(name='first')
        assert second, 'Error swapping datastores: %s' % second
        # Swap datastores again. Now all must be fine

# Path: lighty/db/backend.py
# class Datastore(object):
# class DatastoreManager(object):
#     def __init__(self, name, db_name, **kwargs):
#     def get(self, model, kwargs):
#     def put(self, model, item):
#     def delete(self, model, **kwargs):
#     def get_datastore_operation(operation, operand=None):
#     def process_operand(operand):
#     def build_query(query):
#     def query(self, query, fields=None):
#     def count(self, query):
#     def slice(self, query, limit=1, offset=0):
#     def __init__(self, default_name='default'):
#     def connect(self, name, **kwargs):
#     def get(self, name=None):
#     def default(self):
#     def swap(self, first_name, second_name=None):
# 
# Path: lighty/db/fields.py
# def add_validator(validator, options):
#     def __init__(self, verbose_name=None, primary_key=False, db_index=False,
#                        unique=False, blank=False, null=False, choices=None,
#                        default=None, editable=True, validators=(),
#                        help_text="", db_column=None, db_tablespace=False):
#     def configure(self, model_name, field_name):
#     def get_value_for_datastore(self, model):
#     def make_value_from_datastore(self, value):
#     def __str__(self, model=None):
#     def configure(self, model_name, field_name):
#     def __get__(self, instance, owner):
#     def __set__(self, instance, value):
#     def __init__(self, **options):
#     def __set__(self, instance, value):
#     def __init__(self, **options):
#     def __init__(self, **options):
#     def __set__(self, instance, value):
#     def __init__(self, max_digits=None, decimal_places=None, **options):
#     def __set__(self, instance, value):
#     def __init__(self, **options):
#     def __set__(self, instance, value):
#     def __init__(self, max_length=None, **options):
#     def __init__(self, max_length=75, **options):
#     def __init__(self, verify_exists=True, max_length=200, **options):
#     def __init__(self, **options):
#     def __init__(self, max_length=50, **options):
#     def __init__(self, auto_now=False, auto_now_add=False, **options):
#     def get_value_for_datastore(self, model):
#     def make_value_from_datastore(self, value):
#     def get_value_for_datastore(self, model):
#     def make_value_from_datastore(self, value):
#     def get_value_for_datastore(self, model):
#     def __init__(self, model, **kwargs):
#     def get_value_for_datastore(self, model):
#     def make_value_from_datastore(self, value):
# class Field(BaseField):
# class FieldDescriptor(Field):
# class IntegerField(FieldDescriptor, NumericField):
# class PositiveIntegerField(IntegerField):
# class AutoField(IntegerField):
# class FloatField(FieldDescriptor, NumericField):
# class DecimalField(Field, NumericField):
# class BooleanField(FieldDescriptor):
# class NullBooleanField(BooleanField):
# class CharField(Field, SequenceField):
# class EmailField(CharField):
# class URLField(CharField):
# class IPAddressField(Field):
# class SlugField(CharField):
# class DateField(Field, NumericField):
# class DateTimeField(DateField, NumericField):
# class TimeField(DateField, NumericField):
# class TextField(Field, SequenceField):
# class ForeignKey(Field):
# 
# Path: lighty/db/models.py
# def get_attr_source(name, cls):
#     def __new__(cls, name, bases, attrs):
#     def __init__(self, is_new=True, **kwds):
#     def datastore(cls):
#     def is_saved(self):
#     def key(self):
#     def put(self):
#     def delete(self):
#     def entity_name(cls):
#     def get(cls, _key=None, **keys):
#     def all(cls):
#     def fields(cls):
#     def validators(cls):
# class ModelBase(type):
# class Model(with_metaclass(ModelBase)):


# Path: tests/db.py
import unittest
from lighty.db import backend, fields, models

    class TestClass(models.Model):
        _datastore_name = 'test1'
        name = fields.CharField()

    def testBackendSwap(self):
        '''Test database swapping
        '''

        class TestClass(models.Model):
            _datastore_name = 'test2'
            name = fields.CharField()

        # Create and check objects
        DatastoreTestCase.TestClass(name='first').save()
        TestClass(name='second').save()
        first = DatastoreTestCase.TestClass.get(name='first')
        assert first, 'Error putting object into database: %s' % first
        second = TestClass.get(name='second')
        assert second, 'Error putting object into database: %s' % second
        # Swap databases and check again
        backend.manager.swap('test1', 'test2')
        first = DatastoreTestCase.TestClass.get(name='first')
        assert not first, 'Error swapping datastores: %s' % first
        second = TestClass.get(name='second')
        assert not second, 'Error swapping datastores: %s' % second
        first = DatastoreTestCase.TestClass.get(name='second')
        assert first, 'Error swapping datastores: %s' % first
        second = TestClass.get(name='first')
        assert second, 'Error swapping datastores: %s' % second
        # Swap datastores again. Now all must be fine

        backend.manager.swap('test1', 'test2')