Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install mysql-connector-python
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run tests
run: |
pytest
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
mysql-connector-python
mysql-connector-python==8.4
requests==2.32.2
pytest==8.2.1
47 changes: 19 additions & 28 deletions tests/test_csv_to_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,23 @@
import os
import mysql.connector

# Ensure the config.py can be found
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
def test_mysql_connector_import():
try:
con = mysql.connector.connect(
host="fake_host",
user="fake_user",
password="fake_password"
)
except mysql.connector.Error as err:
# Since this is not real, we expect a connection error
assert isinstance(err, mysql.connector.Error)
print(f"mysql.connector is working: {err}")
else:
# If no exception was raised, it means something is wrong because it should fail
assert False, "Expected a connection error but did not get one"
finally:
if 'con' in locals() and con.is_connected():
con.close()

from config import host, user, password

def test_database_connection():
con = mysql.connector.connect(
host=host,
user=user,
password=password
)
assert con.is_connected(), "Failed to connect to the database"
con.close()

def test_database_creation():
database_name = "test_db"
con = mysql.connector.connect(
host=host,
user=user,
password=password
)
cur = con.cursor()
cur.execute(f"DROP DATABASE IF EXISTS {database_name}")
cur.execute(f"CREATE DATABASE {database_name}")
cur.execute(f"SHOW DATABASES LIKE '{database_name}'")
result = cur.fetchone()
assert result, "Database creation failed"
cur.execute(f"DROP DATABASE {database_name}")
con.close()
if __name__ == "__main__":
test_mysql_connector_import()
13 changes: 13 additions & 0 deletions tests/test_https_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import requests
def test_status_code():
url = "https://github.com/COMMANDO2406/CSVtoMySQL"
try:
response = requests.get(url)
assert response.status_code == 200, f"Expected status code 200, got {response.status_code}"
print("HTTP request successful with status code 200")
except requests.RequestException as e:
print(f"Request failed with exception: {e}")
assert False, f"Request failed with exception: {e}"

if __name__ == "__main__":
test_status_code()