Mercurial > public > sg101
diff bio/tests/test_views.py @ 767:a4ae99359286
Added a bio app test for changing your avatar.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 20 Jan 2014 20:04:25 -0600 |
parents | 22d158ef2217 |
children | 1b1a12abde3b |
line wrap: on
line diff
--- a/bio/tests/test_views.py Sun Jan 19 21:26:42 2014 -0600 +++ b/bio/tests/test_views.py Mon Jan 20 20:04:25 2014 -0600 @@ -2,10 +2,17 @@ View tests for the bio application. """ +from io import BytesIO +import os + from django.contrib.auth.models import User from django.test import TestCase from django.core.urlresolvers import reverse, NoReverseMatch +from PIL import Image + +from bio.models import UserProfile + class MemberSearchTest(TestCase): @@ -128,6 +135,11 @@ u2 = User.objects.create_user('eddie', '', 'pw') u2.save() + def tearDown(self): + profile = UserProfile.objects.get(user__username='paul') + if profile.avatar: + os.remove(profile.avatar.path) + def test_anon_my_profile(self): my_url = reverse('bio-me') response = self.client.get(my_url) @@ -187,3 +199,20 @@ profile = u.get_profile() self.assertEqual(profile.occupation, 'Surf Guitar Pioneer') self.assertEqual(profile.profile_text, 'Wrote Mr. Moto at age 15.') + + def test_avatar_change(self): + self.client.login(username='paul', password='pw') + url = reverse('bio-change_avatar') + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + + # Create an in-memory image for a dummy avatar + file_obj = BytesIO() + image = Image.new('RGBA', size=(100, 100)) + image.save(file_obj, 'png') + file_obj.name = 'avatar.png' + file_obj.seek(0) + + response = self.client.post(url, {'avatar_file': file_obj}, follow=True) + self.assertRedirects(response, reverse('bio-me')) +