python3 random fixes from @rohitdatta
* fixed unicode python3 issues * set flask app to formspree * test? * update travis * travis?
This commit is contained in:
parent
0ea38e18a7
commit
19ae7fcbb6
13
.travis.yml
13
.travis.yml
|
@ -6,6 +6,7 @@ install:
|
||||||
- pip install pipenv
|
- pip install pipenv
|
||||||
- pipenv install --dev --three
|
- pipenv install --dev --three
|
||||||
script:
|
script:
|
||||||
|
- export FLASK_APP=formspree
|
||||||
- flask test
|
- flask test
|
||||||
addons:
|
addons:
|
||||||
postgresql: "9.6"
|
postgresql: "9.6"
|
||||||
|
@ -14,14 +15,4 @@ services:
|
||||||
before_script:
|
before_script:
|
||||||
- psql -c 'create database formspree_test;' -U postgres
|
- psql -c 'create database formspree_test;' -U postgres
|
||||||
env:
|
env:
|
||||||
- TESTING=true
|
- FLASK_APP=formspree TESTING=true REDISTOGO_URL=0.0.0.0:6379 REDIS_URL='redis://h:@localhost:6379' RATE_LIMIT='120 per hour' TEST_DATABASE_URL=postgres:///formspree_test NONCE_SECRET='y0ur_n0nc3_s3cr3t' SECRET_KEY='y0ur_s3cr3t_k3y' HASHIDS_SALT=doesntmatter STRIPE_TEST_PUBLISHABLE_KEY=pk_test_XebfAaLvLpHeO2txAgqWgJPf STRIPE_TEST_SECRET_KEY=sk_test_MLGQEdAHgWy4Rces4khaIxuc PIPENV_VENV_IN_PROJECT=1
|
||||||
- REDISTOGO_URL=0.0.0.0:6379
|
|
||||||
- REDIS_URL='redis://h:@localhost:6379'
|
|
||||||
- RATE_LIMIT='120 per hour'
|
|
||||||
- TEST_DATABASE_URL=postgres:///formspree_test
|
|
||||||
- NONCE_SECRET='y0ur_n0nc3_s3cr3t'
|
|
||||||
- SECRET_KEY='y0ur_s3cr3t_k3y'
|
|
||||||
- HASHIDS_SALT=doesntmatter
|
|
||||||
- STRIPE_TEST_PUBLISHABLE_KEY=pk_test_XebfAaLvLpHeO2txAgqWgJPf
|
|
||||||
- STRIPE_TEST_SECRET_KEY=sk_test_MLGQEdAHgWy4Rces4khaIxuc
|
|
||||||
- PIPENV_VENV_IN_PROJECT=1
|
|
||||||
|
|
|
@ -571,7 +571,7 @@ def form_submissions(hashid, format=None):
|
||||||
for f in fields:
|
for f in fields:
|
||||||
value = sub.data.get(f, '')
|
value = sub.data.get(f, '')
|
||||||
typ = type(value)
|
typ = type(value)
|
||||||
sub.data[f] = value if typ is unicode or typ is str \
|
sub.data[f] = value if typ is str \
|
||||||
else pyaml.dump(value, safe=True)
|
else pyaml.dump(value, safe=True)
|
||||||
submissions.append(sub)
|
submissions.append(sub)
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ class ListUnsubscribeTestCase(FormspreeTestCase):
|
||||||
f = Form.query.first()
|
f = Form.query.first()
|
||||||
|
|
||||||
# List-Unsubscribe is present on confirmation email
|
# List-Unsubscribe is present on confirmation email
|
||||||
body = unquote(httpretty.last_request().body)
|
body = unquote(httpretty.last_request().body.decode('utf-8'))
|
||||||
res = re.search('"List-Unsubscribe":[^"]*"<([^>]+)>"', body)
|
res = re.search('"List-Unsubscribe":[^"]*"<([^>]+)>"', body)
|
||||||
self.assertTrue(res is not None)
|
self.assertTrue(res is not None)
|
||||||
list_unsubscribe_url = res.group(1)
|
list_unsubscribe_url = res.group(1)
|
||||||
|
@ -38,7 +38,7 @@ class ListUnsubscribeTestCase(FormspreeTestCase):
|
||||||
self.assertEqual(r.status_code, 302)
|
self.assertEqual(r.status_code, 302)
|
||||||
|
|
||||||
# List-Unsubscribe is present on normal submission
|
# List-Unsubscribe is present on normal submission
|
||||||
body = unquote(httpretty.last_request().body)
|
body = unquote(httpretty.last_request().body.decode('utf-8'))
|
||||||
res = re.search('"List-Unsubscribe":[^"]*"<([^>]+)>"', body)
|
res = re.search('"List-Unsubscribe":[^"]*"<([^>]+)>"', body)
|
||||||
self.assertTrue(res is not None)
|
self.assertTrue(res is not None)
|
||||||
url = res.group(1)
|
url = res.group(1)
|
||||||
|
|
|
@ -42,7 +42,7 @@ class UserAccountsTestCase(FormspreeTestCase):
|
||||||
user = User.query.filter_by(email='alice@springs.com').first()
|
user = User.query.filter_by(email='alice@springs.com').first()
|
||||||
self.assertIsNone(Email.query.get(['alice@springs.com', user.id]))
|
self.assertIsNone(Email.query.get(['alice@springs.com', user.id]))
|
||||||
|
|
||||||
link, qs = parse_confirmation_link_sent(httpretty.last_request().body)
|
link, qs = parse_confirmation_link_sent(httpretty.last_request().body.decode('utf-8'))
|
||||||
self.client.get(
|
self.client.get(
|
||||||
link,
|
link,
|
||||||
query_string=qs,
|
query_string=qs,
|
||||||
|
@ -89,7 +89,7 @@ class UserAccountsTestCase(FormspreeTestCase):
|
||||||
self.assertEqual(r.status_code, 200)
|
self.assertEqual(r.status_code, 200)
|
||||||
|
|
||||||
# click on the email link
|
# click on the email link
|
||||||
link, qs = parse_confirmation_link_sent(httpretty.last_request().body)
|
link, qs = parse_confirmation_link_sent(httpretty.last_request().body.decode('utf-8'))
|
||||||
r = self.client.get(
|
r = self.client.get(
|
||||||
link,
|
link,
|
||||||
query_string=qs,
|
query_string=qs,
|
||||||
|
@ -157,7 +157,7 @@ class UserAccountsTestCase(FormspreeTestCase):
|
||||||
data={'name': 'bruce'}
|
data={'name': 'bruce'}
|
||||||
)
|
)
|
||||||
self.assertIn("We've sent a link to your email", r.data.decode('utf-8'))
|
self.assertIn("We've sent a link to your email", r.data.decode('utf-8'))
|
||||||
self.assertIn('confirm+your+email', httpretty.last_request().body)
|
self.assertIn('confirm+your+email', httpretty.last_request().body.decode('utf-8'))
|
||||||
self.assertEqual(1, Form.query.count())
|
self.assertEqual(1, Form.query.count())
|
||||||
|
|
||||||
# confirm form
|
# confirm form
|
||||||
|
@ -176,9 +176,9 @@ class UserAccountsTestCase(FormspreeTestCase):
|
||||||
form = Form.query.first()
|
form = Form.query.first()
|
||||||
self.assertEqual(form.counter, 5)
|
self.assertEqual(form.counter, 5)
|
||||||
self.assertEqual(form.get_monthly_counter(), 5)
|
self.assertEqual(form.get_monthly_counter(), 5)
|
||||||
self.assertIn('ana', httpretty.last_request().body)
|
self.assertIn('ana', httpretty.last_request().body.decode('utf-8'))
|
||||||
self.assertIn('__4__', httpretty.last_request().body)
|
self.assertIn('__4__', httpretty.last_request().body.decode('utf-8'))
|
||||||
self.assertNotIn('You+are+past+our+limit', httpretty.last_request().body)
|
self.assertNotIn('You+are+past+our+limit', httpretty.last_request().body.decode('utf-8'))
|
||||||
|
|
||||||
# try (and fail) to submit from a different host
|
# try (and fail) to submit from a different host
|
||||||
r = self.client.post('/' + form_endpoint,
|
r = self.client.post('/' + form_endpoint,
|
||||||
|
@ -186,8 +186,8 @@ class UserAccountsTestCase(FormspreeTestCase):
|
||||||
data={'name': 'usurper'}
|
data={'name': 'usurper'}
|
||||||
)
|
)
|
||||||
self.assertEqual(r.status_code, 403)
|
self.assertEqual(r.status_code, 403)
|
||||||
self.assertIn('ana', httpretty.last_request().body) # no more data is sent to sendgrid
|
self.assertIn('ana', httpretty.last_request().body.decode('utf-8')) # no more data is sent to sendgrid
|
||||||
self.assertIn('__4__', httpretty.last_request().body)
|
self.assertIn('__4__', httpretty.last_request().body.decode('utf-8'))
|
||||||
|
|
||||||
def test_form_toggle(self):
|
def test_form_toggle(self):
|
||||||
# create and login a user
|
# create and login a user
|
||||||
|
@ -328,7 +328,7 @@ class UserAccountsTestCase(FormspreeTestCase):
|
||||||
|
|
||||||
# delete a submission in form
|
# delete a submission in form
|
||||||
first_submission = Submission.query.first()
|
first_submission = Submission.query.first()
|
||||||
r = self.client.post('/forms/' + form_endpoint + '/delete/' + unicode(first_submission.id),
|
r = self.client.post('/forms/' + form_endpoint + '/delete/' + str(first_submission.id),
|
||||||
headers={'Referer': settings.SERVICE_URL},
|
headers={'Referer': settings.SERVICE_URL},
|
||||||
follow_redirects=True)
|
follow_redirects=True)
|
||||||
self.assertEqual(200, r.status_code)
|
self.assertEqual(200, r.status_code)
|
||||||
|
|
Loading…
Reference in New Issue