Skip to content

Commit ea47263

Browse files
committed
Merge pull request mjhea0#11 from mbreisch/master
Test Completed
2 parents 7373cf1 + ba2529b commit ea47263

File tree

16 files changed

+166
-11
lines changed

16 files changed

+166
-11
lines changed

.gitignore

100644100755
+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ venv
44
.DS_STORE
55
htmlcov
66
.coverage
7-
__pycache__
7+
__pycache__
8+
/.idea
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
def reverse(some_string: str) -> str:
3+
return some_string[::-1]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import unittest
2+
from reverse_string import reverse
3+
4+
5+
class ReverseStringTests(unittest.TestCase):
6+
def test_reverse(self):
7+
my_string = "testing"
8+
my_reversed_string = "gnitset"
9+
10+
returned_string=reverse(my_string)
11+
assert my_reversed_string == returned_string
12+
13+
if __name__ == "__main__":
14+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from vowel_counter import vowel_counter
3+
4+
5+
class VowelCounterTests(unittest.TestCase):
6+
def test_vowel_counter(self):
7+
my_string = 'abracadabra'
8+
vowel_count = vowel_counter(my_string)
9+
assert vowel_count == 5
10+
11+
if __name__ == '__main__':
12+
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
vowels=('a','e','i','o','u')
2+
3+
4+
def vowel_counter(some_string: str) -> int:
5+
count=0
6+
for letter in some_string:
7+
if letter in vowels:
8+
count += 1
9+
return count

part2/README.md

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
| [Gary Herd](https://github.com/garyherd/python-devtest) | [reverse-string](https://grh-reverse-string.herokuapp.com/) |
99
| [Noor Faziur Reza](https://github.com/ni8mr/python-devtest) | [reverse_string_reza](http://ni8mr2.herokuapp.com/) |
1010
| [AAkinkunmi](https://github.com/nubianMONK/python-devtest/tree/master/part2/reverse_flask_akinkunmi) | [reverse-flask](http://vast-forest-9436.herokuapp.com/) |
11+
| [Matthew Reisch](https://github.com/mbreisch/python-devtest) | [reverse-flask](https://vast-caverns-90155.herokuapp.com/) |
1112
| Add link here | Add link here |

part2/reverse_flask_reisch/Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: python run.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
import sys
3+
4+
pwd = os.path.abspath(os.path.dirname(__file__))
5+
project = os.path.basename(pwd)
6+
base_path = pwd.strip(project)
7+
new_path = os.path.join(base_path, 'project')
8+
9+
try:
10+
from project import app
11+
except ImportError:
12+
sys.path.append(full_path)
13+
from project import app
14+
15+
16+
def before_feature(context, feature):
17+
app.config['TESTING'] = True
18+
app.config['WTF_CSRF_ENABLED'] = False
19+
context.client = app.test_client()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Created by Matthew B. Reisch at 2/7/2016
2+
Feature: reverse_flask is operational in that users can submit a string via a form and view the word in reverse
3+
Scenario: successful string reversal
4+
Given reverse_flask is set up
5+
When we submit the form with the string "hello"
6+
Then we should see the output "olleh"
7+
8+
Scenario: unsuccessful string reversal
9+
Given reverse_flask is set up
10+
When we submit the form with the string " "
11+
Then we should see the alert "This field is required."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from behave import *
2+
3+
4+
@given(u'reverse_flask is set up')
5+
def flask_is_setup(context):
6+
assert context.client
7+
8+
9+
@when(u'we submit the form with the string "{string_input}"')
10+
def submit_form(context, string_input):
11+
context.page = context.client.post('/', data=dict(input=string_input),follow_redirects=True)
12+
13+
14+
@then(u'we should see the output "{output}"')
15+
def output(context, output):
16+
assert output in context.page.data.decode()
17+
18+
19+
@then(u'we should see the alert "{message}"')
20+
def alert(context, message):
21+
assert message in context.page.data.decode()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from flask import Flask,render_template,request
2+
from flask_bootstrap import Bootstrap
3+
from .forms import ReverseForm
4+
5+
app=Flask(__name__)
6+
app.config.from_pyfile('_config.py')
7+
Bootstrap(app)
8+
9+
@app.route('/',methods=['POST','GET'])
10+
def index():
11+
error = None
12+
form = ReverseForm(request.form)
13+
if request.method == 'POST':
14+
if form.validate_on_submit():
15+
input_string=request.form['input']
16+
return render_template('index.html',form=form,reversed_string=input_string[::-1])
17+
return render_template('index.html',form=form,error=error)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
WTF_CSRF_ENABLED = True
2+
SECRET_KEY = '\x07\xdd\xb7\x1e\xe8\x1d*\xe3`3\xa2\x9e\xf6\x94\xd4i\x14(\xa7\x93\xe5s\n\x8e'
3+
DEBUG = True
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from flask_wtf import Form
2+
from wtforms import StringField
3+
from wtforms.validators import DataRequired
4+
5+
6+
class ReverseForm(Form):
7+
input = StringField('Input', validators=[DataRequired()])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{% extends "bootstrap/base.html" %}
2+
{% block title %}Welcome to Reverse-A-Tron-5000 {% endblock %}
3+
{% block content %}
4+
<div class="reverse-input">
5+
<h2>Please Enter a String to be Reversified</h2>
6+
<form action="{{ url_for('index') }}" method="post">
7+
{{ form.csrf_token }}
8+
<p>
9+
{{ form.input(placeholder="input a string here") }}
10+
<span class="has-error">
11+
{% if form.input.errors %}
12+
{% for error in form.input.errors %}
13+
{{ error }}
14+
{% endfor %}
15+
{% endif %}
16+
</span>
17+
</p>
18+
<p>
19+
<input class="btn btn-default" type="submit" value="Reversify">
20+
</p>
21+
</form>
22+
<div class="reverse-output">
23+
<p>Result: {{ reversed_string }}</p>
24+
</div>
25+
</div>
26+
{% endblock %}

part2/reverse_flask_reisch/run.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import os
2+
from project import app
3+
4+
port=int(os.environ.get('PORT',5000))
5+
app.run(host='0.0.0.0',port=port)

requirements.txt

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
Flask==0.10.1
2-
Flask-WTF==0.11
3-
Flask-Session==0.2
4-
Flask-Bootstrap==3.3.4.1
5-
gunicorn==19.3.0
6-
Jinja2==2.7.3
7-
MarkupSafe==0.23
8-
WTForms==2.0.2
9-
Werkzeug==0.10.4
10-
itsdangerous==0.24
1+
behave==1.2.5
2+
Flask==0.10.1
3+
Flask-Bootstrap==3.3.4.1
4+
Flask-Session==0.2
5+
Flask-WTF==0.11
6+
gunicorn==19.3.0
7+
itsdangerous==0.24
8+
Jinja2==2.7.3
9+
MarkupSafe==0.23
10+
parse==1.6.6
11+
parse-type==0.3.4
12+
six==1.10.0
13+
Werkzeug==0.10.4
14+
wheel==0.26.0
15+
WTForms==2.0.2

0 commit comments

Comments
 (0)