added app.py
This commit is contained in:
		
						commit
						360d242a44
					
				
							
								
								
									
										11
									
								
								app.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								app.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					from flask import Flask
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app = Flask(__name__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.route("/")
 | 
				
			||||||
 | 
					def helloworld():
 | 
				
			||||||
 | 
					    return "Helle from the hell"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == "__main__":
 | 
				
			||||||
 | 
					    app.run(debug=True,host="0.0.0.0",port=5000)
 | 
				
			||||||
							
								
								
									
										1
									
								
								tests/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/__init__.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					# for pytest
 | 
				
			||||||
							
								
								
									
										9
									
								
								tests/conftest.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								tests/conftest.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					import pytest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@pytest.fixture
 | 
				
			||||||
 | 
					def client():
 | 
				
			||||||
 | 
					    from web import app
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    app.app.config['TESTING'] = True
 | 
				
			||||||
 | 
					    yield app.app.test_client()
 | 
				
			||||||
							
								
								
									
										23
									
								
								tests/test_api.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								tests/test_api.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					from urllib.parse import urlencode
 | 
				
			||||||
 | 
					import json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def call(client, path, params):
 | 
				
			||||||
 | 
					    url = path + '?' + urlencode(params)
 | 
				
			||||||
 | 
					    response = client.get(url)
 | 
				
			||||||
 | 
					    return json.loads(response.data.decode('utf-8'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_plus_one(client):
 | 
				
			||||||
 | 
					    result = call(client, '/plus_one', {'x': 2})
 | 
				
			||||||
 | 
					    assert result['x'] == 3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_plus_two(client):
 | 
				
			||||||
 | 
					    result = call(client, '/plus_two', {'x': 2})
 | 
				
			||||||
 | 
					    assert result['x'] == 4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_square(client):
 | 
				
			||||||
 | 
					    result = call(client, '/square', {'x': 2})
 | 
				
			||||||
 | 
					    assert result['x'] == 4
 | 
				
			||||||
							
								
								
									
										22
									
								
								web/app.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								web/app.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					from flask import request, Flask
 | 
				
			||||||
 | 
					import json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app = Flask(__name__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.route('/plus_one')
 | 
				
			||||||
 | 
					def plus_one():
 | 
				
			||||||
 | 
					    x = int(request.args.get('x', 1))
 | 
				
			||||||
 | 
					    return json.dumps({'x': x + 1})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.route('/plus_two')
 | 
				
			||||||
 | 
					def plus_two():
 | 
				
			||||||
 | 
					    x = int(request.args.get('x', 1))
 | 
				
			||||||
 | 
					    return json.dumps({'x': x + 2})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.route('/square')
 | 
				
			||||||
 | 
					def square():
 | 
				
			||||||
 | 
					    x = int(request.args.get('x', 1))
 | 
				
			||||||
 | 
					    return json.dumps({'x': x * x})
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user