test_LocalDBCreate.test_LocalDBCreate()   B
last analyzed

Complexity

Conditions 6

Size

Total Lines 43
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 43
rs 8.3466
c 0
b 0
f 0
cc 6
nop 0
1
from LocalDB_create_CNBP import LocalDBCreate, create_localDB_CNBP
2
from LocalDB_query import check_header
3
from LocalDB_schema import *
4
from pathlib import Path
5
import logging
6
import os
7
import sys
8
9
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
10
11
def test_LocalDBCreate():
12
    logger = logging.getLogger('UT_LocalDBCreate')
13
    PathString = "Test.sqlite"
14
    # if SQL already exist, quit script.
15
    SQLPath = Path(PathString)
16
17
    # check if path is a fiel and exist.
18
    if SQLPath.is_file():
19
        logger.info('Test SQLite database file already exist. Gonna mess with it!')
20
        ''''Delete current database! During testing only'''
21
        os.remove(PathString)
22
23
    table_name = 'whatchacallitid_table'  # All CNBP database should have this table name.
24
    KeyFieldString = 'whatchacalitkeyfield'
25
26
    # must pappend DBKEY creaed as the indexer column.
27
    NewColumns = ['whasdfasdfasdffsdf', '123345sdb', 'CNvaasa31NID', 'CNFUasdfNID', 'Ha1234sh1', 'Hasha2', 'adsfas']
28
    NewColumnsTypes = ['TEXT', 'BLOB', 'REAL', 'TEXT', 'TEXT', 'BLOB', 'TEXT']
29
30
    NewColumnSpec = zip(NewColumns, NewColumnsTypes)
31
    NewColumnSpecList = list(NewColumnSpec)
32
33
    # Create the database
34
    assert LocalDBCreate(PathString, table_name, KeyFieldString, NewColumnSpecList)
35
36
37
38
    table_header = check_header(PathString, table_name)
39
40
    # Remove database before assertion that potentially fail.
41
    os.remove(PathString)
42
43
    NewColumns = [KeyFieldString, 'whasdfasdfasdffsdf', '123345sdb', 'CNvaasa31NID', 'CNFUasdfNID', 'Ha1234sh1',
44
                  'Hasha2', 'adsfas']
45
    NewColumnsTypes = ['INTEGER', 'TEXT', 'BLOB', 'REAL', 'TEXT', 'TEXT', 'BLOB', 'TEXT']
46
47
    for index in range(0, len(NewColumns)):
48
        print(table_header[index][1])
49
        assert table_header[index][1] == NewColumns[index]
50
        print(table_header[index][2])
51
        assert table_header[index][2] == NewColumnsTypes[index]
52
53
    return True
54
55
def test_LocalDBCreate_CNBP():
56
    logger = logging.getLogger('UT_LocalDBCreate_CNBP')
57
    PathString = "TestCNBP.sqlite"
58
    # if SQL already exist, quit script.
59
    SQLPath = Path(PathString)
60
61
    # check if path is a fiela nd exist.
62
    if SQLPath.is_file():
63
        logger.info('Test SQLite database file already exist. Gonna mess with it!')
64
        ''''Delete current database! During testing only'''
65
        os.remove(PathString)
66
67
    # Create the database
68
    assert create_localDB_CNBP(PathString)
69
70
71
    tableName = CNBP_schema_table_name #All CNBP database should have this table name.
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable CNBP_schema_table_name does not seem to be defined.
Loading history...
72
73
    fetchallResult = check_header(PathString, tableName)
74
75
    # remove test database
76
    os.remove(PathString)
77
78
    # must pappend DBKEY creaed as the indexer column.
79
    newColumns, newColumnsTypes = concatenatedSchema()
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable concatenatedSchema does not seem to be defined.
Loading history...
80
81
    for index in range(0, len(newColumns)):
82
        print(fetchallResult[index][1])
83
        assert fetchallResult[index][1] == newColumns[index]
84
        print(fetchallResult[index][2])
85
        assert fetchallResult[index][2] == newColumnsTypes[index]
86
87
88
    return True
89
90
if __name__ == '__main__':
91
    test_LocalDBCreate()