From a6fce02c56d53a61e73b6b102c0be2dbe1e31e3e Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 24 Oct 2020 16:16:41 +0100 Subject: [PATCH] Add unit test. --- .github/workflows/build.yaml | 9 +++++--- tests/__init__.py | 0 tests/test_ui.py | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/test_ui.py diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8b182f4..085e033 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -19,14 +19,17 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 pytest + pip install flake8 unittest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Install bapsicle as module + run: | + pip install -e . - 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 + - name: Test with unittest run: | - pytest \ No newline at end of file + python -m unittest \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_ui.py b/tests/test_ui.py new file mode 100644 index 0000000..c0ed77c --- /dev/null +++ b/tests/test_ui.py @@ -0,0 +1,41 @@ +from bapsicle import server +import unittest + + +class TestUI(unittest.TestCase): + + # initialization logic for the test suite declared in the test module + # code that is executed before all tests in one test run + @classmethod + def setUpClass(cls): + pass + + # clean up logic for the test suite declared in the test module + # code that is executed after all tests in one test run + @classmethod + def tearDownClass(cls): + pass + + # initialization logic + # code that is executed before each test + def setUp(self): + self.app = server.app.test_client() + self.app.testing = True + + # clean up logic + # code that is executed after each test + def tearDown(self): + pass + + def test_index_status_code(self): + # sends HTTP GET request to the application + # on the specified path + result = self.app.get('/') + + # assert the status code of the response + self.assertEqual(result.status_code, 200) + + +# runs the unit tests in the module +if __name__ == '__main__': + unittest.main()