From fbf0277dd17a55410e2d094bddc1a725dc5c7547 Mon Sep 17 00:00:00 2001 From: bvanroll Date: Wed, 24 Mar 2021 13:47:47 +0100 Subject: [PATCH] improvements to the tests, and added testing to the pipeline. Now a package won't publish if it doesn't test :) --- .github/workflows/python-publish.yml | 3 +++ setup.py | 1 + test/{database.py => test_database.py} | 23 +++++++++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) rename test/{database.py => test_database.py} (65%) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 857b8ae..a01bc89 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -22,6 +22,9 @@ jobs: run: | python -m pip install --upgrade pip pip install setuptools wheel twine + - name: Test #TODO use a testing solution that won't be deprecated soon + run: | + python setup.py test - name: Build and publish env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} diff --git a/setup.py b/setup.py index d521f69..d96f156 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ setuptools.setup( name="vaultdb", version="0.0.1", version_config=True, + test_suite="test", setup_requires=['setuptools-git-versioning'], author="Beppe Vanrolleghem", author_email="beppe.vanrolleghem@gmail.com", diff --git a/test/database.py b/test/test_database.py similarity index 65% rename from test/database.py rename to test/test_database.py index 76b96cc..393f73d 100644 --- a/test/database.py +++ b/test/test_database.py @@ -4,8 +4,17 @@ import os sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) import src -class MyTestCase(unittest.TestCase): - def test_psql(self): +class DatabaseClassTests(unittest.TestCase): + + def test_vault_connection_error(self): + #TODO give some "valid" url + self.fail() + + def test_vault_non_existent_database(self): + #TODO test non existent_database + self.fail() + + def test_psql_connection(self): #TODO exec psql connect print("hi") test = src.Database() @@ -13,18 +22,24 @@ class MyTestCase(unittest.TestCase): self.assertEqual(test.valid, False) def test_psql_invalid_vault_url(self): - #TODO figure out how to fail unit test check try: src.Database(dbname="sdfk", vault_url="localhost", vault_port=8200, token="bla") except: - print("did it") + #TODO check the err msg return + else: + self.fail() + def test_psql_invalid_vault_port(self): try: src.Database(dbname="sdfk", vault_url="localhost", vault_port="a", token="bla") except: + #TODO check the error message return + else: + self.fail() + def test_psql_valid(self): print(src.Database(dbname="psql", vault_url="http://localhost", token="s.GoR2nisHPeKU1vOaw9hZ5L7h").get_creds())