python3 random fixes from @rohitdatta

* fixed unicode python3 issues
* set flask app to formspree
* test?
* update travis
* travis?
This commit is contained in:
Rohit Datta 2018-05-13 00:00:23 -05:00 committed by Giovanni T. Parra
parent 0ea38e18a7
commit 19ae7fcbb6
4 changed files with 14 additions and 23 deletions

View File

@ -6,6 +6,7 @@ install:
- pip install pipenv
- pipenv install --dev --three
script:
- export FLASK_APP=formspree
- flask test
addons:
postgresql: "9.6"
@ -14,14 +15,4 @@ services:
before_script:
- psql -c 'create database formspree_test;' -U postgres
env:
- 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
- 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

View File

@ -571,7 +571,7 @@ def form_submissions(hashid, format=None):
for f in fields:
value = sub.data.get(f, '')
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)
submissions.append(sub)

View File

@ -21,7 +21,7 @@ class ListUnsubscribeTestCase(FormspreeTestCase):
f = Form.query.first()
# 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)
self.assertTrue(res is not None)
list_unsubscribe_url = res.group(1)
@ -38,7 +38,7 @@ class ListUnsubscribeTestCase(FormspreeTestCase):
self.assertEqual(r.status_code, 302)
# 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)
self.assertTrue(res is not None)
url = res.group(1)

View File

@ -42,7 +42,7 @@ class UserAccountsTestCase(FormspreeTestCase):
user = User.query.filter_by(email='alice@springs.com').first()
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(
link,
query_string=qs,
@ -89,7 +89,7 @@ class UserAccountsTestCase(FormspreeTestCase):
self.assertEqual(r.status_code, 200)
# 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(
link,
query_string=qs,
@ -157,7 +157,7 @@ class UserAccountsTestCase(FormspreeTestCase):
data={'name': 'bruce'}
)
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())
# confirm form
@ -176,9 +176,9 @@ class UserAccountsTestCase(FormspreeTestCase):
form = Form.query.first()
self.assertEqual(form.counter, 5)
self.assertEqual(form.get_monthly_counter(), 5)
self.assertIn('ana', httpretty.last_request().body)
self.assertIn('__4__', httpretty.last_request().body)
self.assertNotIn('You+are+past+our+limit', httpretty.last_request().body)
self.assertIn('ana', httpretty.last_request().body.decode('utf-8'))
self.assertIn('__4__', httpretty.last_request().body.decode('utf-8'))
self.assertNotIn('You+are+past+our+limit', httpretty.last_request().body.decode('utf-8'))
# try (and fail) to submit from a different host
r = self.client.post('/' + form_endpoint,
@ -186,8 +186,8 @@ class UserAccountsTestCase(FormspreeTestCase):
data={'name': 'usurper'}
)
self.assertEqual(r.status_code, 403)
self.assertIn('ana', httpretty.last_request().body) # no more data is sent to sendgrid
self.assertIn('__4__', httpretty.last_request().body)
self.assertIn('ana', httpretty.last_request().body.decode('utf-8')) # no more data is sent to sendgrid
self.assertIn('__4__', httpretty.last_request().body.decode('utf-8'))
def test_form_toggle(self):
# create and login a user
@ -328,7 +328,7 @@ class UserAccountsTestCase(FormspreeTestCase):
# delete a submission in form
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},
follow_redirects=True)
self.assertEqual(200, r.status_code)