File tree 9 files changed +119
-1
lines changed
9 files changed +119
-1
lines changed Original file line number Diff line number Diff line change 5
5
| [ Michael Norman] ( https://github.com/mlnorman/python-devtest ) | [ reverse-flask] ( http://reverse-flask.herokuapp.com/ ) |
6
6
| [ Michael Herman] ( https://github.com/mjhea0/python-devtest/tree/master/part2/reverse_flask_herman ) | N/A |
7
7
| [ MPerham] ( https://github.com/mperham2/python-devtest/tree/master/part2/reverse_flask_perham ) | [ Heroku] ( https://shrouded-thicket-5935.herokuapp.com/ ) |
8
- | Add link here | Add link here |
8
+ | [ Gary Herd ] ( https://github.com/garyherd/python-devtest ) | [ reverse-string ] ( https://grh-reverse-string.herokuapp.com/ ) |
9
9
| Add link here | Add link here |
10
10
| Add link here | Add link here |
11
11
| Add link here | Add link here |
Original file line number Diff line number Diff line change
1
+ web : python run.py
Original file line number Diff line number Diff line change
1
+ __author__ = 'G'
Original file line number Diff line number Diff line change
1
+ from flask import Flask , render_template , request
2
+ import os
3
+
4
+ app = Flask (__name__ )
5
+
6
+ app .config ['DEBUG' ] = True
7
+
8
+
9
+ @app .route ('/' )
10
+ def get_string ():
11
+ return render_template ('index.html' )
12
+
13
+
14
+ @app .route ('/reverse_string' , methods = ['POST' ])
15
+ def reverse_string ():
16
+ return render_template (
17
+ 'result.html' ,
18
+ original_str = request .form ['str_to_reverse' ],
19
+ result = request .form ['str_to_reverse' ][::- 1 ]
20
+ )
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head lang ="en ">
4
+ < meta charset ="UTF-8 ">
5
+ < title > </ title >
6
+ </ head >
7
+ < body >
8
+ < h2 > Welcome to Gary's Magic String Reverser!</ h2 >
9
+ < br >
10
+ < form action ="{{ url_for('reverse_string') }} " method ="post ">
11
+ Enter the string to reverse:< br >
12
+ < input type ="text " name ="str_to_reverse ">
13
+ < input type ="submit " value ="Reverse! ">
14
+ </ form >
15
+
16
+
17
+ </ body >
18
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head lang ="en ">
4
+ < meta charset ="UTF-8 ">
5
+ < title > </ title >
6
+ </ head >
7
+ < body >
8
+ Original string: < strong > {{ original_str }}</ strong >
9
+ < br >
10
+ Reversed string: < strong > {{ result }}</ strong >
11
+ < br >
12
+ < br >
13
+ < a href ="/ "> Try again</ a >
14
+
15
+ </ body >
16
+ </ html >
Original file line number Diff line number Diff line change
1
+ # run.py
2
+
3
+ import os
4
+ from project .reverse_flask import app
5
+
6
+ host = '0.0.0.0'
7
+ port = int (os .environ .get ('PORT' , 5000 ))
8
+
9
+ if app .config ['DEBUG' ] == True :
10
+ app .run ()
11
+ else :
12
+ app .run (host = host , port = port )
Original file line number Diff line number Diff line change
1
+ import unittest
2
+
3
+ from project .reverse_flask import app
4
+
5
+
6
+
7
+ class AppTest (unittest .TestCase ):
8
+ # helper methods
9
+
10
+ ##########################
11
+ ### setup and teardown ###
12
+ ##########################
13
+
14
+ def setUp (self ):
15
+ app .config ['TESTING' ] = True
16
+ app .config ['DEBUG' ] = False
17
+ self .app = app .test_client ()
18
+
19
+
20
+ #############
21
+ ### tests ###
22
+ #############
23
+
24
+ def test_index_page_renders (self ):
25
+ response = self .app .get ('/' )
26
+ self .assertEqual (response .status_code , 200 )
27
+ self .assertIn (b'Enter the string to reverse' , response .data )
28
+
29
+ def test_reverse_string_page_renders (self ):
30
+ test_string = 'rabbit'
31
+ expected_string = 'tibbar'
32
+ response = self .app .post ('/reverse_string' , data = dict (
33
+ str_to_reverse = test_string )
34
+ )
35
+ self .assertEqual (response .status_code , 200 )
36
+ self .assertIn (expected_string , response .data )
37
+
38
+
39
+ if __name__ == '__main__' :
40
+ unittest .main ()
Original file line number Diff line number Diff line change
1
+ import unittest
2
+
3
+ from project .reverse_flask import app
4
+
5
+ class ConfigTest (unittest .TestCase ):
6
+ def test_not_in_debug (self ):
7
+ self .assertNotEqual (app .config ['DEBUG' ], True )
8
+
9
+ if __name__ == '__main__' :
10
+ unittest .main ()
You can’t perform that action at this time.
0 commit comments