# Path: syncano_cli/config.py
# ACCOUNT_CONFIG = ConfigParser()
# 
# Path: syncano_cli/main.py
# def main():
# 
# Path: syncano_cli/parse_to_syncano/processors/push_notifications.py
# DEVICE_CHANNELS_CLASS_NAME = 'internal_device_channels'
# 
# Path: tests/base.py
# class InstanceMixin(object):
# 
#     @classmethod
#     def setUpClass(cls):
#         super(InstanceMixin, cls).setUpClass()
# 
#         cls.instance = cls.connection.Instance.please.create(
#             name='test-cli-i%s' % cls.generate_hash()[:10],
#             description='IntegrationTest %s' % datetime.now(),
#         )
# 
#     @classmethod
#     def tearDownClass(cls):
#         cls.instance.delete()
#         super(InstanceMixin, cls).tearDownClass()
# 
# class IntegrationTest(unittest.TestCase):
# 
#     @classmethod
#     def setUpClass(cls):
#         cls.runner = CliRunner()
#         cls.API_KEY = os.getenv('INTEGRATION_API_KEY')
#         cls.API_EMAIL = os.getenv('INTEGRATION_API_EMAIL')
#         cls.API_PASSWORD = os.getenv('INTEGRATION_API_PASSWORD')
#         cls.API_ROOT = os.getenv('INTEGRATION_API_ROOT')
# 
#         cls.connection = syncano.connect(
#             host=cls.API_ROOT,
#             email=cls.API_EMAIL,
#             password=cls.API_PASSWORD,
#             api_key=cls.API_KEY
#         )
# 
#     @classmethod
#     def tearDownClass(cls):
#         cls.connection = None
# 
#     @classmethod
#     def generate_hash(cls):
#         hash_feed = '{}{}'.format(uuid4(), datetime.now())
#         return md5(hash_feed.encode('ascii')).hexdigest()


import json
import mock
from syncano_cli.config import ACCOUNT_CONFIG
from syncano_cli.main import cli
from syncano_cli.parse_to_syncano.processors.push_notifications import DEVICE_CHANNELS_CLASS_NAME
from tests.base import InstanceMixin, IntegrationTest

        with open('tests/json_migrate_mocks/installations.json', 'r+') as f:
            parse_installations = json.loads(f.read())

        # remove blu_bla Class from Classes;
        classes['results'] = classes['results'][1:]
        # Class schemas, objects, break the objects fetch, installations
        request_mock.side_effect = [classes, objects, {'results': []}, parse_installations]

        self.assertFalse(request_mock.called)
        self.runner.invoke(cli, args=['migrate', 'parse'], obj={}, input='y\n')
        self.assertTrue(request_mock.called)

        objects_list = self.instance.classes.get(name='test_class_1234').objects.all()
        self.assertEqual(len([data_object for data_object in objects_list]), 10)

        object_to_test = self.instance.classes.get(name='test_class_1234').objects.filter(
            objectid__eq='ZfowBYpvpw'
        ).first()

        self.assertListEqual(object_to_test.testarray, ["a", "b", "c", "d"])
        self.assertEqual(object_to_test.barg, 12)
        self.assertEqual(object_to_test.carg, True)

        apns_devices = self.instance.apns_devices.all()
        gcm_devices = self.instance.gcm_devices.all()

        self.assertEqual(len([apns_d for apns_d in apns_devices]), 1)
        self.assertEqual(len([gcm_d for gcm_d in gcm_devices]), 1)


# Path: syncano_cli/config.py
# ACCOUNT_CONFIG = ConfigParser()
# 
# Path: syncano_cli/main.py
# def main():
# 
# Path: syncano_cli/parse_to_syncano/processors/push_notifications.py
# DEVICE_CHANNELS_CLASS_NAME = 'internal_device_channels'
# 
# Path: tests/base.py
# class InstanceMixin(object):
# 
#     @classmethod
#     def setUpClass(cls):
#         super(InstanceMixin, cls).setUpClass()
# 
#         cls.instance = cls.connection.Instance.please.create(
#             name='test-cli-i%s' % cls.generate_hash()[:10],
#             description='IntegrationTest %s' % datetime.now(),
#         )
# 
#     @classmethod
#     def tearDownClass(cls):
#         cls.instance.delete()
#         super(InstanceMixin, cls).tearDownClass()
# 
# class IntegrationTest(unittest.TestCase):
# 
#     @classmethod
#     def setUpClass(cls):
#         cls.runner = CliRunner()
#         cls.API_KEY = os.getenv('INTEGRATION_API_KEY')
#         cls.API_EMAIL = os.getenv('INTEGRATION_API_EMAIL')
#         cls.API_PASSWORD = os.getenv('INTEGRATION_API_PASSWORD')
#         cls.API_ROOT = os.getenv('INTEGRATION_API_ROOT')
# 
#         cls.connection = syncano.connect(
#             host=cls.API_ROOT,
#             email=cls.API_EMAIL,
#             password=cls.API_PASSWORD,
#             api_key=cls.API_KEY
#         )
# 
#     @classmethod
#     def tearDownClass(cls):
#         cls.connection = None
# 
#     @classmethod
#     def generate_hash(cls):
#         hash_feed = '{}{}'.format(uuid4(), datetime.now())
#         return md5(hash_feed.encode('ascii')).hexdigest()


# Path: tests/test_migrate_commands.py
import json
import mock
from syncano_cli.config import ACCOUNT_CONFIG
from syncano_cli.main import cli
from syncano_cli.parse_to_syncano.processors.push_notifications import DEVICE_CHANNELS_CLASS_NAME
from tests.base import InstanceMixin, IntegrationTest


        with open('tests/json_migrate_mocks/installations.json', 'r+') as f:
            parse_installations = json.loads(f.read())

        # remove blu_bla Class from Classes;
        classes['results'] = classes['results'][1:]
        # Class schemas, objects, break the objects fetch, installations
        request_mock.side_effect = [classes, objects, {'results': []}, parse_installations]

        self.assertFalse(request_mock.called)
        self.runner.invoke(cli, args=['migrate', 'parse'], obj={}, input='y\n')
        self.assertTrue(request_mock.called)

        objects_list = self.instance.classes.get(name='test_class_1234').objects.all()
        self.assertEqual(len([data_object for data_object in objects_list]), 10)

        object_to_test = self.instance.classes.get(name='test_class_1234').objects.filter(
            objectid__eq='ZfowBYpvpw'
        ).first()

        self.assertListEqual(object_to_test.testarray, ["a", "b", "c", "d"])
        self.assertEqual(object_to_test.barg, 12)
        self.assertEqual(object_to_test.carg, True)

        apns_devices = self.instance.apns_devices.all()
        gcm_devices = self.instance.gcm_devices.all()

        self.assertEqual(len([apns_d for apns_d in apns_devices]), 1)
        self.assertEqual(len([gcm_d for gcm_d in gcm_devices]), 1)


        channels_class = self.instance.classes.get(name=DEVICE_CHANNELS_CLASS_NAME)