def _reset_avatar_services(): avatar_services.reset() gravatar_service = avatar_services.get_avatar_service( GravatarService.avatar_service_id) avatar_services.enable_service(gravatar_service.avatar_service_id, save=False) avatar_services.set_default_service(gravatar_service, save=False)
def test_post_with_render_avatars_at(self): """Testing the POST <URL> API with render_avatars_at=...""" self.client.login(username='******', password='******') avatar_services.register(SimpleRenderAvatarService) avatar_services.enable_service(SimpleRenderAvatarService, save=False) avatar_services.set_default_service(SimpleRenderAvatarService) rsp = self.api_post( get_user_list_url(), { 'username': '******', 'password': '******', 'email': '*****@*****.**', 'render_avatars_at': '24,abc,48,,128', }, expected_mimetype=user_item_mimetype) self.assertEqual(rsp['stat'], 'ok') self.assertEqual( rsp['user']['avatar_html'], { '24': '<div class="avatar" data-size="24">myuser</div>', '48': '<div class="avatar" data-size="48">myuser</div>', '128': '<div class="avatar" data-size="128">myuser</div>', })
def test_put_with_render_avatars_at(self): """Testing the PUT <URL> API with render_avatars_at=...""" avatar_services.register(SimpleRenderAvatarService) avatar_services.enable_service(SimpleRenderAvatarService, save=False) avatar_services.set_default_service(SimpleRenderAvatarService) user = self.create_user(username='******', password='******') self.assertTrue(self.client.login(username='******', password='******')) rsp = self.api_put( get_user_item_url(user.username), { 'first_name': 'new-name', 'render_avatars_at': '24,abc,48,,128', }, expected_mimetype=user_item_mimetype) self.assertEqual(rsp['stat'], 'ok') self.assertEqual( rsp['user']['avatar_html'], { '24': '<div class="avatar" data-size="24">test-user</div>', '48': '<div class="avatar" data-size="48">test-user</div>', '128': '<div class="avatar" data-size="128">test-user</div>', })
def _reset_avatar_services(): avatar_services.reset() gravatar_service = avatar_services.get_avatar_service( GravatarService.avatar_service_id) avatar_services.enable_service(gravatar_service.avatar_service_id, save=False) avatar_services.set_default_service(gravatar_service, save=False)
def setUp(self): super(TemplateTagTests, self).setUp() avatar_services.enable_service(GravatarService, save=False) avatar_services.set_default_service(GravatarService, save=False) self.user = User.objects.get(username='******') self.request = RequestFactory().get('/') self.request.user = AnonymousUser()
def setUp(self): super(TemplateTagTests, self).setUp() avatar_services.enable_service(GravatarService, save=False) avatar_services.set_default_service(GravatarService, save=False) self.user = User.objects.get(username='******') self.request = RequestFactory().get('/') self.request.user = AnonymousUser()
def save(self): """Save the enabled services and default service to the database.""" avatar_services.enabled_services = [ avatar_services.get('avatar_service_id', service_id) for service_id in self.cleaned_data['enabled_services'] ] avatar_services.set_default_service( self.cleaned_data['default_service'], save=False) avatar_services.avatars_enabled = self.cleaned_data['avatars_enabled'] avatar_services.save()
def save(self): """Save the enabled services and default service to the database.""" avatar_services.enabled_services = [ avatar_services.get('avatar_service_id', service_id) for service_id in self.cleaned_data['enabled_services'] ] avatar_services.set_default_service( self.cleaned_data['default_service'], save=False) avatar_services.avatars_enabled = self.cleaned_data['avatars_enabled'] avatar_services.save()
def setUp(self): super(TemplateTagTests, self).setUp() gravatar_service = avatar_services.get_avatar_service( GravatarService.avatar_service_id) avatar_services.enable_service(gravatar_service.avatar_service_id, save=False) avatar_services.set_default_service(gravatar_service, save=False) self.user = User.objects.get(username='******') self.request = HttpRequest() self.request.user = AnonymousUser()
def test_get_with_render_avatars_at(self): """Testing the GET <URL> API with ?render-avatars-at=...""" avatar_services.register(SimpleRenderAvatarService) avatar_services.enable_service(SimpleRenderAvatarService, save=False) avatar_services.set_default_service(SimpleRenderAvatarService) rsp = self.api_get( get_user_list_url(), { 'render-avatars-at': '24,abc,48,,128', }, expected_mimetype=user_list_mimetype) self.assertEqual(rsp['stat'], 'ok') self.assertEqual(len(rsp['users']), 4) self.assertEqual( rsp['users'][0]['avatar_html'], { '24': '<div class="avatar" data-size="24">admin</div>', '48': '<div class="avatar" data-size="48">admin</div>', '128': '<div class="avatar" data-size="128">admin</div>', }) self.assertEqual( rsp['users'][1]['avatar_html'], { '24': '<div class="avatar" data-size="24">doc</div>', '48': '<div class="avatar" data-size="48">doc</div>', '128': '<div class="avatar" data-size="128">doc</div>', }) self.assertEqual( rsp['users'][2]['avatar_html'], { '24': '<div class="avatar" data-size="24">dopey</div>', '48': '<div class="avatar" data-size="48">dopey</div>', '128': '<div class="avatar" data-size="128">dopey</div>', }) self.assertEqual( rsp['users'][3]['avatar_html'], { '24': '<div class="avatar" data-size="24">grumpy</div>', '48': '<div class="avatar" data-size="48">grumpy</div>', '128': '<div class="avatar" data-size="128">grumpy</div>', })
def save(self): """Save the enabled services and default service to the database.""" avatar_services.enabled_services = [ avatar_services.get('avatar_service_id', service_id) for service_id in self.cleaned_data['enabled_services'] ] avatar_services.set_default_service( self.cleaned_data['default_service'], save=False) avatars_enabled_changed = (avatar_services.avatars_enabled != self.cleaned_data['avatars_enabled']) avatar_services.avatars_enabled = self.cleaned_data['avatars_enabled'] avatar_services.save() if avatars_enabled_changed: if avatar_services.avatars_enabled: AccountPage.registry.add_form_to_page(ProfilePage, AvatarSettingsForm) else: AccountPage.registry.remove_form_from_page( ProfilePage, AvatarSettingsForm)
def save(self): """Save the enabled services and default service to the database.""" avatar_services.enabled_services = [ avatar_services.get('avatar_service_id', service_id) for service_id in self.cleaned_data['enabled_services'] ] avatar_services.set_default_service( self.cleaned_data['default_service'], save=False) avatars_enabled_changed = (avatar_services.avatars_enabled != self.cleaned_data['avatars_enabled']) avatar_services.avatars_enabled = self.cleaned_data['avatars_enabled'] avatar_services.save() if avatars_enabled_changed: if avatar_services.avatars_enabled: AccountPage.registry.add_form_to_page(ProfilePage, AvatarSettingsForm) else: AccountPage.registry.remove_form_from_page(ProfilePage, AvatarSettingsForm)