# Path: gengine/app/tests/base.py
# class BaseDBTest(unittest.TestCase):
# 
#     @classmethod
#     def setUpClass(cls):
#         if cls is BaseDBTest:
#             raise unittest.SkipTest("Skip BaseTest tests, it's a base class")
#         super(BaseDBTest, cls).setUpClass()
# 
#     def setUp(self):
#         from gengine.app.cache import clear_all_caches
#         clear_all_caches()
# 
#         if os.path.exists("/tmp/test_pgdata"):
#             shutil.rmtree("/tmp/test_pgdata")
# 
#         self.db = testDB.db()
#         dsn = self.db.dsn()
#         self.engine =  create_engine(
#             "postgresql://%(user)s@%(host)s:%(port)s/%(database)s" % {
#                 "user": dsn["user"],
#                 "host": dsn["host"],
#                 "port": dsn["port"],
#                 "database": dsn["database"],
#             }
#         )
#         init_session(override_session=scoped_session(get_sessionmaker(bind=self.engine)), replace=True)
#         from gengine.metadata import Base
#         Base.metadata.bind = self.engine
# 
#         Base.metadata.drop_all(self.engine)
#         self.engine.execute("DROP SCHEMA IF EXISTS public CASCADE")
#         self.engine.execute("CREATE SCHEMA IF NOT EXISTS public")
# 
#         from alembic.config import Config
#         from alembic import command
# 
#         alembic_cfg = Config(attributes={
#             'engine': self.engine,
#             'schema': 'public'
#         })
#         script_location = os.path.join(
#             os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
#             'app/alembic'
#         )
#         alembic_cfg.set_main_option("script_location", script_location)
# 
#         from gengine.app import model
# 
#         tables = [t for name, t in model.__dict__.items() if isinstance(t, Table)]
#         Base.metadata.create_all(self.engine, tables=tables)
# 
#         command.stamp(alembic_cfg, "head")
# 
#     def tearDown(self):
#         self.db.stop()
#         shutil.rmtree("/tmp/test_pgdata")
# 
# Path: gengine/app/tests/helpers.py
# class Undefined():
# def randrange_float(f1,f2):
# def create_subjecttypes():
# def get_user_subjecttype():
# def create_subjects():
# def create_variables():
# def create_achievements():
# def create_subject(
#         name,
#         type,
#         lat=None,
#         lng=None,
#         timezone=None,
#         language=None,
#         additional_public_data={},
#     ):
# def get_or_create_language(name):
# def create_device(
#         subject_id=undefined,
#         device_id=undefined,
#         device_os=undefined,
#         push_id=undefined,
#         app_version=undefined,
#         gen_data=default_device_data
#     ):
# def create_achievement_rewards(achievement):
# def create_variable(name, increase_permission="admin"):
# def default_dt():
# def next_day(dt):
# def next_month(dt):
# def next_week(dt):
# def last_month(dt):


from gengine.app.tests.base import BaseDBTest
from gengine.app.tests.helpers import create_user, create_device, update_device


class TestUserDevice(BaseDBTest):

    def test_create_user_device(self):

        user = create_user()

        device = create_device(
            device_id='3424',
            user_id=user.id,
            device_os='Android',
            push_id='1234',
            app_version='1.1'
        )

        self.assertTrue(device.device_id == '3424')
        self.assertTrue(device.user_id == user.id)
        self.assertTrue(device.device_os == 'Android')
        self.assertTrue(device.push_id == '1234')
        self.assertTrue(device.app_version == '1.1')

    def test_update_user_device(self):

        user = create_user()

# Path: gengine/app/tests/base.py
# class BaseDBTest(unittest.TestCase):
# 
#     @classmethod
#     def setUpClass(cls):
#         if cls is BaseDBTest:
#             raise unittest.SkipTest("Skip BaseTest tests, it's a base class")
#         super(BaseDBTest, cls).setUpClass()
# 
#     def setUp(self):
#         from gengine.app.cache import clear_all_caches
#         clear_all_caches()
# 
#         if os.path.exists("/tmp/test_pgdata"):
#             shutil.rmtree("/tmp/test_pgdata")
# 
#         self.db = testDB.db()
#         dsn = self.db.dsn()
#         self.engine =  create_engine(
#             "postgresql://%(user)s@%(host)s:%(port)s/%(database)s" % {
#                 "user": dsn["user"],
#                 "host": dsn["host"],
#                 "port": dsn["port"],
#                 "database": dsn["database"],
#             }
#         )
#         init_session(override_session=scoped_session(get_sessionmaker(bind=self.engine)), replace=True)
#         from gengine.metadata import Base
#         Base.metadata.bind = self.engine
# 
#         Base.metadata.drop_all(self.engine)
#         self.engine.execute("DROP SCHEMA IF EXISTS public CASCADE")
#         self.engine.execute("CREATE SCHEMA IF NOT EXISTS public")
# 
#         from alembic.config import Config
#         from alembic import command
# 
#         alembic_cfg = Config(attributes={
#             'engine': self.engine,
#             'schema': 'public'
#         })
#         script_location = os.path.join(
#             os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
#             'app/alembic'
#         )
#         alembic_cfg.set_main_option("script_location", script_location)
# 
#         from gengine.app import model
# 
#         tables = [t for name, t in model.__dict__.items() if isinstance(t, Table)]
#         Base.metadata.create_all(self.engine, tables=tables)
# 
#         command.stamp(alembic_cfg, "head")
# 
#     def tearDown(self):
#         self.db.stop()
#         shutil.rmtree("/tmp/test_pgdata")
# 
# Path: gengine/app/tests/helpers.py
# class Undefined():
# def randrange_float(f1,f2):
# def create_subjecttypes():
# def get_user_subjecttype():
# def create_subjects():
# def create_variables():
# def create_achievements():
# def create_subject(
#         name,
#         type,
#         lat=None,
#         lng=None,
#         timezone=None,
#         language=None,
#         additional_public_data={},
#     ):
# def get_or_create_language(name):
# def create_device(
#         subject_id=undefined,
#         device_id=undefined,
#         device_os=undefined,
#         push_id=undefined,
#         app_version=undefined,
#         gen_data=default_device_data
#     ):
# def create_achievement_rewards(achievement):
# def create_variable(name, increase_permission="admin"):
# def default_dt():
# def next_day(dt):
# def next_month(dt):
# def next_week(dt):
# def last_month(dt):


# Path: gengine/app/tests_old/test_device.py
from gengine.app.tests.base import BaseDBTest
from gengine.app.tests.helpers import create_user, create_device, update_device



class TestUserDevice(BaseDBTest):

    def test_create_user_device(self):

        user = create_user()

        device = create_device(
            device_id='3424',
            user_id=user.id,
            device_os='Android',
            push_id='1234',
            app_version='1.1'
        )

        self.assertTrue(device.device_id == '3424')
        self.assertTrue(device.user_id == user.id)
        self.assertTrue(device.device_os == 'Android')
        self.assertTrue(device.push_id == '1234')
        self.assertTrue(device.app_version == '1.1')

    def test_update_user_device(self):

        user = create_user()

        create_device(user_id=user.id)