pull/43/head
eric 2017-07-28 12:40:34 -04:00
parent a745223e3c
commit f1dd40fe00
1 changed files with 101 additions and 109 deletions

View File

@ -1,18 +1,12 @@
"""
external library imports
"""
#external library imports
import json
import re
import time
import mimetypes
from datetime import timedelta
from decimal import Decimal as D
"""
django imports
"""
from django.conf import settings
#django imports
from django.contrib import auth
from django.contrib.auth.models import User
from django.core import mail
@ -22,9 +16,7 @@ from django.test.client import Client
from notification.models import Notice
"""
regluit imports
"""
#regluit imports
from regluit.core.models import Work, Campaign, RightsHolder, Claim, Subject
from regluit.payment.models import Transaction
from regluit.payment.manager import PaymentManager
@ -44,7 +36,7 @@ class WishlistTests(TestCase):
HTTP_X_REQUESTED_WITH="XMLHttpRequest")
self.assertEqual(r.status_code, 200)
self.assertEqual(self.user.wishlist.works.all().count(), 1)
wished= self.user.wishlist.works.all()[0]
wished = self.user.wishlist.works.all()[0]
# test the work page
r = self.client.get("/work/%s/" % wished.id)
self.assertEqual(r.status_code, 200)
@ -63,9 +55,9 @@ class RhPageTests(TestCase):
self.user = User.objects.create_user('test', 'test@example.org', 'test')
self.rh_user = User.objects.create_user('rh', 'rh@example.org', 'test')
self.staff_user = User.objects.create_superuser('staff', 'staff@example.org', 'test')
self.work = Work.objects.create(title="test work",language='en')
self.work = Work.objects.create(title="test work", language='en')
rh = RightsHolder.objects.create(rights_holder_name='test', owner=self.rh_user)
Claim.objects.create(work=self.work, user=self.rh_user, status='active',rights_holder=rh)
Claim.objects.create(work=self.work, user=self.rh_user, status='active', rights_holder=rh)
self.kw = Subject.objects.create(name="Fiction")
def test_anonymous(self):
@ -82,7 +74,7 @@ class RhPageTests(TestCase):
self.assertEqual(r.status_code, 200)
csrfmatch = re.search("name='csrfmiddlewaretoken' value='([^']*)'", r.content)
self.assertTrue(csrfmatch)
csrf=csrfmatch.group(1)
csrf = csrfmatch.group(1)
r = client.post("/work/{}/kw/".format(self.work.id), {
u'csrfmiddlewaretoken': csrf,
u'kw_add':u'true',
@ -127,7 +119,7 @@ class PageTests(TestCase):
User.objects.create_user('test_other', 'test@example.org', 'test_other')
self.client = Client()
self.client.login(username='test', password='test')
w= Work.objects.create(title="test work",language='en')
w = Work.objects.create(title="test work", language='en')
def test_setttings(self):
self.assertEqual(mimetypes.guess_type('/whatever/my_file.epub')[0], 'application/epub+zip')
@ -178,7 +170,7 @@ class GoogleBooksTest(TestCase):
r = self.client.get("/googlebooks/IDFfMPW32hQC/")
self.assertEqual(r.status_code, 302)
work_url = r['location']
self.assertTrue(re.match('.*/work/\d+/$', work_url))
self.assertTrue(re.match(r'.*/work/\d+/$', work_url))
class CampaignUiTests(TestCase):
def setUp(self):
@ -235,7 +227,7 @@ class PledgingUiTests(TestCase):
HTTP_X_REQUESTED_WITH="XMLHttpRequest")
self.assertEqual(r.status_code, 200)
self.assertEqual(self.user.wishlist.works.all().count(), 1)
wished= self.user.wishlist.works.all()[0]
wished = self.user.wishlist.works.all()[0]
# test the work page
r = self.client.get("/work/%s/" % wished.id)
self.assertEqual(r.status_code, 200)
@ -278,7 +270,7 @@ class PledgingUiTests(TestCase):
pass
class UnifiedCampaignTests(TestCase):
fixtures=['initial_data.json','basic_campaign_test.json']
fixtures = ['initial_data.json','basic_campaign_test.json']
def test_setup(self):
# testing basics: are there 3 users?
@ -483,11 +475,11 @@ class UnifiedCampaignTests(TestCase):
def stripe_token_none(self):
"""Test that if an empty stripe_token is submitted to pledge page, we catch that issue and present normal error page to user"""
username="hmelville"
password="gofish!"
work_id =1
preapproval_amount='10'
premium_id='150'
username = "hmelville"
password = "gofish!"
work_id = 1
preapproval_amount = '10'
premium_id = '150'
self.assertTrue(self.client.login(username=username, password=password))