Skip to content

Commit

Permalink
Added a couple more test cases for service functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Phillips committed Jun 16, 2014
1 parent 8e3ab39 commit be65f97
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ perma_web/.coverage
.idea
venv
.vagrant
.DS_Store

services/django/generated_assets/*
!services/django/generated_assets/README
Expand Down
62 changes: 59 additions & 3 deletions perma_web/perma/tests/test_views_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from .utils import PermaTestCase
from django.conf import settings
from django.core.urlresolvers import reverse
Expand All @@ -12,13 +14,16 @@ def test_email_confirm(self):
"""

# We send from this email. Verify it's in our settings.
self.assertNotEquals(settings.DEFAULT_FROM_EMAIL, '')
self.assertIn('@', settings.DEFAULT_FROM_EMAIL)

# TODO: write emails to files and then validate that file
response = self.client.post(reverse('service_email_confirm'), data={'email_address': 'test@example.com',
'link_url': 'http://weshouldactuallytestthis.org'})
self.assertEqual(response.status_code, 200)

jsoned_response = json.loads(response.content)
self.assertEqual(True, jsoned_response['sent'])

# The service needs an email address and a link. If we don't send both we should fail
response = self.client.post(reverse('service_email_confirm'), data={'email_address': 'test@example.com'})
self.assertEqual(response.status_code, 400)
Expand All @@ -30,12 +35,63 @@ def test_receive_feedback(self):
"""

# We send from this email. Verify it's in our settings.
self.assertNotEquals(settings.DEFAULT_FROM_EMAIL, '')
self.assertIn('@', settings.DEFAULT_FROM_EMAIL)

data = {'visited_page': 'http://perma.cc/something',
'feedback_text': 'something about example.com',
'broken_link': 'http://example.com'}

# TODO: write emails to files and then validate that file
response = self.client.post(reverse('service_receive_feedback'), data=data)
self.assertEqual(response.status_code, 201)
self.assertEqual(response.status_code, 201)

jsoned_response = json.loads(response.content)
self.assertEqual('true', jsoned_response['submitted'])
self.assertIsNotNone(jsoned_response['content'])

def test_link_status(self):
"""During link creation we can poll the link for its status"""

response = self.client.post(reverse('service_link_status', kwargs={'guid': 'JJ3S-2Q5N',}))
self.assertEqual(response.status_code, 200)

jsoned_response = json.loads(response.content)
self.assertIsNotNone(jsoned_response['path'])
self.assertIsNotNone(jsoned_response['source_capture'])
self.assertIsNotNone(jsoned_response['image_capture'])
self.assertIsNone(jsoned_response['pdf_capture'])
self.assertEqual(False, jsoned_response['vested'])
self.assertEqual(False, jsoned_response['dark_archived'])

response = self.client.post(reverse('service_link_status', kwargs={'guid': '7CF8-SS4G',}))
self.assertEqual(response.status_code, 200)

jsoned_response = json.loads(response.content)
self.assertIsNotNone(jsoned_response['path'])
self.assertIsNone(jsoned_response['source_capture'])
self.assertIsNone(jsoned_response['image_capture'])
self.assertIsNotNone(jsoned_response['pdf_capture'])
self.assertEqual(False, jsoned_response['vested'])
self.assertEqual(False, jsoned_response['dark_archived'])

response = self.client.post(reverse('service_link_status', kwargs={'guid': '7CF8-JJJJ',}))
self.assertEqual(response.status_code, 404)

def test_link_assets(self):
"""
make sure we get a download with a zip from our
asssets bundler service
"""

guid = '7CF8-SS4G'

response = self.client.post(reverse('service_link_assets', kwargs={'guid': guid,}))
self.assertEqual(response.status_code, 200)

self.assertEquals(
response.get('Content-Disposition'),
'attachment; filename="assets_%s.zip"' % guid
)

response = self.client.post(reverse('service_link_assets', kwargs={'guid': '9999-JCDL',}))
self.assertEqual(response.status_code, 404)
2 changes: 1 addition & 1 deletion perma_web/perma/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class PermaTestCase(TestCase):
fixtures = ['fixtures/groups.json','fixtures/users.json', 'archive.json']
fixtures = ['fixtures/groups.json','fixtures/users.json', 'fixtures/archive.json']

def setUp(self):
registrar = Registrar(name='Test Registrar', email='registrar@test.com', website='http://testregistrar.com')
Expand Down
2 changes: 1 addition & 1 deletion perma_web/perma/views/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def email_confirm(request):

email_address = request.POST.get('email_address')
link_url = request.POST.get('link_url')

if not email_address or not link_url:
return HttpResponse(status=400)

Expand Down
Binary file removed perma_web/static/.DS_Store
Binary file not shown.
Binary file removed perma_web/static/img/.DS_Store
Binary file not shown.

0 comments on commit be65f97

Please sign in to comment.