<s> from nose . tools import * <EOL> from scripts . dataverse . migrate_to_external_account import do_migration , get_targets <EOL> from framework . auth import Auth <EOL> from tests . base import OsfTestCase <EOL> from tests . factories import ProjectFactory , UserFactory <EOL> from website . addons . dataverse . model import AddonDataverseUserSettings <EOL> class TestDatasetMigration ( OsfTestCase ) : <EOL> def test_migration_no_project ( self ) : <EOL> user = UserFactory ( ) <EOL> api_token = '<STR_LIT>' <EOL> user . add_addon ( '<STR_LIT>' ) <EOL> user_addon = user . get_addon ( '<STR_LIT>' ) <EOL> user_addon . api_token = api_token <EOL> user_addon . save ( ) <EOL> do_migration ( [ user_addon ] , dry = False ) <EOL> user_addon . reload ( ) <EOL> assert_is_none ( user_addon . api_token ) <EOL> assert_equal ( len ( user_addon . external_accounts ) , <NUM_LIT:1> ) <EOL> account = user_addon . external_accounts [ <NUM_LIT:0> ] <EOL> assert_equal ( account . provider , '<STR_LIT>' ) <EOL> assert_equal ( account . oauth_key , '<STR_LIT>' ) <EOL> assert_equal ( account . oauth_secret , api_token ) <EOL> def test_migration_includes_project ( self ) : <EOL> user = UserFactory ( ) <EOL> project = ProjectFactory ( creator = user ) <EOL> api_token = '<STR_LIT>' <EOL> user . add_addon ( '<STR_LIT>' , auth = Auth ( user ) ) <EOL> user_addon = user . get_addon ( '<STR_LIT>' ) <EOL> user_addon . api_token = api_token <EOL> user_addon . save ( ) <EOL> project . add_addon ( '<STR_LIT>' , auth = Auth ( user ) ) <EOL> node_addon = project . get_addon ( '<STR_LIT>' ) <EOL> node_addon . user_settings = user_addon <EOL> node_addon . save ( ) <EOL> do_migration ( [ user_addon ] , dry = False ) <EOL> user_addon . reload ( ) <EOL> node_addon . reload ( ) <EOL> account = user_addon . external_accounts [ <NUM_LIT:0> ] <EOL> assert_equal ( account , node_addon . external_account ) <EOL> def test_migration_multiple_users ( self ) : <EOL> user1 = UserFactory ( ) <EOL> user2 = UserFactory ( ) <EOL> api_token = '<STR_LIT>' <EOL> user1 . add_addon ( '<STR_LIT>' ) <EOL> user1_addon = user1 . get_addon ( '<STR_LIT>' ) <EOL> user1_addon . api_token = api_token <EOL> user1_addon . save ( ) <EOL> user2 . add_addon ( '<STR_LIT>' ) <EOL> user2_addon = user2 . get_addon ( '<STR_LIT>' ) <EOL> user2_addon . api_token = api_token <EOL> user2_addon . save ( ) <EOL> do_migration ( [ user1_addon , user2_addon ] , dry = False ) <EOL> user1_addon . reload ( ) <EOL> user2_addon . reload ( ) <EOL> assert_equal ( <EOL> user1_addon . external_accounts [ <NUM_LIT:0> ] , <EOL> user2_addon . external_accounts [ <NUM_LIT:0> ] , <EOL> ) <EOL> def test_get_targets ( self ) : <EOL> AddonDataverseUserSettings . remove ( ) <EOL> addons = [ <EOL> AddonDataverseUserSettings ( ) , <EOL> AddonDataverseUserSettings ( api_token = '<STR_LIT>' ) , <EOL> ] <EOL> for addon in addons : <EOL> addon . save ( ) <EOL> targets = get_targets ( ) <EOL> assert_equal ( targets . count ( ) , <NUM_LIT:1> ) <EOL> assert_equal ( targets [ <NUM_LIT:0> ] . _id , addons [ - <NUM_LIT:1> ] . _id ) </s>
