-
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
e3eeb86
commit ef1cc00
Showing
3 changed files
with
133 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,33 @@ | ||
name: Build and Test | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 pytest | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with pytest | ||
run: | | ||
pytest test.py |
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
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,91 @@ | ||
from app import app | ||
import unittest | ||
import json | ||
|
||
|
||
class MorseCodeTest(unittest.TestCase): | ||
|
||
# This method test for the index page that the response status code is 200. | ||
def test_index_statuscode(self): | ||
tester = app.test_client(self) | ||
response = tester.get('/') | ||
self.assertEqual(response.status_code, 200, | ||
'Index page did not returned 200 status code.') | ||
|
||
# Test the content of the index page. | ||
def test_index_content(self): | ||
tester = app.test_client(self) | ||
response = tester.get('/') | ||
self.assertEqual(response.content_type, 'text/html; charset=utf-8', | ||
'Response content is not of html type.') | ||
|
||
self.assertTrue(b'The Morse Code' in response.data, | ||
'"The Morse Code" was not found in the returned resposne.') | ||
|
||
# Test the encrypt post api for positive scenario. | ||
def test_encrypt_success(self): | ||
tester = app.test_client(self) | ||
request_data = {'message': 'Hi, Welcome.'} | ||
response = tester.post('/encrypt/', data=request_data, | ||
content_type='application/x-www-form-urlencoded') | ||
|
||
self.assertEqual(response.status_code, 200, | ||
'Encryt request did not returned 200 status code.') | ||
|
||
self.assertEqual(response.content_type, 'application/json', | ||
'Response content is not of json type.') | ||
|
||
self.assertEqual(response.json['status'], 'success') | ||
self.assertEqual( | ||
response.json['cipher'], '.... .. --..-- / .-- . .-.. -.-. --- -- . .-.-.-') | ||
|
||
# Test the encrypt post api for negative scenario. | ||
def test_encrypt_error(self): | ||
tester = app.test_client(self) | ||
request_data = {} | ||
response = tester.post('/encrypt/', data=request_data, | ||
content_type='application/x-www-form-urlencoded') | ||
|
||
self.assertEqual(response.status_code, 400, | ||
'Encryt request did not returned 400 status code.') | ||
|
||
self.assertEqual(response.content_type, 'application/json', | ||
'Response content is not of json type.') | ||
|
||
self.assertEqual(response.json['status'], 'error') | ||
|
||
# Test the decrypt post api for positive scenario. | ||
def test_decrypt_success(self): | ||
tester = app.test_client(self) | ||
request_data = {'cipher': '.... .. --..-- / .-- . .-.. -.-. --- -- . .-.-.-'} | ||
response = tester.post('/decrypt/', data=request_data, | ||
content_type='application/x-www-form-urlencoded') | ||
|
||
self.assertEqual(response.status_code, 200, | ||
'Decryt request did not returned 200 status code.') | ||
|
||
self.assertEqual(response.content_type, 'application/json', | ||
'Response content is not of json type.') | ||
|
||
self.assertEqual(response.json['status'], 'success') | ||
self.assertEqual( | ||
response.json['message'], 'Hi, welcome.') | ||
|
||
# Test the decrypt post api for negative scenario. | ||
def test_decrypt_error(self): | ||
tester = app.test_client(self) | ||
request_data = {} | ||
response = tester.post('/decrypt/', data=request_data, | ||
content_type='application/x-www-form-urlencoded') | ||
|
||
self.assertEqual(response.status_code, 400, | ||
'Decryt request did not returned 400 status code.') | ||
|
||
self.assertEqual(response.content_type, 'application/json', | ||
'Response content is not of json type.') | ||
|
||
self.assertEqual(response.json['status'], 'error') | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |