def test_copy_custom_data(self):
        migrator = ApplicationMigrator(destination_client=self.dst, source_application=self.app)
        copied_app = migrator.copy_app()
        copied_data = migrator.copy_custom_data()

        self.assertEqual(copied_data['hi'], 'there')
        copied_app.delete()
    def test_copy_oauth_policy(self):
        migrator = ApplicationMigrator(destination_client=self.dst, source_application=self.app)
        copied_app = migrator.copy_app()
        copied_policy = migrator.copy_oauth_policy()

        self.assertEqual(copied_policy.access_token_ttl, timedelta(hours=2))
        self.assertEqual(copied_policy.refresh_token_ttl, timedelta(hours=24))
        copied_app.delete()
    def test_copy_app(self):
        migrator = ApplicationMigrator(destination_client=self.dst, source_application=self.app)
        copied_app = migrator.copy_app()

        self.assertEqual(copied_app.description, self.app.description)
        self.assertEqual(copied_app.name, self.app.name)
        self.assertEqual(copied_app.status, self.app.status)

        copied_app.delete()
    def test_migrate(self):
        migrator = ApplicationMigrator(destination_client=self.dst, source_application=self.app)
        copied_app = migrator.migrate()
        copied_data = copied_app.custom_data
        copied_policy = copied_app.oauth_policy

        self.assertEqual(copied_app.description, self.app.description)
        self.assertEqual(copied_app.name, self.app.name)
        self.assertEqual(copied_app.status, self.app.status)
        self.assertEqual(copied_data['hi'], 'there')
        self.assertEqual(copied_policy.access_token_ttl, timedelta(hours=2))
        self.assertEqual(copied_policy.refresh_token_ttl, timedelta(hours=24))

        copied_app.delete()
    def setUp(self):
        self.src = Client(id=SRC_CLIENT_ID, secret=SRC_CLIENT_SECRET)
        self.dst = Client(id=DST_CLIENT_ID, secret=DST_CLIENT_SECRET)

        self.src_app = self.src.applications.create({'name': uuid4().hex})
        self.src_dir = self.src.directories.create({'name': uuid4().hex})
        self.src_org = self.src.organizations.create({'name': uuid4().hex, 'name_key': uuid4().hex})
        self.src_group = self.src_dir.groups.create({'name': uuid4().hex})

        migrator = ApplicationMigrator(destination_client=self.dst, source_application=self.src_app)
        self.dst_app = migrator.migrate()

        migrator = DirectoryMigrator(destination_client=self.dst, source_directory=self.src_dir)
        self.dst_dir = migrator.migrate()

        migrator = OrganizationMigrator(destination_client=self.dst, source_organization=self.src_org)
        self.dst_org = migrator.migrate()

        migrator = GroupMigrator(destination_directory=self.dst_dir, source_group=self.src_group)
        self.dst_group = migrator.migrate()

        self.src_mapping_1 = self.src_app.account_store_mappings.create({
            'application': self.src_app,
            'account_store': self.src_dir,
            'list_index': 0,
            'is_default_account_store': True,
            'is_default_group_store': True,
        })

        self.src_mapping_2 = self.src_app.account_store_mappings.create({
            'application': self.src_app,
            'account_store': self.src_org,
            'list_index': 1,
            'is_default_account_store': False,
            'is_default_group_store': False,
        })

        self.src_mapping_3 = self.src_app.account_store_mappings.create({
            'application': self.src_app,
            'account_store': self.src_group,
            'list_index': 2,
            'is_default_account_store': False,
            'is_default_group_store': False,
        })
 def test_get_oauth_policy(self):
     migrator = ApplicationMigrator(destination_client=self.dst, source_application=self.app)
     oauth_policy = migrator.get_oauth_policy()
     self.assertTrue(oauth_policy)
     self.assertEqual(oauth_policy.access_token_ttl, timedelta(hours=2))
     self.assertEqual(oauth_policy.refresh_token_ttl, timedelta(hours=24))