-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sql.py
More file actions
47 lines (39 loc) · 1.32 KB
/
test_sql.py
File metadata and controls
47 lines (39 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from sqlmodel import Field, Session, SQLModel, create_engine, select
from pathlib import Path
from table_structure import *
from xml_parser import *
test_xml = [
Path("archive/NCT0000xxxx/NCT00000102.xml"),
Path("archive/NCT0000xxxx/NCT00000111.xml"),
]
engine = create_engine("sqlite:///testing_database.db")
SQLModel.metadata.create_all(engine)
def test_sql_main_schema():
"""
This function tests the main_schema_dict function for the xml_parser.py
can be added to an sql database
"""
for i in test_xml:
dict0 = extract_xml(i)
CTPdict = main_schema_dict(dict0)
add_CTPgeneral = MainTable(**CTPdict)
with Session(engine) as session:
session.add(add_CTPgeneral)
session.commit()
print(f"\n Added {i.stem}")
def test_sql_drug_schema():
"""
This function tests the drug_schema_dict function for the xml_parser.py
can be added to an sql database
"""
for i in test_xml:
dict0 = extract_xml(i)
drug_dict = drug_schema_dict(dict0)
for drug_entry in drug_dict:
add_drug = DrugTable(**drug_entry)
with Session(engine) as session:
session.add(add_drug)
session.commit()
print(f"\n Added {i.stem}")
test_sql_main_schema()
# test_sql_drug_schema()