Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string composition from form fields #79

Merged
merged 6 commits into from
Aug 16, 2017
Merged

string composition from form fields #79

merged 6 commits into from
Aug 16, 2017

Conversation

leian7
Copy link
Contributor

@leian7 leian7 commented Jun 2, 2017

For #77 . Needed for osuosl-pelican's osuosl/osuosl-pelican#159

Changes

  • handles a form's fields_to_join as described in string composition from form fields #77 when it is provided
  • adds another test similar to the existing test for format_message that includes a fields_to_join in the dummy POST request
  • validates the fields_to_join field if it exists

To run tests

  • make tests

To "send" a test email (unable to send actual email locally because it would require running a local smtp server)

  • in request_handler.py, comment out lines 467-481 and uncomment print(msg_send) on 466 instead
  • Prepare your own test form with a hidden fields_to_join or use the premade example in templates: navigate to templates/ and do python -m SimpleHTTPServer [port num that isn't 5000]. Make sure your form action is to localhost:5000. You can also try including a nonexistent field in fields_to_join to test validation (see below for sample output).
  • make run in another terminal
  • got to localhost:[the port num your form is on] in your browser and submit the form. Verify that your fields_to_join were concatenated correctly if you supplied valid fields. Sample terminal output for index.html is below.

Expected output

  • Tests pass (47)
  • Test good "email":
(venv) leian@turquoise:~/formsender$ make run
python request_handler.py
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
From nobody Fri Jun  2 16:37:48 2017
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: Form Submission
To: [email protected]

Contact:
--------
NAME:   Firstname Lastname
EMAIL:   [email protected]

Information:
------------
[email protected]:Firstname Lastname


127.0.0.1 - - [02/Jun/2017 16:37:48] "POST / HTTP/1.1" 302 -
  • test bad "email": the email will not print in the terminal. The redirected page upon submission should include something like ?error=3&message=Improper+Form+Submission in the url.

Notes

  • Did everything in request_handler.py's existing format_message method, but I can make a new method for format_message to call if needed.

@leian7 leian7 requested review from ramereth and Kennric June 2, 2017 20:17
@ramereth
Copy link
Member

ramereth commented Jun 8, 2017

@leian7 did you see my update to #77 related to this PR?

@leian7
Copy link
Contributor Author

leian7 commented Jun 9, 2017

@ramereth I did, I discussed it with @Kennric , and my understanding is that the list provided to fields_to_join can be completely arbitrary; the form author gets to decide their specific string and its order. For extra bits like ibm-power they can have it be a hidden field. Is this correct? Or did you want $username:$user_first:$user_last:$phone:$company:$date:$email:ibm-power:support to always be included in the string?

@ramereth
Copy link
Member

ramereth commented Jun 9, 2017

How will the date field work since it's not a field in the form?

@Kennric
Copy link
Contributor

Kennric commented Jun 12, 2017

@leian7 @ramereth for the date, we'll need to calculate that - my thought was that we'd do it in the form, but on second thought I'd rather not add javascript for that. Let's have formsender check the fields_to_join list, and if it contains 'date' just insert today's date.

@ramereth
Copy link
Member

@Kennric how will we determine the format of the date being printed in the string? For this specific use-case, we need a unix echo timestamp, but we may need others later.

@leian7
Copy link
Contributor Author

leian7 commented Jun 14, 2017

@Kennric @ramereth For now I check for 'date' and insert the timestamp if 'date' is there. I interpreted "unix timestamp" as the regular "seconds since 1970" unix standard, is this correct?

[email protected]:Timestamp Test:1497398504:Annie Lei

@ramereth
Copy link
Member

@leian7 yes, that is correct

@ramereth
Copy link
Member

@Kennric can we please get this merged and deployed?

@ramereth ramereth merged commit 43a24f8 into develop Aug 16, 2017
@ramereth ramereth deleted the leian/string_comp branch August 16, 2017 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants