File tree 6 files changed +92
-0
lines changed
6 files changed +92
-0
lines changed 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
+
3
+ app = Flask (__name__ )
4
+
5
+
6
+ @app .route ('/' )
7
+ def get_string ():
8
+ return render_template ('index.html' )
9
+
10
+
11
+ @app .route ('/reverse_string' , methods = ['POST' ])
12
+ def reverse_string ():
13
+ str_to_reverse = request .form ['str_to_reverse' ]
14
+ return render_template (
15
+ 'result.html' ,
16
+ result = str_to_reverse [::- 1 ]
17
+ )
18
+
19
+ if __name__ == '__main__' :
20
+ app .debug = True
21
+ app .run ()
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
+ Reversed string: < strong > {{ result }}</ strong >
9
+
10
+ </ body >
11
+ </ html >
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
+ __author__ = 'G'
You can’t perform that action at this time.
0 commit comments