Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database #9

Merged
merged 17 commits into from
Apr 14, 2024
40 changes: 40 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Python Test with MySQL

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
MYSQL_DATABASE: testgrocer
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up python
uses: actions/setup-python@v2
with:
python-version: '3.11.2'

- name: Install dependencies
run: |
pip install -r requirements.txt

- name: Run main test script
run: |
cd src && python test_main.py
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![MIT License][license-shield]][license-url]
[![LinkedIn][linkedin-shield]][linkedin-url]

<!-- PROJECT LOGO -->
<br />
Expand Down
2 changes: 1 addition & 1 deletion src/controller/dataControllerv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ def _init_database_(self):
logging.error(f'Error creating {self.database}:', e)

def _is_connected_(self):
return self.connection is not None and self.connection.is_connected()
return self.connection is not None and self.connection.is_connected()
30 changes: 27 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
from controller.dataController import DataController
import logging
import argparse

from controller.dataControllerv2 import DataController2 as DataController

def main(db):
db.connect()
print("HI")
db.disconnect()
print(type(db))

if __name__ == "__main__":
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Run unit tests with different logging levels')
parser.add_argument('-D', '--debug', action='store_const', const=logging.DEBUG, dest='log_level',
help='Set logging level to DEBUG')
parser.add_argument('-I', '--info', action='store_const', const=logging.INFO, dest='log_level',
help='Set logging level to INFO (default)')
parser.add_argument('-W', '--warning', action='store_const', const=logging.WARNING,dest='log_level',
help='Set logging level to WARNING')
parser.add_argument('-E', '--error', action='store_const', const=logging.ERROR, dest='log_level',
help='Set logging level to ERROR')
parser.add_argument('-C', '--critical', action='store_const', const=logging.CRITICAL, dest='log_level',
help='Set logging level to CRITICAL')
args = parser.parse_args()

if args.log_level is not None:
logging.basicConfig(level=args.log_level)
else:
logging.basicConfig(level=logging.INFO)

db = DataController()
main(db)
main(db)
Loading