@@ -0,0 +1,2808 @@
+from nose.tools import *%0A%0Afrom scripts.box.migrate_to_external_account import do_migration, get_targets%0A%0Afrom framework.auth import Auth%0A%0Afrom tests.base import OsfTestCase%0Afrom tests.factories import ProjectFactory, UserFactory%0A%0Afrom website.addons.box.model import BoxUserSettings%0Afrom website.addons.box.tests.factories import BoxOAuthSettingsFactory%0A%0A%0Aclass TestBoxMigration(OsfTestCase):%0A    # Note: BoxUserSettings.user_settings has to be changed to foreign_user_settings (model and mongo). See migration instructions%0A%0A    def test_migration_no_project(self):%0A%0A        user = UserFactory()%0A%0A        user.add_addon('box')%0A        user_addon = user.get_addon('box')%0A        user_addon.oauth_settings = BoxOAuthSettingsFactory()%0A        user_addon.save()%0A%0A        do_migration(%5Buser_addon%5D)%0A        user_addon.reload()%0A%0A        assert_is_none(user_addon.oauth_settings)%0A        assert_equal(len(user.external_accounts), 1)%0A%0A        account = user.external_accounts%5B0%5D%0A        assert_equal(account.provider, 'box')%0A        assert_equal(account.oauth_key, 'abcdef1')%0A%0A    def test_migration_removes_targets(self):%0A        BoxUserSettings.remove()%0A%0A        user = UserFactory()%0A        project = ProjectFactory(creator=user)%0A%0A        user.add_addon('box', auth=Auth(user))%0A        user_addon = user.get_addon('box')%0A        user_addon.oauth_settings = BoxOAuthSettingsFactory()%0A        user_addon.save()%0A%0A        project.add_addon('box', auth=Auth(user))%0A        node_addon = project.get_addon('box')%0A        node_addon.foreign_user_settings = user_addon%0A        node_addon.save()%0A%0A        assert_equal(get_targets().count(), 1)%0A%0A        do_migration(%5Buser_addon%5D)%0A        user_addon.reload()%0A%0A        assert_equal(get_targets().count(), 0)%0A%0A    def test_migration_multiple_users(self):%0A        user1 = UserFactory()%0A        user2 = UserFactory()%0A        oauth_settings = BoxOAuthSettingsFactory()%0A%0A        user1.add_addon('box')%0A        user1_addon = user1.get_addon('box')%0A        user1_addon.oauth_settings = oauth_settings%0A        user1_addon.save()%0A%0A        user2.add_addon('box')%0A        user2_addon = user2.get_addon('box')%0A        user2_addon.oauth_settings = oauth_settings%0A        user2_addon.save()%0A%0A        do_migration(%5Buser1_addon, user2_addon%5D)%0A        user1_addon.reload()%0A        user2_addon.reload()%0A%0A        assert_equal(%0A            user1.external_accounts%5B0%5D,%0A            user2.external_accounts%5B0%5D,%0A        )%0A%0A    def test_get_targets(self):%0A        BoxUserSettings.remove()%0A        addons = %5B%0A            BoxUserSettings(),%0A            BoxUserSettings(oauth_settings=BoxOAuthSettingsFactory()),%0A        %5D%0A        for addon in addons:%0A            addon.save()%0A        targets = get_targets()%0A        assert_equal(targets.count(), 1)%0A        assert_equal(targets%5B0%5D._id, addons%5B-1%5D._id)%0A

Add test for box migration script