def test_no_results(self): q = "SELECT school_name FROM codetran_collegedata.collegescorecard WHERE latest_admissions_act_scores_midpoint_cumulative BETWEEN 36 AND 35" actualOutput = query_to_json(q) expectedOutput = {"column_names": [], "rows": []} self.assertEqual(actualOutput, expectedOutput)
def post(self): args = College_Data.parser.parse_args() # build query tablename = sql_info.get_full_table_name() select_col = sql_info.get_select_cols() q = build_query(tablename, select_col, args['filter_dict']) return {"table": query_to_json(q)}
def test_one_col_results(self): q = 'SELECT school_name FROM codetran_collegedata.collegescorecard WHERE school_name="Pomona College" or school_name="Rice University"' actualOutput = query_to_json(q) expectedOutput = { "column_names": ["school_name"], "rows": [{ "school_name": "Pomona College" }, { "school_name": "Rice University" }] } self.assertEqual(actualOutput["column_names"], expectedOutput["column_names"]) self.assertEqual(actualOutput["rows"], expectedOutput["rows"])
def test_results_with_id(self): q = 'SELECT ope6_id, school_name, school_state FROM codetran_collegedata.collegescorecard WHERE school_name="Pomona College" or school_name="Rice University"' actualOutput = query_to_json(q) expectedOutput = { "column_names": ["ope6_id", "school_name", "school_state"], "rows": [{ "ope6_id": 1173, "school_name": "Pomona College", "school_state": "CA" }, { "ope6_id": 3604, "school_name": "Rice University", "school_state": "TX" }] } self.assertEqual(actualOutput["column_names"], expectedOutput["column_names"]) self.assertEqual(actualOutput["rows"], expectedOutput["rows"])