Example #1
0
    def test_one_user_with_multiple_addons(self):
        results = AddonSnapshot().get_events()
        github_res = [
            res for res in results if res['provider']['name'] == 'github'
        ][0]
        googledrive_res = [
            res for res in results if res['provider']['name'] == 'googledrive'
        ][0]
        assert_equal(github_res['users']['enabled'], 1)
        assert_equal(googledrive_res['users']['enabled'], 0)

        self.user.add_addon('googledrive')
        oauth_settings = GoogleDriveAccountFactory()
        oauth_settings.save()
        self.user.external_accounts.add(oauth_settings)
        self.user.save()
        results = AddonSnapshot().get_events()
        github_res = [
            res for res in results if res['provider']['name'] == 'github'
        ][0]
        googledrive_res = [
            res for res in results if res['provider']['name'] == 'googledrive'
        ][0]
        assert_equal(github_res['users']['enabled'], 1)
        assert_equal(googledrive_res['users']['enabled'], 1)
Example #2
0
    def test_one_node_with_multiple_addons(self):
        results = AddonSnapshot().get_events()
        github_res = [
            res for res in results if res['provider']['name'] == 'github'
        ][0]
        googledrive_res = [
            res for res in results if res['provider']['name'] == 'googledrive'
        ][0]
        assert_equal(github_res['nodes']['total'], 1)
        assert_equal(googledrive_res['nodes']['total'], 0)

        self.user.add_addon('googledrive')
        user_addon = self.user.get_addon('googledrive')
        oauth_settings = GoogleDriveAccountFactory()
        oauth_settings.save()
        self.user.external_accounts.add(oauth_settings)
        self.user.save()
        self.node.add_addon('googledrive', Auth(self.user))
        node_addon = self.node.get_addon('googledrive')
        node_addon.user = self.user.fullname
        node_addon.user_settings = user_addon
        node_addon.external_account = oauth_settings
        node_addon.save()
        results = AddonSnapshot().get_events()
        github_res = [
            res for res in results if res['provider']['name'] == 'github'
        ][0]
        googledrive_res = [
            res for res in results if res['provider']['name'] == 'googledrive'
        ][0]
        assert_equal(github_res['nodes']['total'], 1)
        assert_equal(googledrive_res['nodes']['total'], 1)
 def test_refresh(self, mock_box_refresh, mock_drive_refresh, mock_mendeley_refresh):
     fake_authorized_box_account = BoxAccountFactory(date_last_refreshed=timezone.now())
     fake_authorized_drive_account = GoogleDriveAccountFactory(date_last_refreshed=timezone.now())
     fake_authorized_mendeley_account = MendeleyAccountFactory(date_last_refreshed=timezone.now())
     fake_unauthorized_box_account = BoxAccountFactory(date_last_refreshed=timezone.now() - datetime.timedelta(days=4))
     fake_unauthorized_drive_account = GoogleDriveAccountFactory(date_last_refreshed=timezone.now() - datetime.timedelta(days=4))
     fake_unauthorized_mendeley_account = MendeleyAccountFactory(date_last_refreshed=timezone.now() - datetime.timedelta(days=4))
     for addon in self.addons:
         Provider = look_up_provider(addon)
         main(delta=relativedelta(days=3), Provider=Provider, rate_limit=(5, 1), dry_run=False)
     assert_equal(1, mock_box_refresh.call_count)
     assert_equal(1, mock_drive_refresh.call_count)
     assert_equal(1, mock_mendeley_refresh.call_count)
