-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8bb15fc
commit 6c7229c
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
pipeline { | ||
agent { docker { image 'python:3.7.2' } } | ||
stages { | ||
stage('build') { | ||
steps { | ||
sh 'pip install -r requirements.txt' | ||
} | ||
} | ||
stage('test') { | ||
steps { | ||
sh 'python test_app.py' | ||
} | ||
post { | ||
always { | ||
junit 'test-reports/*.xml' | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from flask import Flask | ||
app = Flask(__name__) | ||
|
||
@app.route('/') | ||
@app.route('/hello/') | ||
def hello_world(): | ||
return 'Hello World!\n' | ||
|
||
@app.route('/hello/<username>') # dynamic route | ||
def hello_user(username): | ||
return 'Why Hello %s!\n' % username | ||
|
||
if __name__ == '__main__': | ||
app.run(host='0.0.0.0') # open for everyone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Click==7.0 | ||
Flask==1.0.2 | ||
itsdangerous==1.1.0 | ||
Jinja2==2.10 | ||
MarkupSafe==1.1.0 | ||
Werkzeug==0.14.1 | ||
xmlrunner==1.7.7 | ||
# pytest==6.1.2 | ||
# pytest-cov==2.10.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import unittest | ||
import app | ||
|
||
class TestHello(unittest.TestCase): | ||
|
||
def setUp(self): | ||
app.app.testing = True | ||
self.app = app.app.test_client() | ||
|
||
def test_hello(self): | ||
rv = self.app.get('/') | ||
self.assertEqual(rv.status, '200 OK') | ||
self.assertEqual(rv.data, b'Hello World!\n') | ||
|
||
def test_hello_hello(self): | ||
rv = self.app.get('/hello/') | ||
self.assertEqual(rv.status, '200 OK') | ||
self.assertEqual(rv.data, b'Hello World!\n') | ||
|
||
def test_hello_name(self): | ||
name = 'Simon' | ||
rv = self.app.get(f'/hello/{name}') | ||
self.assertEqual(rv.status, '200 OK') | ||
self.assertIn(bytearray(f"{name}", 'utf-8'), rv.data) | ||
|
||
if __name__ == '__main__': | ||
############# Add these lines ############# | ||
import xmlrunner | ||
runner = xmlrunner.XMLTestRunner(output='test-reports') | ||
unittest.main(testRunner=runner) | ||
########################################### |