def my_function(self): logging.debug("inside my function . Processing "+self.file_type + " file") reader = ingest.FileReader(self.file_type) writer = persist.PersistData("postgres") read_json = reader.read_file() print("read the json "+str(read_json)) writer.store_data(read_json)
def insert_course(): input_json = request.get_json(force=True) print("input_json > "+str(input_json)) dbObject = persist.PersistData("postgres") dbObject.write_from_json_to_pg("futureschema.futurex_course_catalog", input_json) return "success"
def test_write_from_json_to_pg_2(self): dbObject = persist.PersistData("postgres") course_json = json.dumps({ "course_name": "New course 20", "author_name": "futurex", "course_section": { "section1": ' \ ' "Value", "section2": "Value3" }, "creation_date": "2021-03-20" }) dbObject.write_from_json_to_pg("futureschema.futurex_course_catalog", course_json)
def test_read_from_pg(): dbObject = persist.PersistData("postgres") courses = dbObject.read_from_pg("futureschema.futurex_course_catalog") print(len(courses[0])) assert 5 == len(courses[0])
def test_read_from_pg_2(): dbObject = persist.PersistData("postgres") with pytest.raises(psycopg2.errors.UndefinedTable): dbObject.read_from_pg("futureschema.table_invalid")
def get_courses(): dbObject = persist.PersistData("postgres") courses = dbObject.read_from_pg("futureschema.futurex_course_catalog") return "courses are - "+str(courses)
def test_read_from_pg(self): dbObject = persist.PersistData("postgres") courses = dbObject.read_from_pg("futureschema.futurex_course_catalog") print(len(courses[0])) self.assertEqual(len(courses[0]), 5)
def test_write_from_json_to_pg(self): dbObject = persist.PersistData("postgres") with self.assertRaises(KeyError): dbObject.write_from_json_to_pg( "futureschema.futurex_course_catalog", {})