Skip to content

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LordFarquaadtheCreator committed Aug 28, 2024
1 parent 70c4110 commit 0b51ca9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
branches:
- main


jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -19,9 +20,16 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
python-version: '3.10'

- name: Install dependencies
env:
POSTGRESQL_DB_USER: ${{ secrets.POSTGRESQL_DB_USER }}
POSTGRESQL_DB_PASSWORD: ${{ secrets.POSTGRESQL_DB_PASSWORD }}
POSTGRESQL_DB: ${{ secrets.POSTGRESQL_DB }}
POSTGRESQL_DB_PORT: ${{ secrets.POSTGRESQL_DB_PORT }}
POSTGRESQL_DB_HOST: ${{ secrets.POSTGRESQL_DB_HOST }}

run: |
python -m pip install --upgrade pip
pip install -r req.txt
Expand Down
38 changes: 24 additions & 14 deletions Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ class Test:
def __init__(self):
from Database import Database

self.passed_counter = 0
self.failed = 0
self.database = Database()
self.uid_to_delete = ""

def load_environment(self):
try:
Expand All @@ -15,16 +16,18 @@ def load_environment(self):

load_dotenv()

_ = os.getenv("POSTGRESQL_DB")
_ = os.getenv("POSTGRESQL_DB_USER")
_ = os.getenv("POSTGRESQL_DB_PASSWORD")
_ = os.getenv("POSTGRESQL_DB_HOST")
_ = os.getenv("POSTGRESQL_DB_PORT")
db = os.getenv("POSTGRESQL_DB")
db_user = os.getenv("POSTGRESQL_DB_USER")
db_pass = os.getenv("POSTGRESQL_DB_PASSWORD")
db_host = os.getenv("POSTGRESQL_DB_HsadsOST")
db_port = os.getenv("POSTGRESQL_DB_PORT")

self.passed_counter += 1
if not db or not db_user or not db_pass or not db_host or not db_port:
raise Exception("Missing Certain Environment Variables")
return True

except Exception as e:
self.failed += 1
print("Failed load environment test")
print(e)
return False
Expand All @@ -50,36 +53,43 @@ def add_test(self):
try:
res = self.database.add(t)[0]
self.uid_to_delete = str(res[0])
self.passed_counter += 1
return True
except Exception as e:
self.failed += 1
print("Add Test Unit Test failed\n", e)
return False

def delete_test(self):
try:
self.database.remove(self.uid_to_delete)
self.passed_counter += 1
return True
except Exception as e:
self.failed += 1
print("Deleting User Test Failed")
print(e)
return False

def get_test(self):
try:
_ = self.database.get()
self.passed_counter += 1
return True
except Exception as e:
self.failed += 1
print("Get All Values test failed")
print(e)
return False


if __name__ == "__main__":
ut = UnitTest()
assert ut.load_environment() is True
assert ut.add_test() is True
assert ut.get_test() is True
assert ut.delete_test() is True

ut.load_environment()
ut.add_test()
ut.get_test()
ut.delete_test()

if ut.failed > 0:
print("Tests Failed")
exit(1)
print("Tests Passed!")
exit(0)

0 comments on commit 0b51ca9

Please sign in to comment.