generated from nogibjj/Mobasserul_Haque_MiniProject5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c66447
commit f661303
Showing
5 changed files
with
106 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,72 @@ | ||
""" | ||
Test for ETL and complex SQL queries | ||
""" | ||
|
||
import subprocess | ||
|
||
|
||
def test_extract(): | ||
"""tests extract()""" | ||
"""Test extractData()""" | ||
result = subprocess.run( | ||
["python", "main.py", "extract"], | ||
capture_output=True, | ||
text=True, | ||
check=True, | ||
) | ||
assert result.returncode == 0 | ||
assert "Extracting data..." in result.stdout | ||
assert ( | ||
result.returncode == 0 | ||
), f"Extract failed with return code {result.returncode}" | ||
assert ( | ||
"Extracting data..." in result.stdout | ||
), "Expected 'Extracting data...' in output" | ||
print("Extract Test Passed!") | ||
|
||
|
||
def test_transform_load(): | ||
"""tests transform_load""" | ||
def test_load(): | ||
"""Test loadData()""" | ||
result = subprocess.run( | ||
["python", "main.py", "load"], | ||
capture_output=True, | ||
text=True, | ||
check=True, | ||
) | ||
assert result.returncode == 0 | ||
assert "Transforming data..." in result.stdout | ||
) | ||
|
||
if result.returncode != 0: | ||
print(f"Load failed with return code {result.returncode}") | ||
print(f"Error output: {result.stderr}") # Print the error output | ||
assert result.returncode == 0 # Reassert to ensure the test fails | ||
|
||
assert ( | ||
"Loading data to Databricks..." in result.stdout | ||
), "Expected 'Loading data to Databricks...' in output" | ||
print("Load Test Passed!") | ||
|
||
|
||
def test_general_query(): | ||
"""tests general_query""" | ||
"""Test general_query() with a complex SQL query""" | ||
query_string = """ | ||
SELECT | ||
rg.Major, | ||
rg.Employed AS Undergrad_Employed, | ||
gs.Grad_employed AS Grad_Employed, | ||
rg.Unemployment_rate AS Undergrad_Unemployment_Rate, | ||
gs.Grad_unemployment_rate AS Grad_Unemployment_Rate, | ||
(gs.Grad_median - rg.Median) AS Salary_Premium | ||
FROM RecentGradsDB rg | ||
JOIN GradStudentsDB gs ON rg.Major_code = gs.Major_code | ||
WHERE rg.Unemployment_rate < 0.05 | ||
AND gs.Grad_unemployment_rate < 0.05 | ||
ORDER BY Salary_Premium DESC | ||
LIMIT 5; | ||
""" | ||
|
||
result = subprocess.run( | ||
[ | ||
"python", | ||
"main.py", | ||
"query", | ||
"""SELECT | ||
rg.Major, | ||
rg.Employed AS Undergrad_Employed, | ||
gs.Grad_employed AS Grad_Employed, | ||
rg.Unemployment_rate AS Undergrad_Unemployment_Rate, | ||
gs.Grad_unemployment_rate AS Grad_Unemployment_Rate, | ||
(gs.Grad_median - rg.Median) AS Salary_Premium | ||
FROM RecentGradsDB rg | ||
JOIN GradStudentsDB gs | ||
ON rg.Major_code = gs.Major_code | ||
WHERE rg.Unemployment_rate < 0.05 -- High undergraduate employment rate | ||
AND gs.Grad_unemployment_rate < 0.05 -- High graduate employment rate | ||
ORDER BY Salary_Premium DESC;""" | ||
], | ||
["python", "main.py", "query", query_string], | ||
capture_output=True, | ||
text=True, | ||
check=True, | ||
) | ||
assert result.returncode == 0 | ||
assert result.returncode == 0, f"Query failed with return code {result.returncode}" | ||
print("General Query Test Passed!") | ||
|
||
|
||
if __name__ == "__main__": | ||
test_extract() | ||
test_transform_load() | ||
test_load() | ||
test_general_query() |