Created
November 28, 2011 22:14
-
-
Save tofumatt/1402331 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_profile_photo(self): | |
"""Make sure profile photo uploads and removals work. | |
Test the upload, encoding, and removal of photo profiles. Also make | |
sure edge cases (from naughty user input) and HTML elements work | |
properly. | |
""" | |
client = self.mozillian_client | |
# No photo exists by default, the delete photo form control shouldn't | |
# be present, and trying to delete a non-existant photo shouldn't | |
# do anything. | |
r = client.get(reverse('phonebook.edit_profile')) | |
doc = pq(r.content) | |
image = client.get(doc('#profile-photo').attr('src')) | |
eq_(image.status_code, 302, ( | |
'Profile image URL should redirect to "unknown" image.')) | |
assert not doc('#photo_delete'), ( | |
'"Remove Profile Photo" control should not appear.') | |
# Try to game the form -- it shouldn't do anything. | |
r = client.post(reverse('phonebook.edit_profile'), | |
dict(photo_delete=1), follow=True) | |
eq_(r.status_code, 200, ('Trying to delete a non-existant photo ' | |
"shouldn't result in an error.")) | |
# Add a profile photo | |
f = open(os.path.join(os.path.dirname(__file__), 'profile-photo.jpg'), | |
'rb') # Same thing happens if I use Django's File() | |
r = client.post(reverse('phonebook.edit_profile'), dict(photo=f), | |
follow=True) | |
f.close() | |
doc = pq(r.content) | |
image = client.get(doc('#profile-photo').attr('src')) | |
eq_(r.status_code, 200, 'Adding a photo should work.') | |
eq_(image.status_code, 200, 'Profile image URL should not redirect.') | |
assert doc('#photo_delete'), ( | |
'"Remove Profile Photo" control should appear.') | |
# Remove a profile photo | |
r = client.post(reverse('phonebook.edit_profile'), | |
dict(photo_delete=1), follow=True) | |
doc = pq(r.content) | |
image = client.get(doc('#profile-photo').attr('src')) | |
eq_(image.status_code, 302, ( | |
'Profile image URL should redirect to "unknown" image.')) | |
assert not doc('#photo_delete'), ( | |
'"Remove Profile Photo" control should not appear.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment