Created
January 6, 2016 19:12
-
-
Save grobertson/66734f0e5ce347ad4894 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
from django.test import TestCase | |
from django.test.client import Client, RequestFactory | |
from dd.grabit.views import save_image_from_url | |
from django.contrib.auth.models import User | |
class GrabitViewsTestCase(TestCase): | |
def setUp(self): | |
self.user = User.objects.create_superuser('foo', '[email protected]', 'bar') | |
self.rf = RequestFactory() | |
self.client = Client() | |
def tearDown(self): | |
self.user.delete() | |
def test_save_from_url(self): | |
data = { 'url': 'http://i.imgur.com/bsNbztf.jpg', | |
'title': "Title", | |
'description': 'Description', | |
'attribution_link': 'http://i.imgur.com/bsNbztf' } | |
request = self.rf.get('/grabit/addimage/', data=data) | |
request.user = self.user | |
result = save_image_from_url(request) | |
self.assertEqual(200, result.status_code) | |
def test_file_protocol_disallowed(self): | |
expected = "Local files aren't supported by the grabit bookmarklet!" | |
data = { 'url': 'file://i.imgur.com/bsNbztf.jpg' } | |
request = self.rf.get('/grabit/addimage/', data=data) | |
request.user = self.user | |
result = save_image_from_url(request) | |
self.assertIn(expected, result.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment