def test_sync_teams(self): # test the sync_teams field user = UserFactory() account_team = TeamFactory(admin=user, name='Account Team') account = YouTubeAccountFactory(team=account_team) correct_choices = [] correct_initial = [] # make some random teams that the user isn't an admin for and aren't # currently synced. We shouldn't include these. for i in xrange(5): TeamFactory(name='Other team %s' % i) # by default, the choices sync_teams should include all teams the user # is an admin for for i in xrange(5): team = TeamFactory(admin=user, name='Related team %s' % i) correct_choices.append((team.id, unicode(team))) # add one of the teams to the sync_teams set so that we check that # the initial value is correct. if i == 0: account.sync_teams.add(team) correct_initial.append(team.id) # it also should include teams that are currently synced, but the user # isn't an admin for team = TeamFactory(name='Synced team') account.sync_teams.add(team) correct_choices.append(('', 'Clear')) correct_choices.append((team.id, unicode(team))) correct_initial.append(team.id) form = forms.YoutubeAccountForm(user, account) assert_items_equal(form['sync_teams'].field.choices, correct_choices) assert_items_equal(form['sync_teams'].field.initial, correct_initial)
def test_no_remove(self): user = UserFactory() team = TeamFactory(admin=user) account = YouTubeAccountFactory(team=team) assert_equal(models.YouTubeAccount.objects.count(), 1) form = forms.YoutubeAccountForm(user, account, {}) form.save() assert_equal(models.YouTubeAccount.objects.count(), 1)
def test_save_sync_teams(self): user = UserFactory() account_team = TeamFactory(admin=user) account = YouTubeAccountFactory(team=account_team) teams = [TeamFactory(admin=user) for i in xrange(5)] account.sync_teams = teams[:2] form = forms.YoutubeAccountForm(user, account, { 'sync_teams': [t.id for t in teams[3:]], }) form.save() account = models.YouTubeAccount.objects.get(id=account.id) assert_items_equal(account.sync_teams.all(), teams[3:])
def team_edit_external_account(request, team, form_name=None): context = {} account = None template = 'future/teams/settings/forms/integrations-edit.html' if request.method == "POST": try: account_type = request.POST.get('accountType') account_pk = request.POST.get('accountPk') removing = request.POST.get('remove', False) except KeyError: return HttpResponseBadRequest() if account_type == YouTubeAccount.account_type: account = YouTubeAccount.objects.get(pk=account_pk) form = forms.YoutubeAccountForm(request.user, account, request.POST) elif account_type == VimeoSyncAccount.account_type: account = VimeoSyncAccount.objects.get(pk=account_pk) form = forms.VimeoAccountForm(request.user, account, request.POST) elif account_type == KalturaAccount.account_type: account = KalturaAccount.objects.get(pk=account_pk) form = new_forms.KalturaAccountForm(team, request.POST) elif account_type == BrightcoveCMSAccount.account_type: account = BrightcoveCMSAccount.objects.get(pk=account_pk) form = new_forms.BrightcoveCMSAccountForm(team, request.POST) account_verbose_name = account._meta.verbose_name if removing: form = new_forms.RemoveAccountForm(account) if form.is_valid(): form.save() if removing: messages.success(request, _(u'{} removed'.format(account_verbose_name))) else: messages.success( request, _(u'{} {} settings updated'.format( account_verbose_name, account.readable_account_name()))) response_renderer = AJAXResponseRenderer(request) response_renderer.reload_page() return response_renderer.render() else: try: account_pk = request.GET['selection'] except KeyError: return HttpResponseBadRequest() if form_name == 'edit-youtube': account = YouTubeAccount.objects.get(pk=account_pk) form = forms.YoutubeAccountForm(request.user, account) elif form_name == 'edit-vimeo': account = VimeoSyncAccount.objects.get(pk=account_pk) form = forms.VimeoAccountForm(request.user, account) elif form_name == 'edit-kaltura': account = KalturaAccount.objects.get(pk=account_pk) form = new_forms.KalturaAccountForm(team) elif form_name == 'edit-brightcove': account = BrightcoveCMSAccount.objects.get(pk=account_pk) form = new_forms.BrightcoveCMSAccountForm(team) if form_name == 'remove-youtube': account = YouTubeAccount.objects.get(pk=account_pk) elif form_name == 'remove-vimeo': account = VimeoSyncAccount.objects.get(pk=account_pk) elif form_name == 'remove-kaltura': account = KalturaAccount.objects.get(pk=account_pk) elif form_name == 'remove-brightcove': account = BrightcoveCMSAccount.objects.get(pk=account_pk) if form_name.startswith('remove'): form = new_forms.RemoveAccountForm(account) template = 'future/teams/settings/forms/integrations-remove.html' context['form'] = form context['team'] = team context['account'] = account context['account_type_display'] = account.readable_account_type() response_renderer = AJAXResponseRenderer(request) response_renderer.show_modal(template, context) return response_renderer.render()