Example #4
0
    def test_migration(self):
        GoogleDriveUserSettings.remove()

        user = UserFactory()
        node = ProjectFactory(creator=user)
        account = GoogleDriveAccountFactory()

        user.external_accounts = [account]

        user.add_addon('googledrive', auth=Auth(user))
        user_addon = user.get_addon('googledrive')
        user_addon.save()


        node.add_addon('googledrive', auth=Auth(user))
        node_addon = node.get_addon('googledrive')
        node_addon.foreign_user_settings = user_addon
        node_addon.folder_id = 'abcdef0'
        node_addon.folder_path = '/'
        node_addon.save()

        assert_equal(node_addon.external_account, None)
        assert_equal(node_addon.folder_id, 'abcdef0')

        do_migration()
        node_addon.reload()

        assert_equal(node_addon.external_account, account)
        assert_equal(node_addon.folder_id, 'abcdef0')
        assert_equal(node_addon.folder_path, '/')
        assert_equal(node_addon.folder_name, '/ (Full Google Drive)')
    def test_one_user_with_multiple_addons(self):
        results = AddonSnapshot().get_events()
        github_res = [res for res in results if res['provider']['name'] == 'github'][0]
        googledrive_res = [res for res in results if res['provider']['name'] == 'googledrive'][0]
        assert_equal(github_res['users']['enabled'], 1)
        assert_equal(googledrive_res['users']['enabled'], 0)

        self.user.add_addon('googledrive')
        oauth_settings = GoogleDriveAccountFactory()
        oauth_settings.save()
        self.user.external_accounts.add(oauth_settings)
        self.user.save()
        results = AddonSnapshot().get_events()
        github_res = [res for res in results if res['provider']['name'] == 'github'][0]
        googledrive_res = [res for res in results if res['provider']['name'] == 'googledrive'][0]
        assert_equal(github_res['users']['enabled'], 1)
        assert_equal(googledrive_res['users']['enabled'], 1)
 def test_get_targets(self):
     now = timezone.now()
     records = [
         BoxAccountFactory(date_last_refreshed=now - datetime.timedelta(days=4)),
         BoxAccountFactory(date_last_refreshed=now - datetime.timedelta(days=2)),
         GoogleDriveAccountFactory(date_last_refreshed=now - datetime.timedelta(days=4)),
         GoogleDriveAccountFactory(date_last_refreshed=now - datetime.timedelta(days=2)),
         MendeleyAccountFactory(date_last_refreshed=now - datetime.timedelta(days=4)),
         MendeleyAccountFactory(date_last_refreshed=now - datetime.timedelta(days=2)),
     ]
     box_targets = list(get_targets(delta=relativedelta(days=3), addon_short_name='box'))
     drive_targets = list(get_targets(delta=relativedelta(days=3), addon_short_name='googledrive'))
     mendeley_targets = list(get_targets(delta=relativedelta(days=3), addon_short_name='mendeley'))
     assert_equal(records[0]._id, box_targets[0]._id)
     assert_not_in(records[1], box_targets)
     assert_equal(records[2]._id, drive_targets[0]._id)
     assert_not_in(records[3], drive_targets)
     assert_equal(records[4]._id, mendeley_targets[0]._id)
     assert_not_in(records[5], mendeley_targets)
    def test_one_node_with_multiple_addons(self):
        results = AddonSnapshot().get_events()
        github_res = [res for res in results if res['provider']['name'] == 'github'][0]
        googledrive_res = [res for res in results if res['provider']['name'] == 'googledrive'][0]
        assert_equal(github_res['nodes']['total'], 1)
        assert_equal(googledrive_res['nodes']['total'], 0)

        self.user.add_addon('googledrive')
        user_addon = self.user.get_addon('googledrive')
        oauth_settings = GoogleDriveAccountFactory()
        oauth_settings.save()
        self.user.external_accounts.add(oauth_settings)
        self.user.save()
        self.node.add_addon('googledrive', Auth(self.user))
        node_addon = self.node.get_addon('googledrive')
        node_addon.user = self.user.fullname
        node_addon.user_settings = user_addon
        node_addon.external_account = oauth_settings
        node_addon.save()
        results = AddonSnapshot().get_events()
        github_res = [res for res in results if res['provider']['name'] == 'github'][0]
        googledrive_res = [res for res in results if res['provider']['name'] == 'googledrive'][0]
        assert_equal(github_res['nodes']['total'], 1)
        assert_equal(googledrive_res['nodes']['total'], 1)